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