Ignore:
Timestamp:
2017-06-01T00:05:55+02:00 (7 years ago)
Author:
donvip
Message:

fix #josm11166 - Long ways should be split into shorter segments during shapefile import

Location:
applications/editors/josm/plugins/opendata
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/build.xml

    r33245 r33358  
    11<?xml version="1.0" encoding="utf-8"?>
    22<project name="opendata" default="dist" basedir=".">
    3     <property name="plugin.main.version" value="11919"/>
     3    <property name="plugin.main.version" value="12287"/>
    44    <property name="plugin.author" value="Don-vip"/>
    55    <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  
    44import java.io.File;
    55import java.text.SimpleDateFormat;
     6import java.util.ArrayList;
     7import java.util.Collections;
    68import java.util.Date;
     9import java.util.List;
     10import java.util.stream.Collectors;
    711
    812import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.actions.SimplifyWayAction;
     14import org.openstreetmap.josm.actions.SplitWayAction;
     15import org.openstreetmap.josm.actions.SplitWayAction.SplitWayResult;
    916import org.openstreetmap.josm.command.SequenceCommand;
    1017import org.openstreetmap.josm.data.osm.DataSet;
     18import org.openstreetmap.josm.data.osm.Node;
    1119import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1220import org.openstreetmap.josm.data.osm.Relation;
    1321import org.openstreetmap.josm.data.osm.Way;
     22import org.openstreetmap.josm.io.OsmApi;
    1423import org.openstreetmap.josm.plugins.opendata.core.OdConstants;
    1524
     
    1726
    1827    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();
    2548                }
    2649            }
    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                }
    2967            }
    30             handler.checkDataSetSource(dataSet);
    31             handler.checkNames(dataSet);
    3268            // Replace multipolygons with single untagged member by their sole member
    3369            for (Relation r : dataSet.getRelations()) {
     
    4278                }
    4379            }
    44             // Simplify ways geometries
    45             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             }
    5180        }
    5281    }
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicReader.java

    r33356 r33358  
    299299    }
    300300
     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
    301310    private static void loadEsriWkid() throws IOException {
    302311        Main.info("Loading ESRI WKID database...");
    303         try (InputStream in = GeographicReader.class.getResourceAsStream(OdConstants.ESRI_WKID);
     312        try (InputStream in = getEsriWkidStream();
    304313            JsonReader json = JsonProvider.provider().createReader(in)) {
    305314            JsonObject root = json.readObject();
Note: See TracChangeset for help on using the changeset viewer.