Changeset 33356 in osm for applications/editors/josm/plugins/opendata
- Timestamp:
- 2017-05-31T22:27:33+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/opendata
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java
r33245 r33356 124 124 public static final String RESOURCE_PATH = "/resources/org/openstreetmap/josm/plugins/opendata/core/resources/"; 125 125 public static final String DICTIONARY_FR = RESOURCE_PATH+"dictionary.fr.csv"; 126 public static final String ESRI_WKID = RESOURCE_PATH+"wkid.json"; 126 127 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicReader.java
r33245 r33356 6 6 import java.awt.Component; 7 7 import java.awt.GraphicsEnvironment; 8 import java.io.IOException; 8 9 import java.io.InputStream; 10 import java.lang.reflect.Field; 9 11 import java.util.ArrayList; 10 12 import java.util.Arrays; … … 13 15 import java.util.List; 14 16 import java.util.Map; 15 17 import java.util.TreeMap; 18 19 import javax.json.JsonArray; 20 import javax.json.JsonObject; 21 import javax.json.JsonReader; 22 import javax.json.spi.JsonProvider; 16 23 import javax.swing.Icon; 17 24 import javax.swing.JOptionPane; … … 19 26 import org.geotools.factory.Hints; 20 27 import org.geotools.geometry.jts.JTS; 28 import org.geotools.metadata.iso.citation.Citations; 21 29 import org.geotools.referencing.AbstractIdentifiedObject; 22 30 import org.geotools.referencing.CRS; 31 import org.geotools.referencing.NamedIdentifier; 23 32 import org.geotools.referencing.crs.AbstractCRS; 24 33 import org.geotools.referencing.crs.AbstractDerivedCRS; … … 54 63 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; 55 64 import org.openstreetmap.josm.tools.UserCancelException; 65 import org.openstreetmap.josm.tools.Utils; 56 66 57 67 import com.vividsolutions.jts.geom.LineString; … … 78 88 protected CoordinateReferenceSystem crs; 79 89 protected MathTransform transform; 90 91 private static final Map<String, Integer> esriWkid = new TreeMap<>(); 80 92 81 93 public GeographicReader(GeographicHandler handler, GeographicHandler[] defaultHandlers) { … … 287 299 } 288 300 301 private static void loadEsriWkid() throws IOException { 302 Main.info("Loading ESRI WKID database..."); 303 try (InputStream in = GeographicReader.class.getResourceAsStream(OdConstants.ESRI_WKID); 304 JsonReader json = JsonProvider.provider().createReader(in)) { 305 JsonObject root = json.readObject(); 306 JsonArray wkids = root.getJsonArray("wkids"); 307 JsonArray labels = root.getJsonArray("labels"); 308 if (wkids.size() != labels.size()) { 309 throw new IllegalStateException(); 310 } 311 for (int i = 0; i < wkids.size(); i++) { 312 esriWkid.put(labels.getString(i), wkids.getInt(i)); 313 } 314 } 315 Main.info("ESRI WKID database loaded"); 316 } 317 318 private static Integer getEpsgCodeFromEsriWkid(String wkid) { 319 if (esriWkid.isEmpty()) { 320 try { 321 loadEsriWkid(); 322 } catch (IOException e) { 323 Main.error(e); 324 } 325 } 326 return esriWkid.get(wkid); 327 } 328 289 329 protected void findMathTransform(Component parent, boolean findSimiliarCrs) 290 330 throws FactoryException, UserCancelException, GeoMathTransformException { 291 331 try { 332 // Geotools relies on Authority identifiers to find suitable transformations 333 // but this information is optional in WKT and not defined in ESRI WKID database, so often missing in real-world files 334 if (crs instanceof AbstractIdentifiedObject && crs.getIdentifiers().isEmpty()) { 335 // If no identifier, attempt to find one in embedded ESRI database 336 String wkid = crs.getName().getCode(); 337 if (wkid != null) { 338 Integer epsgCode = getEpsgCodeFromEsriWkid(wkid); 339 if (epsgCode != null) { 340 try { 341 Field f = AbstractIdentifiedObject.class.getDeclaredField("identifiers"); 342 Utils.setObjectsAccessible(f); 343 f.set(crs, Collections.singleton(new NamedIdentifier(Citations.fromName("EPSG"), epsgCode.toString()))); 344 } catch (ReflectiveOperationException | SecurityException e) { 345 Main.error(e); 346 } 347 } 348 } 349 } 350 // Find math transformation 292 351 transform = CRS.findMathTransform(crs, wgs84); 293 352 } catch (OperationNotFoundException e) {
Note:
See TracChangeset
for help on using the changeset viewer.