hasOuterWay = true;
break;
}
}
if (!hasOuterWay) {
addError(r, new TestError(this, Severity.WARNING, tr("No outer way for multipolygon"), MISSING_OUTER_WAY, r));
}
if (r.hasIncompleteMembers()) {
return; // Rest of checks is only for complete multipolygons
}
// Create new multipolygon using the logics from CreateMultipolygonAction and see if roles match.
final Pair<Relation, Relation> newMP = CreateMultipolygonAction.createMultipolygonRelation(r.getMemberPrimitives(Way.class), false);
if (newMP != null) {
for (RelationMember member : r.getMembers()) {
final Collection<RelationMember> memberInNewMP = newMP.b.getMembersFor(Collections.singleton(member.getMember()));
if (memberInNewMP != null && !memberInNewMP.isEmpty()) {
final String roleInNewMP = memberInNewMP.iterator().next().getRole();
if (!member.getRole().equals(roleInNewMP)) {
addError(r, new TestError(this, Severity.WARNING, RelationChecker.ROLE_VERIF_PROBLEM_MSG,
tr("Role for ''{0}'' should be ''{1}''",
member.getMember().getDisplayName(DefaultNameFormatter.getInstance()), roleInNewMP),
MessageFormat.format("Role for ''{0}'' should be ''{1}''",
member.getMember().getDisplayName(DefaultNameFormatter.getInstance()), roleInNewMP),
WRONG_MEMBER_ROLE, Collections.singleton(r), Collections.singleton(member.getMember())));
}
}
}
}
List<List<Node>> innerWays = joinWays(polygon.getInnerWays()); // Side effect - sets nonClosedWays
List<List<Node>> outerWays = joinWays(polygon.getOuterWays());
if (styles != null) {
AreaElemStyle area = ElemStyles.getAreaElemStyle(r, false);
boolean areaStyle = area != null;
// If area style was not found for relation then use style of ways
if (area == null) {
for (Way w : polygon.getOuterWays()) {
area = ElemStyles.getAreaElemStyle(w, true);
if (area != null) {
break;
}
}
if (!"boundary".equals(r.get("type"))) {
if (area == null) {
addError(r, new TestError(this, Severity.OTHER, tr("No style for multipolygon"), NO_STYLE, r));
} else {
addError(r, new TestError(this, Severity.OTHER, tr("No style in multipolygon relation"),
NO_STYLE_POLYGON, r));
}
}
}
if (area != null) {
for (Way wInner : polygon.getInnerWays()) {
AreaElemStyle areaInner = ElemStyles.getAreaElemStyle(wInner, false);
if (areaInner != null && area.equals(areaInner)) {
List<OsmPrimitive> l = new ArrayList<>();
l.add(r);
l.add(wInner);
addError(r, new TestError(this, Severity.WARNING, tr("Style for inner way equals multipolygon"),
INNER_STYLE_MISMATCH, l, Collections.singletonList(wInner)));
}
}
if(!areaStyle) {
for (Way wOuter : polygon.getOuterWays()) {
AreaElemStyle areaOuter = ElemStyles.getAreaElemStyle(wOuter, false);
if (areaOuter != null && !area.equals(areaOuter)) {
List<OsmPrimitive> l = new ArrayList<>();
l.add(r);
l.add(wOuter);
addError(r, new TestError(this, Severity.WARNING, tr("Style for outer way mismatches"),
OUTER_STYLE_MISMATCH, l, Collections.singletonList(wOuter)));
}
}
}
}
}
List<Node> openNodes = new LinkedList<>();
for (List<Node> w : nonClosedWays) {
if (w.size()<1) continue;
openNodes.add(w.get(0));
openNodes.add(w.get(w.size() - 1));
}
if (!openNodes.isEmpty()) {
List<OsmPrimitive> primitives = new LinkedList<>();
primitives.add(r);
primitives.addAll(openNodes);
Arrays.asList(openNodes, r);
addError(r, new TestError(this, Severity.WARNING, tr("Multipolygon is not closed"), NON_CLOSED_WAY,
primitives, openNodes));
}
// For painting is used Polygon class which works with ints only. For validation we need more precision
List<GeneralPath> outerPolygons = createPolygons(outerWays);
for (List<Node> pdInner : innerWays) {
boolean outside = true;
boolean crossing = false;
List<Node> outerWay = null;
for (int i=0; i<outerWays.size(); i++) {
GeneralPath outer = outerPolygons.get(i);
Intersection intersection = getPolygonIntersection(outer, pdInner);
outside = outside & intersection == Intersection.OUTSIDE;
if (intersection == Intersection.CROSSING) {
crossing = true;
outerWay = outerWays.get(i);
}
}
if (outside || crossing) {
List<List<Node>> highlights = new ArrayList<>();
highlights.add(pdInner);
if (outside) {
addError(r, new TestError(this, Severity.WARNING, tr("Multipolygon inner way is outside"), INNER_WAY_OUTSIDE, Collections.singletonList(r), highlights));
} else if (crossing) {
highlights.add(outerWay);
addError(r, new TestError(this, Severity.WARNING, tr("Intersection between multipolygon ways"), CROSSING_WAYS, Collections.singletonList(r), highlights));
}
}
}
}
}