Skip to content

Commit

Permalink
Validate connections to multi-polygons with appropriate tags
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Jan 23, 2024
1 parent 2839be6 commit 71bc2b4
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 deletions src/main/java/de/blau/android/validation/BaseValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,30 +373,54 @@ private void validateEndNodes(@NonNull Way w, @NonNull String key) {
private void checkNearbyWays(@NonNull String tagKey, @NonNull Way w, @NonNull Logic logic, int layer, @NonNull Node n) throws OsmException {
final int lat = n.getLat();
final int lon = n.getLon();
if (App.getDelegator().isInDownload(lon, lat)) { // only check for nodes in download
BoundingBox box = GeoMath.createBoundingBoxForCoordinates(lat / 1E7D, lon / 1E7D, tolerance);
List<Way> nearbyWays = App.getDelegator().getCurrentStorage().getWays(box);
List<Way> connectedWays = new ArrayList<>();
BoundingBox bb = w.getBounds();
for (Way maybeConnected : new ArrayList<>(nearbyWays)) {
if (!maybeConnected.hasTagKey(tagKey) || maybeConnected.equals(w)) {
nearbyWays.remove(maybeConnected);
continue;
}
if (bb.intersects(maybeConnected.getBounds()) && maybeConnected.hasCommonNode(w)) {
connectedWays.add(maybeConnected);
nearbyWays.remove(maybeConnected);
if (!App.getDelegator().isInDownload(lon, lat)) { // only check for nodes in download
return;
}
BoundingBox box = GeoMath.createBoundingBoxForCoordinates(lat / 1E7D, lon / 1E7D, tolerance);
List<Way> nearbyWays = App.getDelegator().getCurrentStorage().getWays(box);
List<Way> connectedWays = new ArrayList<>();
BoundingBox bb = w.getBounds();
for (Way maybeConnected : new ArrayList<>(nearbyWays)) {
if (maybeConnected.equals(w) || !hasTagKey(tagKey, maybeConnected)) {
nearbyWays.remove(maybeConnected);
continue;
}
if (bb.intersects(maybeConnected.getBounds()) && maybeConnected.hasCommonNode(w)) {
connectedWays.add(maybeConnected);
nearbyWays.remove(maybeConnected);
}
}
for (Way nearbyWay : nearbyWays) {
if (!hasConnection(nearbyWay, connectedWays) && layer == getLayer(nearbyWay)) {
connectedValidation(logic, tolerance, nearbyWay, n);
if ((n.getCachedProblems() & Validator.UNCONNECTED_END_NODE) != 0) {
break;
}
}
for (Way nearbyWay : nearbyWays) {
if (!hasConnection(nearbyWay, connectedWays) && layer == getLayer(nearbyWay)) {
connectedValidation(logic, tolerance, nearbyWay, n);
if ((n.getCachedProblems() & Validator.UNCONNECTED_END_NODE) != 0) {
break;
}
}
}

/**
* Check if the way has a specific key or has a parent MP with that key
*
* @param key the key we are checking for
* @param way the way to check
* @return true if the way has a specific key or has a parent MP with that key
*/
private boolean hasTagKey(@NonNull String key, @NonNull Way way) {
if (way.hasTagKey(key)) {
return true;
}
// check for MPs
List<Relation> parents = way.getParentRelations();
if (parents != null) {
for (Relation parent : parents) {
if (parent.hasTag(Tags.KEY_TYPE, Tags.VALUE_MULTIPOLYGON) && parent.hasTagKey(key)) {
return true;
}
}
}
return false;
}

/**
Expand Down Expand Up @@ -657,7 +681,7 @@ public int validate(@NonNull Way way) {
}
if (!way.isClosed()) {
for (String key : END_NODE_VALIDATION_KEYS) {
if (way.hasTagKey(key)) {
if (hasTagKey(key, way)) {
validateEndNodes(way, key);
break;
}
Expand Down

0 comments on commit 71bc2b4

Please sign in to comment.