Changeset 12941 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2017-10-08T11:28:05+02:00 (2 years ago)
Author:
GerdP
Message:

fix #14766 - Self-intersection check not working for multipolygons

The test failed to detect self-intersecting rings formed by multiple ways.
This is now handled. Single self-intersecting ways are still only handled by SelfIntersectingWay to avoind duplicate warnings for the same issue.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r12905 r12941  
    277277            for (int i = 0; i < allPolygons.size(); i++) {
    278278                PolyData pd1 = allPolygons.get(i);
     279                checkPolygonForSelfIntersection(r, pd1);
    279280                for (int j = i + 1; j < allPolygons.size(); j++) {
    280281                    PolyData pd2 = allPolygons.get(j);
     
    296297            // now we can calculate the nesting level to verify the roles with some simple node checks
    297298            checkRoles(r, allPolygons, wayMap, sharedNodes);
     299        }
     300    }
     301
     302    /**
     303     * Check if a polygon ring is self-intersecting when the ring was build from multiple ways.
     304     * An self intersection in a single way is checked in {@link SelfIntersectingWay}.
     305     * @param r the relation
     306     * @param pd the ring
     307     */
     308    private void checkPolygonForSelfIntersection(Relation r, PolyData pd) {
     309        if (pd.getWayIds().size() == 1)
     310            return;
     311        List<Node> wayNodes = pd.getNodes();
     312        int num = wayNodes.size();
     313        Set<Node> nodes = new HashSet<>();
     314        Node firstNode = wayNodes.get(0);
     315        nodes.add(firstNode);
     316        List<Node> isNodes = new ArrayList<>();
     317        for (int i = 1; i < num - 1; i++) {
     318            Node n = wayNodes.get(i);
     319            if (nodes.contains(n)) {
     320                isNodes.add(n);
     321            } else {
     322                nodes.add(n);
     323            }
     324        }
     325        if (!isNodes.isEmpty()) {
     326            List<OsmPrimitive> prims = new ArrayList<>();
     327            prims.add(r);
     328            prims.addAll(isNodes);
     329            errors.add(TestError.builder(this, Severity.WARNING, CROSSING_WAYS)
     330                    .message(tr("Self-intersecting polygon ring"))
     331                    .primitives(prims)
     332                    .highlight(isNodes)
     333                    .build());
     334
    298335        }
    299336    }
Note: See TracChangeset for help on using the changeset viewer.