Class MultipolygonTest
- java.lang.Object
-
- org.openstreetmap.josm.data.validation.Test
-
- org.openstreetmap.josm.data.validation.tests.MultipolygonTest
-
- All Implemented Interfaces:
OsmPrimitiveVisitor
public class MultipolygonTest extends Test
Checks if multipolygons are valid- Since:
- 3669
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MultipolygonTest.ExtPolygonIntersection
private static class
MultipolygonTest.PolygonLevel
Helper class for calculation of nesting levelsprivate static class
MultipolygonTest.PolygonLevelFinder
Find nesting levels of polygons.-
Nested classes/interfaces inherited from class org.openstreetmap.josm.data.validation.Test
Test.TagTest
-
-
Field Summary
Fields Modifier and Type Field Description private Relation
createdRelation
set when used to build a multipolygon relationstatic int
CROSSING_WAYS
Intersection between multipolygon waysstatic int
EQUAL_RINGS
Multipolygon ring is equal to another ringprivate static int
FOUND_INSIDE
private static int
FOUND_OUTSIDE
private static java.lang.String
INNER
static int
INNER_STYLE_MISMATCH
With the currently used mappaint style the style for inner way equals the multipolygon stylestatic int
INNER_WAY_OUTSIDE
Multipolygon inner way is outsidestatic int
MODIFIED_INCOMPLETE
Incomplete multipolygon was modifiedstatic int
NO_STYLE
No area style for multipolygonstatic int
NON_CLOSED_WAY
Multipolygon is not closedprivate static java.lang.String
OUTER
static int
OUTER_STYLE
Area style on outer waystatic int
OUTER_STYLE_MISMATCH
Style for outer way mismatches / With the currently used mappaint style(s) the style for outer way mismatches the area styleprivate boolean
repeatCheck
might be set when creating a relation and touching rings were found.static int
REPEATED_MEMBER_DIFF_ROLE
Multipolygon member repeated (same primitive, different role)static int
REPEATED_MEMBER_SAME_ROLE
Multipolygon member repeated (same primitive, same rolestatic int
RINGS_SHARE_NODES
Multipolygon rings share nodesstatic int
WRONG_MEMBER_ROLE
No useful role for multipolygon memberstatic int
WRONG_MEMBER_TYPE
Non-Way in multipolygon-
Fields inherited from class org.openstreetmap.josm.data.validation.Test
checkBeforeUpload, checkEnabled, description, enabled, errors, IN_DOWNLOADED_AREA, IN_DOWNLOADED_AREA_STRICT, isBeforeUpload, name, partialSelection, progressMonitor, stopwatch, testBeforeUpload
-
-
Constructor Summary
Constructors Constructor Description MultipolygonTest()
Constructs a newMultipolygonTest
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addRepeatedMemberError(Relation r, java.util.List<OsmPrimitive> repeatedMembers, int errorCode, java.lang.String msg)
private void
checkGeometryAndRoles(Relation r, Multipolygon polygon)
Various geometry-related checks:NON_CLOSED_WAY
: Multipolygon is not closedINNER_WAY_OUTSIDE
: Multipolygon inner way is outsideCROSSING_WAYS
: Intersection between multipolygon waysprivate static boolean
checkIfNodeIsInsidePolygon(Node n, Multipolygon.PolyData p)
Check if a node is inside the polygon according to the insideness rules of Shape.private boolean
checkMembersAndRoles(Relation r, java.util.List<TestError> tmpErrors)
Check for:WRONG_MEMBER_ROLE
: No useful role for multipolygon memberWRONG_MEMBER_TYPE
: Non-Way in multipolygonprivate void
checkOrSetRoles(Relation r, java.util.List<Multipolygon.PolyData> allPolygons, java.util.Map<java.lang.Long,RelationMember> wayMap, java.util.Set<Node> sharedNodes)
Calculate the nesting levels of the polygon rings and check if calculated role matchesprivate static MultipolygonTest.ExtPolygonIntersection
checkOverlapAtSharedNodes(java.util.Set<Node> shared, Multipolygon.PolyData pd1, Multipolygon.PolyData pd2)
private void
checkPolygonForSelfIntersection(Relation r, Multipolygon.PolyData pd)
Check if a polygon ring is self-intersecting when the ring was build from multiple ways.private void
checkPolygonsForSharedNodes(Relation r, Multipolygon.PolyData pd1, Multipolygon.PolyData pd2, java.util.Set<Node> allSharedNodes)
private static boolean
checkProblemMap(java.util.Map<Multipolygon.PolyData,java.util.List<Multipolygon.PolyData>> problemPolyMap, Multipolygon.PolyData pd1, Multipolygon.PolyData pd2)
Check if map contains combination of two given polygons.private boolean
checkRepeatedWayMembers(Relation r)
Check for:REPEATED_MEMBER_DIFF_ROLE
: Multipolygon member repeated with different roleREPEATED_MEMBER_SAME_ROLE
: Multipolygon member repeated with same roleprivate void
checkStyleConsistency(Relation r, Multipolygon polygon)
Various style-related checks:NO_STYLE
: No area style for multipolygonINNER_STYLE_MISMATCH
: With the currently used mappaint style the style for inner way equals the multipolygon styleOUTER_STYLE_MISMATCH
: With the currently used mappaint style the style for outer way mismatches the area styleOUTER_STYLE
: Area style on outer wayprivate static java.util.Collection<? extends OsmPrimitive>
combineRelAndPrimitives(Relation r, java.util.Collection<? extends OsmPrimitive> primitives)
private static java.util.Map<java.util.List<Way>,java.util.List<WaySegment>>
findIntersectingWays(Relation r, boolean findSharedWaySegments)
SeeCrossingWays
private java.util.Map<Multipolygon.PolyData,java.util.List<Multipolygon.PolyData>>
findIntersectingWays(Relation r, java.util.List<Multipolygon.PolyData> innerPolygons, java.util.List<Multipolygon.PolyData> outerPolygons)
Determine multipolygon ways which are intersecting (crossing without a common node) or sharing one or more way segments.private void
findIntersectingWaysIncomplete(Relation r)
Determine multipolygon ways which are intersecting (crossing without a common node) or sharing one or more way segments.private static void
findIntersectionNodes(Relation r, java.util.Set<Node> sharedNodes, java.util.Set<Way> intersectionWays)
Detect intersections of multipolygon ways at nodes.Command
fixError(TestError testError)
Fixes the error with the appropriate commandprivate static boolean
hasIntersectionWay(Multipolygon.PolyData pd, java.util.Set<Way> intersectionWays)
Simple check if given ring contains way that is known to intersect.boolean
isFixable(TestError testError)
Returns true if the given error can be fixed automaticallyRelation
makeFromWays(java.util.Collection<Way> ways)
Create a multipolygon relation from the given ways and test it.void
visit(Relation r)
Visiting call for relations.-
Methods inherited from class org.openstreetmap.josm.data.validation.Test
addGui, clear, deletePrimitivesIfNeeded, endTest, getErrors, getName, getSource, initialize, isBuilding, isCanceled, isPrimitiveUsable, isResidentialArea, ok, removeIrrelevantErrors, setBeforeUpload, setPartialSelection, setShowElements, startTest, testBeforeUpload, visit, visit, visit
-
-
-
-
Field Detail
-
OUTER
private static final java.lang.String OUTER
- See Also:
- Constant Field Values
-
INNER
private static final java.lang.String INNER
- See Also:
- Constant Field Values
-
WRONG_MEMBER_TYPE
public static final int WRONG_MEMBER_TYPE
Non-Way in multipolygon- See Also:
- Constant Field Values
-
WRONG_MEMBER_ROLE
public static final int WRONG_MEMBER_ROLE
No useful role for multipolygon member- See Also:
- Constant Field Values
-
NON_CLOSED_WAY
public static final int NON_CLOSED_WAY
Multipolygon is not closed- See Also:
- Constant Field Values
-
INNER_WAY_OUTSIDE
public static final int INNER_WAY_OUTSIDE
Multipolygon inner way is outside- See Also:
- Constant Field Values
-
CROSSING_WAYS
public static final int CROSSING_WAYS
Intersection between multipolygon ways- See Also:
- Constant Field Values
-
OUTER_STYLE_MISMATCH
public static final int OUTER_STYLE_MISMATCH
Style for outer way mismatches / With the currently used mappaint style(s) the style for outer way mismatches the area style- See Also:
- Constant Field Values
-
INNER_STYLE_MISMATCH
public static final int INNER_STYLE_MISMATCH
With the currently used mappaint style the style for inner way equals the multipolygon style- See Also:
- Constant Field Values
-
NO_STYLE
public static final int NO_STYLE
No area style for multipolygon- See Also:
- Constant Field Values
-
OUTER_STYLE
public static final int OUTER_STYLE
Area style on outer way- See Also:
- Constant Field Values
-
REPEATED_MEMBER_SAME_ROLE
public static final int REPEATED_MEMBER_SAME_ROLE
Multipolygon member repeated (same primitive, same role- See Also:
- Constant Field Values
-
REPEATED_MEMBER_DIFF_ROLE
public static final int REPEATED_MEMBER_DIFF_ROLE
Multipolygon member repeated (same primitive, different role)- See Also:
- Constant Field Values
-
EQUAL_RINGS
public static final int EQUAL_RINGS
Multipolygon ring is equal to another ring- See Also:
- Constant Field Values
-
RINGS_SHARE_NODES
public static final int RINGS_SHARE_NODES
Multipolygon rings share nodes- See Also:
- Constant Field Values
-
MODIFIED_INCOMPLETE
public static final int MODIFIED_INCOMPLETE
Incomplete multipolygon was modified- See Also:
- Constant Field Values
-
FOUND_INSIDE
private static final int FOUND_INSIDE
- See Also:
- Constant Field Values
-
FOUND_OUTSIDE
private static final int FOUND_OUTSIDE
- See Also:
- Constant Field Values
-
createdRelation
private Relation createdRelation
set when used to build a multipolygon relation
-
repeatCheck
private boolean repeatCheck
might be set when creating a relation and touching rings were found.
-
-
Constructor Detail
-
MultipolygonTest
public MultipolygonTest()
Constructs a newMultipolygonTest
.
-
-
Method Detail
-
visit
public void visit(Relation r)
Description copied from interface:OsmPrimitiveVisitor
Visiting call for relations.- Specified by:
visit
in interfaceOsmPrimitiveVisitor
- Overrides:
visit
in classTest
- Parameters:
r
- The relation to inspect.
-
checkStyleConsistency
private void checkStyleConsistency(Relation r, Multipolygon polygon)
Various style-related checks:NO_STYLE
: No area style for multipolygonINNER_STYLE_MISMATCH
: With the currently used mappaint style the style for inner way equals the multipolygon styleOUTER_STYLE_MISMATCH
: With the currently used mappaint style the style for outer way mismatches the area styleOUTER_STYLE
: Area style on outer way
- Parameters:
r
- relationpolygon
- multipolygon
-
checkGeometryAndRoles
private void checkGeometryAndRoles(Relation r, Multipolygon polygon)
Various geometry-related checks:NON_CLOSED_WAY
: Multipolygon is not closedINNER_WAY_OUTSIDE
: Multipolygon inner way is outsideCROSSING_WAYS
: Intersection between multipolygon ways
- Parameters:
r
- relationpolygon
- multipolygon
-
hasIntersectionWay
private static boolean hasIntersectionWay(Multipolygon.PolyData pd, java.util.Set<Way> intersectionWays)
Simple check if given ring contains way that is known to intersect.- Parameters:
pd
- the ringintersectionWays
- the known intersection ways- Returns:
- true if one or more ways are in the set of known ways
-
checkPolygonForSelfIntersection
private void checkPolygonForSelfIntersection(Relation r, Multipolygon.PolyData pd)
Check if a polygon ring is self-intersecting when the ring was build from multiple ways. An self intersection in a single way is checked inSelfIntersectingWay
.- Parameters:
r
- the relationpd
- the ring
-
findIntersectionNodes
private static void findIntersectionNodes(Relation r, java.util.Set<Node> sharedNodes, java.util.Set<Way> intersectionWays)
Detect intersections of multipolygon ways at nodes. If any way node is used by more than two ways or two times in one way and at least once in another way we found an intersection.- Parameters:
r
- the relationsharedNodes
- We be filled with shared nodesintersectionWays
- We be filled with ways that have a shared node
-
checkPolygonsForSharedNodes
private void checkPolygonsForSharedNodes(Relation r, Multipolygon.PolyData pd1, Multipolygon.PolyData pd2, java.util.Set<Node> allSharedNodes)
-
checkOverlapAtSharedNodes
private static MultipolygonTest.ExtPolygonIntersection checkOverlapAtSharedNodes(java.util.Set<Node> shared, Multipolygon.PolyData pd1, Multipolygon.PolyData pd2)
-
checkOrSetRoles
private void checkOrSetRoles(Relation r, java.util.List<Multipolygon.PolyData> allPolygons, java.util.Map<java.lang.Long,RelationMember> wayMap, java.util.Set<Node> sharedNodes)
Calculate the nesting levels of the polygon rings and check if calculated role matches- Parameters:
r
- relation (for error reporting)allPolygons
- list of polygon ringswayMap
- maps way ids to relation memberssharedNodes
- all nodes shared by multiple ways of this multipolygon
-
checkIfNodeIsInsidePolygon
private static boolean checkIfNodeIsInsidePolygon(Node n, Multipolygon.PolyData p)
Check if a node is inside the polygon according to the insideness rules of Shape.- Parameters:
n
- the nodep
- the polygon- Returns:
- true if the node is inside the polygon
-
findIntersectingWays
private java.util.Map<Multipolygon.PolyData,java.util.List<Multipolygon.PolyData>> findIntersectingWays(Relation r, java.util.List<Multipolygon.PolyData> innerPolygons, java.util.List<Multipolygon.PolyData> outerPolygons)
Determine multipolygon ways which are intersecting (crossing without a common node) or sharing one or more way segments. See alsoCrossingWays
- Parameters:
r
- the relation (for error reporting)innerPolygons
- list of inner polygonsouterPolygons
- list of outer polygons- Returns:
- map with crossing polygons
-
findIntersectingWaysIncomplete
private void findIntersectingWaysIncomplete(Relation r)
Determine multipolygon ways which are intersecting (crossing without a common node) or sharing one or more way segments. This should only be used for relations with incomplete members. See alsoCrossingWays
- Parameters:
r
- the relation (for error reporting)
-
findIntersectingWays
private static java.util.Map<java.util.List<Way>,java.util.List<WaySegment>> findIntersectingWays(Relation r, boolean findSharedWaySegments)
SeeCrossingWays
- Parameters:
r
- the relationfindSharedWaySegments
- true: find shared way segments instead of crossings- Returns:
- map with crossing ways and the related segments
-
checkProblemMap
private static boolean checkProblemMap(java.util.Map<Multipolygon.PolyData,java.util.List<Multipolygon.PolyData>> problemPolyMap, Multipolygon.PolyData pd1, Multipolygon.PolyData pd2)
Check if map contains combination of two given polygons.- Parameters:
problemPolyMap
- the mappd1
- 1st polygonpd2
- 2nd polygon- Returns:
- true if the combination of polygons is found in the map
-
checkMembersAndRoles
private boolean checkMembersAndRoles(Relation r, java.util.List<TestError> tmpErrors)
Check for:WRONG_MEMBER_ROLE
: No useful role for multipolygon memberWRONG_MEMBER_TYPE
: Non-Way in multipolygon
- Parameters:
r
- relationtmpErrors
- list that will contain found errors- Returns:
- true if ways with roles other than inner, outer or empty where found
-
combineRelAndPrimitives
private static java.util.Collection<? extends OsmPrimitive> combineRelAndPrimitives(Relation r, java.util.Collection<? extends OsmPrimitive> primitives)
-
checkRepeatedWayMembers
private boolean checkRepeatedWayMembers(Relation r)
Check for:REPEATED_MEMBER_DIFF_ROLE
: Multipolygon member repeated with different roleREPEATED_MEMBER_SAME_ROLE
: Multipolygon member repeated with same role
- Parameters:
r
- relation- Returns:
- true if repeated members have been detected, false otherwise
-
addRepeatedMemberError
private void addRepeatedMemberError(Relation r, java.util.List<OsmPrimitive> repeatedMembers, int errorCode, java.lang.String msg)
-
fixError
public Command fixError(TestError testError)
Description copied from class:Test
Fixes the error with the appropriate command
-
isFixable
public boolean isFixable(TestError testError)
Description copied from class:Test
Returns true if the given error can be fixed automatically
-
makeFromWays
public Relation makeFromWays(java.util.Collection<Way> ways)
Create a multipolygon relation from the given ways and test it.- Parameters:
ways
- the collection of ways- Returns:
- a pair of a
Multipolygon
instance and the relation. - Since:
- 15160
-
-