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 classMultipolygonTest.ExtPolygonIntersectionprivate static classMultipolygonTest.PolygonLevelHelper class for calculation of nesting levelsprivate static classMultipolygonTest.PolygonLevelFinderFind 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 RelationcreatedRelationset when used to build a multipolygon relationstatic intCROSSING_WAYSIntersection between multipolygon waysstatic intEQUAL_RINGSMultipolygon ring is equal to another ringprivate static intFOUND_INSIDEprivate static intFOUND_OUTSIDEprivate static java.lang.StringINNERstatic intINNER_STYLE_MISMATCHWith the currently used mappaint style the style for inner way equals the multipolygon stylestatic intINNER_WAY_OUTSIDEMultipolygon inner way is outsidestatic intMODIFIED_INCOMPLETEIncomplete multipolygon was modifiedstatic intNO_STYLENo area style for multipolygonstatic intNON_CLOSED_WAYMultipolygon is not closedprivate static java.lang.StringOUTERstatic intOUTER_STYLEArea style on outer waystatic intOUTER_STYLE_MISMATCHStyle for outer way mismatches / With the currently used mappaint style(s) the style for outer way mismatches the area styleprivate booleanrepeatCheckmight be set when creating a relation and touching rings were found.static intREPEATED_MEMBER_DIFF_ROLEMultipolygon member repeated (same primitive, different role)static intREPEATED_MEMBER_SAME_ROLEMultipolygon member repeated (same primitive, same rolestatic intRINGS_SHARE_NODESMultipolygon rings share nodesstatic intWRONG_MEMBER_ROLENo useful role for multipolygon memberstatic intWRONG_MEMBER_TYPENon-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 voidaddRepeatedMemberError(Relation r, java.util.List<OsmPrimitive> repeatedMembers, int errorCode, java.lang.String msg)private voidcheckGeometryAndRoles(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 booleancheckIfNodeIsInsidePolygon(Node n, Multipolygon.PolyData p)Check if a node is inside the polygon according to the insideness rules of Shape.private booleancheckMembersAndRoles(Relation r, java.util.List<TestError> tmpErrors)Check for:WRONG_MEMBER_ROLE: No useful role for multipolygon memberWRONG_MEMBER_TYPE: Non-Way in multipolygonprivate voidcheckOrSetRoles(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.ExtPolygonIntersectioncheckOverlapAtSharedNodes(java.util.Set<Node> shared, Multipolygon.PolyData pd1, Multipolygon.PolyData pd2)private voidcheckPolygonForSelfIntersection(Relation r, Multipolygon.PolyData pd)Check if a polygon ring is self-intersecting when the ring was build from multiple ways.private voidcheckPolygonsForSharedNodes(Relation r, Multipolygon.PolyData pd1, Multipolygon.PolyData pd2, java.util.Set<Node> allSharedNodes)private static booleancheckProblemMap(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 booleancheckRepeatedWayMembers(Relation r)Check for:REPEATED_MEMBER_DIFF_ROLE: Multipolygon member repeated with different roleREPEATED_MEMBER_SAME_ROLE: Multipolygon member repeated with same roleprivate voidcheckStyleConsistency(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)SeeCrossingWaysprivate 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 voidfindIntersectingWaysIncomplete(Relation r)Determine multipolygon ways which are intersecting (crossing without a common node) or sharing one or more way segments.private static voidfindIntersectionNodes(Relation r, java.util.Set<Node> sharedNodes, java.util.Set<Way> intersectionWays)Detect intersections of multipolygon ways at nodes.CommandfixError(TestError testError)Fixes the error with the appropriate commandprivate static booleanhasIntersectionWay(Multipolygon.PolyData pd, java.util.Set<Way> intersectionWays)Simple check if given ring contains way that is known to intersect.booleanisFixable(TestError testError)Returns true if the given error can be fixed automaticallyRelationmakeFromWays(java.util.Collection<Way> ways)Create a multipolygon relation from the given ways and test it.voidvisit(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:OsmPrimitiveVisitorVisiting call for relations.- Specified by:
visitin interfaceOsmPrimitiveVisitor- Overrides:
visitin 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:TestFixes the error with the appropriate command
-
isFixable
public boolean isFixable(TestError testError)
Description copied from class:TestReturns 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
Multipolygoninstance and the relation. - Since:
- 15160
-
-