- Timestamp:
- 2014-05-19T18:03:52+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/MultipolygonCreate.java
r7005 r7145 48 48 * @return list of nodes 49 49 */ 50 p rivateList<Node> getNodes() {50 public List<Node> getNodes() { 51 51 List<Node> nodes = new ArrayList<>(); 52 52 … … 108 108 * @return error description if the ways cannot be split, {@code null} if all fine. 109 109 */ 110 public String makeFromWays(Collection<Way> ways){ 110 public String makeFromWays(Collection<Way> ways) { 111 try { 112 List<JoinedPolygon> joinedWays = joinWays(ways); 113 //analyze witch way is inside witch outside. 114 return makeFromPolygons(joinedWays); 115 } catch (JoinedPolygonCreationException ex) { 116 return ex.getMessage(); 117 } 118 } 119 120 /** 121 * An exception indicating an error while joining ways to multipolygon rings. 122 */ 123 public static class JoinedPolygonCreationException extends RuntimeException { 124 public JoinedPolygonCreationException(String message) { 125 super(message); 126 } 127 } 128 129 /** 130 * Joins the given {@code ways} to multipolygon rings. 131 * @param ways the ways to join. 132 * @return a list of multipolygon rings. 133 * @throws JoinedPolygonCreationException if the creation fails. 134 */ 135 public static List<JoinedPolygon> joinWays(Collection<Way> ways) throws JoinedPolygonCreationException { 111 136 List<JoinedPolygon> joinedWays = new ArrayList<>(); 112 137 … … 117 142 for(Way w: ways) { 118 143 if (w.getNodesCount() < 2) { 119 return tr("Cannot add a way with only {0} nodes.", w.getNodesCount());144 throw new JoinedPolygonCreationException(tr("Cannot add a way with only {0} nodes.", w.getNodesCount())); 120 145 } 121 146 … … 162 187 163 188 if (adjacentWays.size() != 2) { 164 return tr("Each node must connect exactly 2 ways");189 throw new JoinedPolygonCreationException(tr("Each node must connect exactly 2 ways")); 165 190 } 166 191 … … 181 206 } 182 207 183 //analyze witch way is inside witch outside. 184 return makeFromPolygons(joinedWays); 208 return joinedWays; 185 209 } 186 210 -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r7072 r7145 24 24 import org.openstreetmap.josm.data.coor.LatLon; 25 25 import org.openstreetmap.josm.data.osm.BBox; 26 import org.openstreetmap.josm.data.osm.MultipolygonCreate; 26 27 import org.openstreetmap.josm.data.osm.Node; 27 28 import org.openstreetmap.josm.data.osm.NodePositionComparator; … … 860 861 public static boolean isPolygonInsideMultiPolygon(List<Node> nodes, Relation multiPolygon, Predicate<Way> isOuterWayAMatch) { 861 862 // Extract outer/inner members from multipolygon 862 MultiPolygonMembers mpm = new MultiPolygonMembers(multiPolygon); 863 final MultiPolygonMembers mpm = new MultiPolygonMembers(multiPolygon); 864 // Construct complete rings for the inner/outer members 865 final List<MultipolygonCreate.JoinedPolygon> outerRings; 866 final List<MultipolygonCreate.JoinedPolygon> innerRings; 867 try { 868 outerRings = MultipolygonCreate.joinWays(mpm.outers); 869 innerRings = MultipolygonCreate.joinWays(mpm.inners); 870 } catch (MultipolygonCreate.JoinedPolygonCreationException ex) { 871 Main.debug("Invalid multipolygon " + multiPolygon); 872 return false; 873 } 863 874 // Test if object is inside an outer member 864 for ( Way out : mpm.outers) {875 for (MultipolygonCreate.JoinedPolygon out : outerRings) { 865 876 if (nodes.size() == 1 866 877 ? nodeInsidePolygon(nodes.get(0), out.getNodes()) … … 868 879 boolean insideInner = false; 869 880 // If inside an outer, check it is not inside an inner 870 for ( Way in : mpm.inners) {881 for (MultipolygonCreate.JoinedPolygon in : innerRings) { 871 882 if (polygonIntersection(in.getNodes(), out.getNodes()) == PolygonIntersection.FIRST_INSIDE_SECOND 872 883 && (nodes.size() == 1 … … 880 891 if (!insideInner) { 881 892 // Final check using predicate 882 if (isOuterWayAMatch == null || isOuterWayAMatch.evaluate(out )) {893 if (isOuterWayAMatch == null || isOuterWayAMatch.evaluate(out.ways.get(0) /* TODO give a better representation of the outer ring to the predicate */)) { 883 894 return true; 884 895 }
Note:
See TracChangeset
for help on using the changeset viewer.