source: josm/trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFileWrapper.java@ 7037

Last change on this file since 7037 was 7033, checked in by Don-vip, 10 years ago

see #8465 - global use of try-with-resources, according to

File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection.datum;
3
4import java.io.InputStream;
5
6import org.openstreetmap.josm.io.MirroredInputStream;
7
8/**
9 * Wrapper for {@link NTV2GridShiftFile}.
10 *
11 * Loads the shift file from disk, when it is first accessed.
12 * @since 5226
13 */
14public class NTV2GridShiftFileWrapper {
15
16 /**
17 * Used in Germany to convert coordinates between the DHDN (<i>Deutsches Hauptdreiecksnetz</i>)
18 * and ETRS89 (<i>European Terrestrial Reference System 1989</i>) datums.
19 * @see <a href="http://crs.bkg.bund.de/crseu/crs/descrtrans/eu-descrtrans.php?crs_id=REVfREhETiAvIEdLXzM=&op_id=REVfREhETiAoQmVUQSwgMjAwNykgdG8gRVRSUzg5">
20 * Description of Transformation - DE_DHDN (BeTA, 2007) to ETRS89</a>
21 */
22 public static final NTV2GridShiftFileWrapper BETA2007 = new NTV2GridShiftFileWrapper("resource://data/projection/BETA2007.gsb");
23
24 /**
25 * Used in France to convert coordinates between the NTF (<i>Nouvelle triangulation de la France</i>)
26 * and RGF93 (<i>Réseau géodésique français 1993</i>) datums.
27 * @see <a href="http://geodesie.ign.fr/contenu/fichiers/documentation/algorithmes/notice/NT111_V1_HARMEL_TransfoNTF-RGF93_FormatGrilleNTV2.pdf">
28 * [French] Transformation de coordonnées NTF – RGF93 / Format de grille NTv2</a>
29 */
30 public static final NTV2GridShiftFileWrapper ntf_rgf93 = new NTV2GridShiftFileWrapper("resource://data/projection/ntf_r93_b.gsb");
31
32 private NTV2GridShiftFile instance = null;
33 private String gridFileName;
34
35 /**
36 * Constructs a new {@code NTV2GridShiftFileWrapper}.
37 * @param filename Path to the grid file (GSB format)
38 */
39 public NTV2GridShiftFileWrapper(String filename) {
40 this.gridFileName = filename;
41 }
42
43 /**
44 * Returns the actual {@link NTV2GridShiftFile} behind this wrapper.
45 * The grid file is only loaded once, when first accessed.
46 * @return The NTv2 grid file
47 */
48 public NTV2GridShiftFile getShiftFile() {
49 if (instance == null) {
50 try (InputStream is = new MirroredInputStream(gridFileName)) {
51 instance = new NTV2GridShiftFile();
52 instance.loadGridShiftFile(is, false);
53 } catch (Exception e) {
54 throw new RuntimeException(e);
55 }
56 }
57 return instance;
58 }
59}
Note: See TracBrowser for help on using the repository browser.