Changeset 16311 in josm
- Timestamp:
- 2020-04-15T22:40:32+02:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/GeoJSONReader.java
r15865 r16311 24 24 import org.openstreetmap.josm.data.coor.EastNorth; 25 25 import org.openstreetmap.josm.data.coor.LatLon; 26 import org.openstreetmap.josm.data.osm.BBox; 26 27 import org.openstreetmap.josm.data.osm.DataSet; 27 28 import org.openstreetmap.josm.data.osm.Node; … … 267 268 268 269 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 } 269 275 final Node node = new Node(latlon); 270 276 getDataSet().addPrimitive(node); … … 277 283 } 278 284 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()); 281 288 282 289 final int size = latlons.size(); … … 295 302 296 303 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())); 298 306 if (doAutoclose) { 299 307 way.addNode(way.getNode(0)); 300 308 } 301 302 way.getNodes().stream().distinct().forEach(it -> getDataSet().addPrimitive(it));303 getDataSet().addPrimitive(way);304 309 305 310 return Optional.of(way); -
trunk/test/data/geo.json
r15424 r16311 22 22 [ 23 23 102.0, 24 0. 024 0.5 25 25 ], 26 26 [ -
trunk/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java
r15865 r16311 46 46 .doParseDataSet(in, null) 47 47 .getPrimitives(it -> true)); 48 assertEquals(2 1, primitives.size());48 assertEquals(20, primitives.size()); 49 49 50 50 final Node node1 = new Node(new LatLon(0.5, 102.0)); … … 56 56 57 57 final Way way1 = new Way(); 58 way1.addNode(new Node(new LatLon(0 , 102)));58 way1.addNode(new Node(new LatLon(0.5, 102.0))); 59 59 way1.addNode(new Node(new LatLon(1, 103))); 60 60 way1.addNode(new Node(new LatLon(0, 104))); … … 66 66 assertEquals("valueB", foundWay1.get().get("propB")); 67 67 assertEquals("0.0", foundWay1.get().get("propB2")); 68 assertEquals(foundNode1.get(), ((Way) foundWay1.get()).firstNode()); 69 assertEquals("valueA", ((Way) foundWay1.get()).firstNode().get("propA")); 68 70 69 71 final Way way2 = new Way();
Note:
See TracChangeset
for help on using the changeset viewer.