Ignore:
Timestamp:
2016-08-15T21:30:34+02:00 (8 years ago)
Author:
simon04
Message:

see #7307 - Enhance GeoJSON export

  • Save ways as LineString or Polygon depending on the area style.
  • Save multipolygons as MultiPolygon.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r10797 r10817  
    1212import java.util.Comparator;
    1313import java.util.EnumSet;
    14 import java.util.HashSet;
    1514import java.util.LinkedHashSet;
    1615import java.util.List;
     
    2625import org.openstreetmap.josm.data.osm.BBox;
    2726import org.openstreetmap.josm.data.osm.MultipolygonBuilder;
     27import org.openstreetmap.josm.data.osm.MultipolygonBuilder.JoinedPolygon;
    2828import org.openstreetmap.josm.data.osm.Node;
    2929import org.openstreetmap.josm.data.osm.NodePositionComparator;
    3030import org.openstreetmap.josm.data.osm.OsmPrimitive;
    31 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    3231import org.openstreetmap.josm.data.osm.Relation;
    33 import org.openstreetmap.josm.data.osm.RelationMember;
    3432import org.openstreetmap.josm.data.osm.Way;
    3533import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
     
    863861    }
    864862
    865     public static class MultiPolygonMembers {
    866         public final Set<Way> outers = new HashSet<>();
    867         public final Set<Way> inners = new HashSet<>();
    868 
    869         public MultiPolygonMembers(Relation multiPolygon) {
    870             for (RelationMember m : multiPolygon.getMembers()) {
    871                 if (m.getType().equals(OsmPrimitiveType.WAY)) {
    872                     if ("outer".equals(m.getRole())) {
    873                         outers.add(m.getWay());
    874                     } else if ("inner".equals(m.getRole())) {
    875                         inners.add(m.getWay());
    876                     }
    877                 }
    878             }
    879         }
    880     }
    881 
    882863    /**
    883864     * Tests if the {@code node} is inside the multipolygon {@code multiPolygon}. The nullable argument
     
    904885    public static boolean isPolygonInsideMultiPolygon(List<Node> nodes, Relation multiPolygon, Predicate<Way> isOuterWayAMatch) {
    905886        // Extract outer/inner members from multipolygon
    906         final MultiPolygonMembers mpm = new MultiPolygonMembers(multiPolygon);
    907         // Construct complete rings for the inner/outer members
    908         final List<MultipolygonBuilder.JoinedPolygon> outerRings;
    909         final List<MultipolygonBuilder.JoinedPolygon> innerRings;
     887        final Pair<List<JoinedPolygon>, List<JoinedPolygon>> outerInner;
    910888        try {
    911             outerRings = MultipolygonBuilder.joinWays(mpm.outers);
    912             innerRings = MultipolygonBuilder.joinWays(mpm.inners);
     889            outerInner = MultipolygonBuilder.joinWays(multiPolygon);
    913890        } catch (MultipolygonBuilder.JoinedPolygonCreationException ex) {
    914891            Main.trace(ex);
     
    917894        }
    918895        // Test if object is inside an outer member
    919         for (MultipolygonBuilder.JoinedPolygon out : outerRings) {
     896        for (JoinedPolygon out : outerInner.a) {
    920897            if (nodes.size() == 1
    921898                    ? nodeInsidePolygon(nodes.get(0), out.getNodes())
     
    924901                boolean insideInner = false;
    925902                // If inside an outer, check it is not inside an inner
    926                 for (MultipolygonBuilder.JoinedPolygon in : innerRings) {
     903                for (JoinedPolygon in : outerInner.b) {
    927904                    if (polygonIntersection(in.getNodes(), out.getNodes()) == PolygonIntersection.FIRST_INSIDE_SECOND
    928905                            && (nodes.size() == 1
Note: See TracChangeset for help on using the changeset viewer.