Ticket #14422: 14422.patch
File 14422.patch, 15.8 KB (added by , 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
112 112 import org.openstreetmap.josm.tools.Shortcut; 113 113 import org.openstreetmap.josm.tools.Territories; 114 114 import org.openstreetmap.josm.tools.Utils; 115 import org.openstreetmap.josm.tools.bugreport.BugReport; 115 116 116 117 /** 117 118 * Abstract class holding various static global variables and methods used in large parts of JOSM application. … … 522 523 KeyEvent.VK_F1, Shortcut.DIRECT)); 523 524 524 525 // 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 } 526 533 527 534 // contains several initialization tasks to be executed (in parallel) by a ExecutorService 528 535 List<Callable<Void>> tasks = new ArrayList<>(); -
src/org/openstreetmap/josm/data/projection/Projections.java
49 49 /** 50 50 * Class to manage projections. 51 51 * 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. 54 53 */ 55 54 public final class Projections { 56 55 … … 58 57 * Class to hold information about one projection. 59 58 */ 60 59 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; 64 63 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 */ 65 70 public ProjectionDefinition(String code, String name, String definition) { 66 71 this.code = code; 67 72 this.name = name; … … 140 145 "Potsdam Rauenberg 1950 DHDN", "potsdam", 141 146 Ellipsoid.Bessel1841, 598.1, 73.7, 418.2, 0.202, 0.045, -2.455, 6.7)); 142 147 143 nadgrids.put("BETA2007.gsb", NTV2GridShiftFileWrapper.BETA2007);144 nadgrids.put("ntf_r93_b.gsb", NTV2GridShiftFileWrapper.ntf_rgf93);145 146 List<ProjectionDefinition> pds;147 148 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 } 149 154 } catch (IOException ex) { 150 155 throw new JosmRuntimeException(ex); 151 156 } 152 inits = new LinkedHashMap<>();153 for (ProjectionDefinition pd : pds) {154 inits.put(pd.code, pd);155 }156 157 157 158 for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) { 158 159 for (String code : pc.allCodes()) { … … 167 168 // Hide default constructor for utils classes 168 169 } 169 170 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 170 188 /** 171 189 * Convert from lat/lon to easting/northing using the current projection. 172 190 * -
src/org/openstreetmap/josm/data/projection/datum/NTV2Datum.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.projection.datum; 3 3 4 import java.io.IOException; 5 4 6 import org.openstreetmap.josm.data.coor.LatLon; 5 7 import org.openstreetmap.josm.data.projection.Ellipsoid; 8 import org.openstreetmap.josm.tools.JosmRuntimeException; 6 9 7 10 /** 8 11 * Datum based of NTV2 grid shift file. 9 12 */ 10 13 public class NTV2Datum extends AbstractDatum { 11 14 12 pr otectedNTV2GridShiftFileWrapper nadgrids;15 private final NTV2GridShiftFileWrapper nadgrids; 13 16 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 */ 14 24 public NTV2Datum(String name, String proj4Id, Ellipsoid ellps, NTV2GridShiftFileWrapper nadgrids) { 15 25 super(name, proj4Id, ellps); 16 26 this.nadgrids = nadgrids; … … 19 29 @Override 20 30 public LatLon toWGS84(LatLon ll) { 21 31 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 } 24 38 } 25 39 26 40 @Override 27 41 public LatLon fromWGS84(LatLon ll) { 28 42 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 } 31 49 } 32 50 } -
src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFileWrapper.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.projection.datum; 3 3 4 import java.io.File; 4 5 import java.io.IOException; 5 6 import java.io.InputStream; 6 7 8 import org.openstreetmap.josm.Main; 7 9 import org.openstreetmap.josm.io.CachedFile; 8 import org.openstreetmap.josm.tools.JosmRuntimeException;9 10 10 11 /** 11 12 * Wrapper for {@link NTV2GridShiftFile}. … … 15 16 */ 16 17 public class NTV2GridShiftFileWrapper { 17 18 18 // CHECKSTYLE.OFF: LineLength19 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: LineLength37 38 19 private NTV2GridShiftFile instance; 39 20 private final String gridFileName; 40 21 … … 50 31 * Returns the actual {@link NTV2GridShiftFile} behind this wrapper. 51 32 * The grid file is only loaded once, when first accessed. 52 33 * @return The NTv2 grid file 34 * @throws IOException if the grid file cannot be found/loaded 53 35 */ 54 public NTV2GridShiftFile getShiftFile(){36 public synchronized NTV2GridShiftFile getShiftFile() throws IOException { 55 37 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; 61 67 } 62 68 } 63 69 return instance; -
src/org/openstreetmap/josm/tools/PlatformHook.java
8 8 import java.security.KeyStoreException; 9 9 import java.security.NoSuchAlgorithmException; 10 10 import java.security.cert.CertificateException; 11 import java.util.List; 11 12 12 13 /** 13 14 * This interface allows platform (operating system) dependent code … … 171 172 * @since 7834 172 173 */ 173 174 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(); 174 182 } -
src/org/openstreetmap/josm/tools/PlatformHookOsx.java
14 14 import java.lang.reflect.Method; 15 15 import java.lang.reflect.Proxy; 16 16 import java.util.Arrays; 17 import java.util.Collections; 17 18 import java.util.List; 18 19 19 20 import javax.swing.UIManager; … … 381 382 return new File(System.getProperty("user.home")+"/Library", 382 383 Main.pref.getJOSMDirectoryBaseName()); 383 384 } 385 386 @Override 387 public List<File> getDefaultProj4NadshiftDirectories() { 388 return Collections.emptyList(); 389 } 384 390 } -
src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
17 17 import java.nio.file.Path; 18 18 import java.nio.file.Paths; 19 19 import java.util.Arrays; 20 import java.util.List; 20 21 import java.util.Locale; 21 22 22 23 import javax.swing.JOptionPane; … … 432 433 } 433 434 } 434 435 436 @Override 437 public List<File> getDefaultProj4NadshiftDirectories() { 438 return Arrays.asList(new File("/usr/local/share/proj"), new File("/usr/share/proj")); 439 } 435 440 } -
src/org/openstreetmap/josm/tools/PlatformHookWindows.java
52 52 import java.security.spec.InvalidKeySpecException; 53 53 import java.security.spec.X509EncodedKeySpec; 54 54 import java.util.ArrayList; 55 import java.util.Arrays; 55 56 import java.util.Collection; 56 57 import java.util.Enumeration; 57 58 import java.util.List; … … 571 572 572 573 return def; 573 574 } 575 576 @Override 577 public List<File> getDefaultProj4NadshiftDirectories() { 578 return Arrays.asList(new File("C:\\PROJ\\NAD")); 579 } 574 580 }