Ignore:
Timestamp:
2020-04-15T22:40:32+02:00 (4 years ago)
Author:
simon04
Message:

fix #19041 - GeoJSONReader: reuse node on same at same position to

Avoids multiple nodes on top of each other. Avoid creating unconnected polygons.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/GeoJSONReader.java

    r15865 r16311  
    2424import org.openstreetmap.josm.data.coor.EastNorth;
    2525import org.openstreetmap.josm.data.coor.LatLon;
     26import org.openstreetmap.josm.data.osm.BBox;
    2627import org.openstreetmap.josm.data.osm.DataSet;
    2728import org.openstreetmap.josm.data.osm.Node;
     
    267268
    268269    private Node createNode(final LatLon latlon) {
     270        final List<Node> existingNodes = getDataSet().searchNodes(new BBox(latlon, latlon));
     271        if (!existingNodes.isEmpty()) {
     272            // reuse existing node, avoid multiple nodes on top of each other
     273            return existingNodes.get(0);
     274        }
    269275        final Node node = new Node(latlon);
    270276        getDataSet().addPrimitive(node);
     
    277283        }
    278284
    279         final List<LatLon> latlons = coordinates.stream().map(
    280                 coordinate -> getLatLon(coordinate.asJsonArray())).collect(Collectors.toList());
     285        final List<LatLon> latlons = coordinates.stream()
     286                .map(coordinate -> getLatLon(coordinate.asJsonArray()))
     287                .collect(Collectors.toList());
    281288
    282289        final int size = latlons.size();
     
    295302
    296303        final Way way = new Way();
    297         way.setNodes(latlons.stream().map(Node::new).collect(Collectors.toList()));
     304        getDataSet().addPrimitive(way);
     305        way.setNodes(latlons.stream().map(this::createNode).collect(Collectors.toList()));
    298306        if (doAutoclose) {
    299307            way.addNode(way.getNode(0));
    300308        }
    301 
    302         way.getNodes().stream().distinct().forEach(it -> getDataSet().addPrimitive(it));
    303         getDataSet().addPrimitive(way);
    304309
    305310        return Optional.of(way);
Note: See TracChangeset for help on using the changeset viewer.