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