Changeset 9952 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2016-03-07T23:29:30+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r9951 r9952 27 27 import org.openstreetmap.josm.data.osm.Node; 28 28 import org.openstreetmap.josm.data.osm.NodePositionComparator; 29 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 30 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 30 31 import org.openstreetmap.josm.data.osm.Relation; 31 32 import org.openstreetmap.josm.data.osm.RelationMember; 32 33 import org.openstreetmap.josm.data.osm.Way; 34 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; 35 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 33 36 import org.openstreetmap.josm.data.projection.Projection; 34 37 import org.openstreetmap.josm.data.projection.Projections; … … 638 641 public static double closedWayArea(Way way) { 639 642 return getAreaAndPerimeter(way.getNodes(), Projections.getProjectionByCode("EPSG:54008")).getArea(); 643 } 644 645 /** 646 * Returns area of a multipolygon in square meters. 647 * 648 * @param multipolygon the multipolygon to measure 649 * @return area of the multipolygon. 650 */ 651 public static double multipolygonArea(Relation multipolygon) { 652 double area = 0.0; 653 final Multipolygon mp = Main.map == null || Main.map.mapView == null 654 ? new Multipolygon(multipolygon) 655 : MultipolygonCache.getInstance().get(Main.map.mapView, multipolygon); 656 for (Multipolygon.PolyData pd : mp.getCombinedPolygons()) { 657 area += pd.getAreaAndPerimeter(Projections.getProjectionByCode("EPSG:54008")).getArea(); 658 } 659 return area; 660 } 661 662 /** 663 * Computes the area of a closed way and multipolygon in square meters, or {@code null} for other primitives 664 * 665 * @param osm the primitive to measure 666 * @return area of the primitive, or {@code null} 667 */ 668 public static Double computeArea(OsmPrimitive osm) { 669 if (osm instanceof Way && ((Way) osm).isClosed()) { 670 return closedWayArea((Way) osm); 671 } else if (osm instanceof Relation && ((Relation) osm).isMultipolygon() && !((Relation) osm).hasIncompleteMembers()) { 672 return multipolygonArea((Relation) osm); 673 } else { 674 return null; 675 } 640 676 } 641 677
Note: See TracChangeset
for help on using the changeset viewer.