Changeset 33358 in osm for applications/editors/josm/plugins/opendata
- Timestamp:
- 2017-06-01T00:05:55+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/opendata
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/build.xml
r33245 r33358 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <project name="opendata" default="dist" basedir="."> 3 <property name="plugin.main.version" value="1 1919"/>3 <property name="plugin.main.version" value="12287"/> 4 4 <property name="plugin.author" value="Don-vip"/> 5 5 <property name="plugin.class" value="org.openstreetmap.josm.plugins.opendata.OdPlugin"/> -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/DataSetUpdater.java
r30723 r33358 4 4 import java.io.File; 5 5 import java.text.SimpleDateFormat; 6 import java.util.ArrayList; 7 import java.util.Collections; 6 8 import java.util.Date; 9 import java.util.List; 10 import java.util.stream.Collectors; 7 11 8 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.actions.SimplifyWayAction; 14 import org.openstreetmap.josm.actions.SplitWayAction; 15 import org.openstreetmap.josm.actions.SplitWayAction.SplitWayResult; 9 16 import org.openstreetmap.josm.command.SequenceCommand; 10 17 import org.openstreetmap.josm.data.osm.DataSet; 18 import org.openstreetmap.josm.data.osm.Node; 11 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 20 import org.openstreetmap.josm.data.osm.Relation; 13 21 import org.openstreetmap.josm.data.osm.Way; 22 import org.openstreetmap.josm.io.OsmApi; 14 23 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 15 24 … … 17 26 18 27 public static final void updateDataSet(DataSet dataSet, AbstractDataSetHandler handler, File associatedFile) { 19 if (dataSet != null && handler != null) { 20 if (associatedFile != null) { 21 handler.setAssociatedFile(associatedFile); 22 long lastmodified = associatedFile.lastModified(); 23 if (lastmodified > 0) { 24 handler.setSourceDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date(lastmodified))); 28 if (dataSet != null) { 29 if (handler != null) { 30 if (associatedFile != null) { 31 handler.setAssociatedFile(associatedFile); 32 long lastmodified = associatedFile.lastModified(); 33 if (lastmodified > 0) { 34 handler.setSourceDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date(lastmodified))); 35 } 36 } 37 if (!Main.pref.getBoolean(OdConstants.PREF_RAWDATA)) { 38 handler.updateDataSet(dataSet); 39 } 40 handler.checkDataSetSource(dataSet); 41 handler.checkNames(dataSet); 42 } 43 // Simplify ways geometries 44 for (Way w : dataSet.getWays()) { 45 SequenceCommand command = SimplifyWayAction.simplifyWay(w, 0.25); 46 if (command != null) { 47 command.executeCommand(); 25 48 } 26 49 } 27 if (!Main.pref.getBoolean(OdConstants.PREF_RAWDATA)) { 28 handler.updateDataSet(dataSet); 50 // Split ways exceeding 90% of the API limit (currently 2000 nodes) 51 int max = (int) (0.9 * OsmApi.getOsmApi().getCapabilities().getMaxWayNodes()); 52 for (Way w : dataSet.getWays().stream() 53 .filter(w -> w.getNodesCount() > max) 54 .collect(Collectors.toList())) { 55 List<Node> atNodes = new ArrayList<>(); 56 if (w.isClosed()) { 57 atNodes.add(w.getNode(0)); 58 } 59 double n = Math.ceil(w.getNodesCount() / (double) max); 60 for (int i = 1; i < n; i++) { 61 atNodes.add(w.getNode((int) ((i / n) * w.getNodesCount()))); 62 } 63 SplitWayResult res = SplitWayAction.split(null, w, atNodes, Collections.emptyList()); 64 if (res != null) { 65 res.getCommand().executeCommand(); 66 } 29 67 } 30 handler.checkDataSetSource(dataSet);31 handler.checkNames(dataSet);32 68 // Replace multipolygons with single untagged member by their sole member 33 69 for (Relation r : dataSet.getRelations()) { … … 42 78 } 43 79 } 44 // Simplify ways geometries45 for (Way w : dataSet.getWays()) {46 SequenceCommand command = Main.main.menu.simplifyWay.simplifyWay(w, 0.25);47 if (command != null) {48 Main.main.undoRedo.addNoRedraw(command);49 }50 }51 80 } 52 81 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicReader.java
r33356 r33358 299 299 } 300 300 301 private static InputStream getEsriWkidStream() { 302 InputStream in = GeographicReader.class.getResourceAsStream(OdConstants.ESRI_WKID); 303 if (in == null) { 304 // Setup different for unit tests 305 in = GeographicReader.class.getResourceAsStream(OdConstants.ESRI_WKID.replaceFirst("/resources", "")); 306 } 307 return in; 308 } 309 301 310 private static void loadEsriWkid() throws IOException { 302 311 Main.info("Loading ESRI WKID database..."); 303 try (InputStream in = GeographicReader.class.getResourceAsStream(OdConstants.ESRI_WKID);312 try (InputStream in = getEsriWkidStream(); 304 313 JsonReader json = JsonProvider.provider().createReader(in)) { 305 314 JsonObject root = json.readObject();
Note:
See TracChangeset
for help on using the changeset viewer.