001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.projection.datum; 003 004import java.io.IOException; 005import java.io.InputStream; 006 007import org.openstreetmap.josm.io.CachedFile; 008import org.openstreetmap.josm.tools.JosmRuntimeException; 009 010/** 011 * Wrapper for {@link NTV2GridShiftFile}. 012 * 013 * Loads the shift file from disk, when it is first accessed. 014 * @since 5226 015 */ 016public class NTV2GridShiftFileWrapper { 017 018 // CHECKSTYLE.OFF: LineLength 019 020 /** 021 * Used in Germany to convert coordinates between the DHDN (<i>Deutsches Hauptdreiecksnetz</i>) 022 * and ETRS89 (<i>European Terrestrial Reference System 1989</i>) datums. 023 * @see <a href="http://crs.bkg.bund.de/crseu/crs/descrtrans/eu-descrtrans.php?crs_id=REVfREhETiAvIEdLXzM=&op_id=REVfREhETiAoQmVUQSwgMjAwNykgdG8gRVRSUzg5"> 024 * Description of Transformation - DE_DHDN (BeTA, 2007) to ETRS89</a> 025 */ 026 public static final NTV2GridShiftFileWrapper BETA2007 = new NTV2GridShiftFileWrapper("resource://data/projection/BETA2007.gsb"); 027 028 /** 029 * Used in France to convert coordinates between the NTF (<i>Nouvelle triangulation de la France</i>) 030 * and RGF93 (<i>Réseau géodésique français 1993</i>) datums. 031 * @see <a href="http://geodesie.ign.fr/contenu/fichiers/documentation/algorithmes/notice/NT111_V1_HARMEL_TransfoNTF-RGF93_FormatGrilleNTV2.pdf"> 032 * [French] Transformation de coordonnées NTF – RGF93 / Format de grille NTv2</a> 033 */ 034 public static final NTV2GridShiftFileWrapper ntf_rgf93 = new NTV2GridShiftFileWrapper("resource://data/projection/ntf_r93_b.gsb"); 035 036 // CHECKSTYLE.ON: LineLength 037 038 private NTV2GridShiftFile instance; 039 private final String gridFileName; 040 041 /** 042 * Constructs a new {@code NTV2GridShiftFileWrapper}. 043 * @param filename Path to the grid file (GSB format) 044 */ 045 public NTV2GridShiftFileWrapper(String filename) { 046 this.gridFileName = filename; 047 } 048 049 /** 050 * Returns the actual {@link NTV2GridShiftFile} behind this wrapper. 051 * The grid file is only loaded once, when first accessed. 052 * @return The NTv2 grid file 053 */ 054 public NTV2GridShiftFile getShiftFile() { 055 if (instance == null) { 056 try (CachedFile cf = new CachedFile(gridFileName); InputStream is = cf.getInputStream()) { 057 instance = new NTV2GridShiftFile(); 058 instance.loadGridShiftFile(is, false); 059 } catch (IOException e) { 060 throw new JosmRuntimeException(e); 061 } 062 } 063 return instance; 064 } 065}