Changeset 33496 in osm for applications/editors/josm/plugins
- Timestamp:
- 2017-08-13T19:15:28+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/actions/ComputeBoundsAction.java
r33493 r33496 26 26 import org.openstreetmap.josm.data.coor.LatLon; 27 27 import org.openstreetmap.josm.data.osm.BBox; 28 import org.openstreetmap.josm.data.osm.Node; 28 29 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 30 import org.openstreetmap.josm.data.osm.Relation; 30 31 import org.openstreetmap.josm.data.osm.RelationMember; 31 32 import org.openstreetmap.josm.data.osm.Way; 33 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; 34 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.JoinedWay; 35 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData; 32 36 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 33 37 import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsConstants; … … 305 309 protected static final boolean isValidOuterMember(RelationMember mb) { 306 310 return (mb.getRole() == null || mb.getRole().isEmpty() || "outer".equals(mb.getRole())) 307 && mb.getMember() instanceof Way && ((Way) mb.getMember()).isClosed(); 311 && mb.getMember() instanceof Way; 312 } 313 314 protected static final boolean isValidOuterClosedMember(RelationMember mb) { 315 return isValidOuterMember(mb) && ((Way) mb.getMember()).isClosed(); 308 316 } 309 317 310 318 protected static final String getMultiPolygonBounds(Relation mp) { 311 List<Way> outerClosedWays = new ArrayList<>(); 312 for (RelationMember mb : mp.getMembers()) { 313 if (isValidOuterMember(mb)) { 314 outerClosedWays.add((Way) mb.getMember()); 315 } 316 } 317 318 if (outerClosedWays.isEmpty() || (outerClosedWays.size() == 1 && areClosedWayAndBboxEqual(outerClosedWays.get(0), mp.getBBox()))) { 319 List<PolyData> polygons = new Multipolygon(mp).getOuterPolygons(); 320 if (polygons.isEmpty() || (polygons.size() == 1 && areJoinedWayAndBboxEqual(polygons.get(0), mp.getBBox()))) { 319 321 return getBounds(mp, true); 320 322 } else { 321 323 StringBuilder result = new StringBuilder(getBounds(mp, false)); 322 for ( Way way : outerClosedWays) {323 result.append(get ClosedWayShape(way));324 for (PolyData way : polygons) { 325 result.append(getJoinedWayShape(way)); 324 326 } 325 327 result.append(" </bounds>"); … … 329 331 330 332 protected static final boolean areClosedWayAndBboxEqual(Way way, BBox bBox) { 331 if (way.getNodesCount() == 5) { 333 return areNodeListAndBboxEqual(way.getNodes(), bBox); 334 } 335 336 protected static final boolean areJoinedWayAndBboxEqual(JoinedWay way, BBox bBox) { 337 return areNodeListAndBboxEqual(way.getNodes(), bBox); 338 } 339 340 protected static final boolean areNodeListAndBboxEqual(List<Node> nodes, BBox bBox) { 341 if (nodes.size() == 5) { 332 342 Map<Double, List<Integer>> latMap = new HashMap<>(); 333 343 Map<Double, List<Integer>> lonMap = new HashMap<>(); 334 344 335 345 for (int i=0; i<4; i++) { 336 LatLon c = way.getNode(i).getCoor();346 LatLon c = nodes.get(i).getCoor(); 337 347 if (i > 1) { 338 LatLon b = way.getNode(i-1).getCoor();348 LatLon b = nodes.get(i-1).getCoor(); 339 349 if (b.lat() != c.lat() && b.lon() != c.lon()) { 340 350 return false; … … 371 381 372 382 protected static final String getClosedWayShape(Way cw) { 383 return getNodeListShape(cw.getNodes()); 384 } 385 386 protected static final String getJoinedWayShape(JoinedWay jw) { 387 return getNodeListShape(jw.getNodes()); 388 } 389 390 protected static final String getNodeListShape(List<Node> nodes) { 373 391 StringBuilder result = new StringBuilder(" <shape>\n"); 374 for (int i=0; i<cw.getNodesCount(); i++) { 392 int size = nodes.size(); 393 for (int i=0; i<size; i++) { 375 394 if (i%3 == 0) { 376 395 result.append(" "); 377 396 } 378 397 int j = i; 379 if (j == cw.getNodesCount())398 if (j == size) 380 399 j = 0; 400 LatLon ll = nodes.get(i).getCoor(); 381 401 result.append("<point lat='") 382 .append(DF.format( cw.getNode(i).getCoor().lat())).append("' lon='")383 .append(DF.format( cw.getNode(i).getCoor().lon())).append("'/>");384 if (i%3 == 2 || i == cw.getNodesCount()-1) {402 .append(DF.format(ll.lat())).append("' lon='") 403 .append(DF.format(ll.lon())).append("'/>"); 404 if (i%3 == 2 || i == size-1) { 385 405 result.append('\n'); 386 406 }
Note:
See TracChangeset
for help on using the changeset viewer.