Changeset 11642 in josm
- Timestamp:
- 2017-02-28T22:54:27+01:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r11510 r11642 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 /** … … 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 -
trunk/src/org/openstreetmap/josm/data/projection/Projections.java
r11374 r11642 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 { … … 59 58 */ 60 59 public static class ProjectionDefinition { 61 public String code; 62 public String name; 63 public String definition; 64 60 public final String code; 61 public final String name; 62 public final String definition; 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; … … 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 }152 inits = new LinkedHashMap<>();153 for (ProjectionDefinition pd : pds) {154 inits.put(pd.code, pd);155 156 } 156 157 … … 166 167 private Projections() { 167 168 // Hide default constructor for utils classes 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 } 168 186 } 169 187 -
trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2Datum.java
r5226 r11642 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 /** … … 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); … … 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 … … 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 } -
trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFileWrapper.java
r11374 r11642 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 /** … … 15 16 */ 16 17 public class NTV2GridShiftFileWrapper { 17 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 18 38 19 private NTV2GridShiftFile instance; … … 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() + "/proj/" + 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 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
r11156 r11642 9 9 import java.security.NoSuchAlgorithmException; 10 10 import java.security.cert.CertificateException; 11 import java.util.List; 11 12 12 13 /** … … 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 11642 180 */ 181 List<File> getDefaultProj4NadshiftDirectories(); 174 182 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r11535 r11642 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 … … 382 383 Main.pref.getJOSMDirectoryBaseName()); 383 384 } 385 386 @Override 387 public List<File> getDefaultProj4NadshiftDirectories() { 388 return Collections.emptyList(); 389 } 384 390 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
r11613 r11642 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 … … 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 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r11218 r11642 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; … … 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 }
Note:
See TracChangeset
for help on using the changeset viewer.