Ticket #14422: 14422.patch

File 14422.patch, 15.8 KB (added by Don-vip, 7 years ago)
  • src/org/openstreetmap/josm/Main.java

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: data_nodist\grid\BETA2007.gsb
    ___________________________________________________________________
    Added: svn:mime-type
    ## -0,0 +1 ##
    +application/octet-stream
    \ No newline at end of property
    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: data_nodist\grid\ntf_r93_b.gsb
    ___________________________________________________________________
    Added: svn:mime-type
    ## -0,0 +1 ##
    +application/octet-stream
    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: data_nodist\grid\BETA2007.gsb
    ___________________________________________________________________
    Added: svn:mime-type
    ## -0,0 +1 ##
    +application/octet-stream
    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: data_nodist\grid\ntf_r93_b.gsb
    ___________________________________________________________________
    Added: svn:mime-type
    ## -0,0 +1 ##
    +application/octet-stream
     
    112112import org.openstreetmap.josm.tools.Shortcut;
    113113import org.openstreetmap.josm.tools.Territories;
    114114import org.openstreetmap.josm.tools.Utils;
     115import org.openstreetmap.josm.tools.bugreport.BugReport;
    115116
    116117/**
    117118 * Abstract class holding various static global variables and methods used in large parts of JOSM application.
     
    522523                KeyEvent.VK_F1, Shortcut.DIRECT));
    523524
    524525        // This needs to be done before RightAndLefthandTraffic::initialize is called
    525         new InitializationTask(tr("Initializing internal boundaries data"), Territories::initialize).call();
     526        try {
     527            new InitializationTask(tr("Initializing internal boundaries data"), Territories::initialize).call();
     528        } catch (JosmRuntimeException e) {
     529            // Can happen if the current projection needs NTV2 grid which is not available
     530            // In this case we want the user be able to change his projection
     531            BugReport.intercept(e).warn();
     532        }
    526533
    527534        // contains several initialization tasks to be executed (in parallel) by a ExecutorService
    528535        List<Callable<Void>> tasks = new ArrayList<>();
  • src/org/openstreetmap/josm/data/projection/Projections.java

     
    4949/**
    5050 * Class to manage projections.
    5151 *
    52  * Use this class to query available projection or register new projections
    53  * from a plugin.
     52 * Use this class to query available projection or register new projections from a plugin.
    5453 */
    5554public final class Projections {
    5655
     
    5857     * Class to hold information about one projection.
    5958     */
    6059    public static class ProjectionDefinition {
    61         public String code;
    62         public String name;
    63         public String definition;
     60        public final String code;
     61        public final String name;
     62        public final String definition;
    6463
     64        /**
     65         * Constructs a new {@code ProjectionDefinition}.
     66         * @param code EPSG code
     67         * @param name projection name
     68         * @param definition projection definition (EPSG format)
     69         */
    6570        public ProjectionDefinition(String code, String name, String definition) {
    6671            this.code = code;
    6772            this.name = name;
     
    140145                "Potsdam Rauenberg 1950 DHDN", "potsdam",
    141146                Ellipsoid.Bessel1841, 598.1, 73.7, 418.2, 0.202, 0.045, -2.455, 6.7));
    142147
    143         nadgrids.put("BETA2007.gsb", NTV2GridShiftFileWrapper.BETA2007);
    144         nadgrids.put("ntf_r93_b.gsb", NTV2GridShiftFileWrapper.ntf_rgf93);
    145 
    146         List<ProjectionDefinition> pds;
    147148        try {
    148             pds = loadProjectionDefinitions("resource://data/projection/custom-epsg");
     149            inits = new LinkedHashMap<>();
     150            for (ProjectionDefinition pd : loadProjectionDefinitions("resource://data/projection/custom-epsg")) {
     151                inits.put(pd.code, pd);
     152                loadNadgrids(pd.definition);
     153            }
    149154        } catch (IOException ex) {
    150155            throw new JosmRuntimeException(ex);
    151156        }
    152         inits = new LinkedHashMap<>();
    153         for (ProjectionDefinition pd : pds) {
    154             inits.put(pd.code, pd);
    155         }
    156157
    157158        for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) {
    158159            for (String code : pc.allCodes()) {
     
    167168        // Hide default constructor for utils classes
    168169    }
    169170
     171    private static void loadNadgrids(String definition) {
     172        final String key = CustomProjection.Param.nadgrids.key;
     173        if (definition.contains(key)) {
     174            try {
     175                String nadgridsId = CustomProjection.parseParameterList(definition, true).get(key);
     176                if (nadgridsId.startsWith("@")) {
     177                    nadgridsId = nadgridsId.substring(1);
     178                }
     179                if (!"null".equals(nadgridsId) && !nadgrids.containsKey(nadgridsId)) {
     180                    nadgrids.put(nadgridsId, new NTV2GridShiftFileWrapper(nadgridsId));
     181                }
     182            } catch (ProjectionConfigurationException e) {
     183                Main.trace(e);
     184            }
     185        }
     186    }
     187
    170188    /**
    171189     * Convert from lat/lon to easting/northing using the current projection.
    172190     *
  • src/org/openstreetmap/josm/data/projection/datum/NTV2Datum.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.projection.datum;
    33
     4import java.io.IOException;
     5
    46import org.openstreetmap.josm.data.coor.LatLon;
    57import org.openstreetmap.josm.data.projection.Ellipsoid;
     8import org.openstreetmap.josm.tools.JosmRuntimeException;
    69
    710/**
    811 * Datum based of NTV2 grid shift file.
    912 */
    1013public class NTV2Datum extends AbstractDatum {
    1114
    12     protected NTV2GridShiftFileWrapper nadgrids;
     15    private final NTV2GridShiftFileWrapper nadgrids;
    1316
     17    /**
     18     * Constructs a new {@code NTV2Datum}.
     19     * @param name datum name
     20     * @param proj4Id PROJ.4 id
     21     * @param ellps ellipsoid
     22     * @param nadgrids NTV2 grid shift file wrapper
     23     */
    1424    public NTV2Datum(String name, String proj4Id, Ellipsoid ellps, NTV2GridShiftFileWrapper nadgrids) {
    1525        super(name, proj4Id, ellps);
    1626        this.nadgrids = nadgrids;
     
    1929    @Override
    2030    public LatLon toWGS84(LatLon ll) {
    2131        NTV2GridShift gs = new NTV2GridShift(ll);
    22         nadgrids.getShiftFile().gridShiftForward(gs);
    23         return new LatLon(ll.lat() + gs.getLatShiftDegrees(), ll.lon() + gs.getLonShiftPositiveEastDegrees());
     32        try {
     33            nadgrids.getShiftFile().gridShiftForward(gs);
     34            return new LatLon(ll.lat() + gs.getLatShiftDegrees(), ll.lon() + gs.getLonShiftPositiveEastDegrees());
     35        } catch (IOException e) {
     36            throw new JosmRuntimeException(e);
     37        }
    2438    }
    2539
    2640    @Override
    2741    public LatLon fromWGS84(LatLon ll) {
    2842        NTV2GridShift gs = new NTV2GridShift(ll);
    29         nadgrids.getShiftFile().gridShiftReverse(gs);
    30         return new LatLon(ll.lat() + gs.getLatShiftDegrees(), ll.lon() + gs.getLonShiftPositiveEastDegrees());
     43        try {
     44            nadgrids.getShiftFile().gridShiftReverse(gs);
     45            return new LatLon(ll.lat() + gs.getLatShiftDegrees(), ll.lon() + gs.getLonShiftPositiveEastDegrees());
     46        } catch (IOException e) {
     47            throw new JosmRuntimeException(e);
     48        }
    3149    }
    3250}
  • src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFileWrapper.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.projection.datum;
    33
     4import java.io.File;
    45import java.io.IOException;
    56import java.io.InputStream;
    67
     8import org.openstreetmap.josm.Main;
    79import org.openstreetmap.josm.io.CachedFile;
    8 import org.openstreetmap.josm.tools.JosmRuntimeException;
    910
    1011/**
    1112 * Wrapper for {@link NTV2GridShiftFile}.
     
    1516 */
    1617public class NTV2GridShiftFileWrapper {
    1718
    18     // CHECKSTYLE.OFF: LineLength
    19 
    20     /**
    21      * Used in Germany to convert coordinates between the DHDN (<i>Deutsches Hauptdreiecksnetz</i>)
    22      * and ETRS89 (<i>European Terrestrial Reference System 1989</i>) datums.
    23      * @see <a href="http://crs.bkg.bund.de/crseu/crs/descrtrans/eu-descrtrans.php?crs_id=REVfREhETiAvIEdLXzM=&op_id=REVfREhETiAoQmVUQSwgMjAwNykgdG8gRVRSUzg5">
    24      * Description of Transformation - DE_DHDN (BeTA, 2007) to ETRS89</a>
    25      */
    26     public static final NTV2GridShiftFileWrapper BETA2007 = new NTV2GridShiftFileWrapper("resource://data/projection/BETA2007.gsb");
    27 
    28     /**
    29      * Used in France to convert coordinates between the NTF (<i>Nouvelle triangulation de la France</i>)
    30      * and RGF93 (<i>Réseau géodésique français 1993</i>) datums.
    31      * @see <a href="http://geodesie.ign.fr/contenu/fichiers/documentation/algorithmes/notice/NT111_V1_HARMEL_TransfoNTF-RGF93_FormatGrilleNTV2.pdf">
    32      * [French] Transformation de coordonnées NTF – RGF93 / Format de grille NTv2</a>
    33      */
    34     public static final NTV2GridShiftFileWrapper ntf_rgf93 = new NTV2GridShiftFileWrapper("resource://data/projection/ntf_r93_b.gsb");
    35 
    36     // CHECKSTYLE.ON: LineLength
    37 
    3819    private NTV2GridShiftFile instance;
    3920    private final String gridFileName;
    4021
     
    5031     * Returns the actual {@link NTV2GridShiftFile} behind this wrapper.
    5132     * The grid file is only loaded once, when first accessed.
    5233     * @return The NTv2 grid file
     34     * @throws IOException if the grid file cannot be found/loaded
    5335     */
    54     public NTV2GridShiftFile getShiftFile() {
     36    public synchronized NTV2GridShiftFile getShiftFile() throws IOException {
    5537        if (instance == null) {
    56             try (CachedFile cf = new CachedFile(gridFileName); InputStream is = cf.getInputStream()) {
    57                 instance = new NTV2GridShiftFile();
    58                 instance.loadGridShiftFile(is, false);
    59             } catch (IOException e) {
    60                 throw new JosmRuntimeException(e);
     38            File grid = null;
     39            // Check is the grid is installed in default PROJ.4 directories
     40            for (File dir : Main.platform.getDefaultProj4NadshiftDirectories()) {
     41                File file = new File(dir, gridFileName);
     42                if (file.exists() && file.isFile()) {
     43                    grid = file;
     44                    break;
     45                }
     46            }
     47            // If not, search into PROJ_LIB directory
     48            if (grid == null) {
     49                String projLib = System.getProperty("PROJ_LIB");
     50                if (projLib != null && !projLib.isEmpty()) {
     51                    File dir = new File(projLib);
     52                    if (dir.exists() && dir.isDirectory()) {
     53                        File file = new File(dir, gridFileName);
     54                        if (file.exists() && file.isFile()) {
     55                            grid = file;
     56                        }
     57                    }
     58                }
     59            }
     60            // If not, retrieve it from JOSM website
     61            String location = grid != null ? grid.getAbsolutePath() : (Main.getJOSMWebsite() + "/grid/" + gridFileName);
     62            // Try to load grid file
     63            try (CachedFile cf = new CachedFile(location); InputStream is = cf.getInputStream()) {
     64                NTV2GridShiftFile ntv2 = new NTV2GridShiftFile();
     65                ntv2.loadGridShiftFile(is, false);
     66                instance = ntv2;
    6167            }
    6268        }
    6369        return instance;
  • src/org/openstreetmap/josm/tools/PlatformHook.java

     
    88import java.security.KeyStoreException;
    99import java.security.NoSuchAlgorithmException;
    1010import java.security.cert.CertificateException;
     11import java.util.List;
    1112
    1213/**
    1314 * This interface allows platform (operating system) dependent code
     
    171172     * @since 7834
    172173     */
    173174    File getDefaultUserDataDirectory();
     175
     176    /**
     177     * Returns the list of platform-dependent default datum shifting directories for the PROJ.4 library.
     178     * @return the list of platform-dependent default datum shifting directories for the PROJ.4 library
     179     * @since 11640
     180     */
     181    List<File> getDefaultProj4NadshiftDirectories();
    174182}
  • src/org/openstreetmap/josm/tools/PlatformHookOsx.java

     
    1414import java.lang.reflect.Method;
    1515import java.lang.reflect.Proxy;
    1616import java.util.Arrays;
     17import java.util.Collections;
    1718import java.util.List;
    1819
    1920import javax.swing.UIManager;
     
    381382        return new File(System.getProperty("user.home")+"/Library",
    382383                Main.pref.getJOSMDirectoryBaseName());
    383384    }
     385
     386    @Override
     387    public List<File> getDefaultProj4NadshiftDirectories() {
     388        return Collections.emptyList();
     389    }
    384390}
  • src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

     
    1717import java.nio.file.Path;
    1818import java.nio.file.Paths;
    1919import java.util.Arrays;
     20import java.util.List;
    2021import java.util.Locale;
    2122
    2223import javax.swing.JOptionPane;
     
    432433        }
    433434    }
    434435
     436    @Override
     437    public List<File> getDefaultProj4NadshiftDirectories() {
     438        return Arrays.asList(new File("/usr/local/share/proj"), new File("/usr/share/proj"));
     439    }
    435440}
  • src/org/openstreetmap/josm/tools/PlatformHookWindows.java

     
    5252import java.security.spec.InvalidKeySpecException;
    5353import java.security.spec.X509EncodedKeySpec;
    5454import java.util.ArrayList;
     55import java.util.Arrays;
    5556import java.util.Collection;
    5657import java.util.Enumeration;
    5758import java.util.List;
     
    571572
    572573        return def;
    573574    }
     575
     576    @Override
     577    public List<File> getDefaultProj4NadshiftDirectories() {
     578        return Arrays.asList(new File("C:\\PROJ\\NAD"));
     579    }
    574580}