use of org.openstreetmap.atlas.geography.atlas.items.Node in project atlas-checks by osmlab.
the class SignPostCheck method flag.
/**
* This is the actual function that will check to see whether the object needs to be flagged.
*
* @param object
* the atlas object supplied by the Atlas-Checks framework for evaluation
* @return an optional {@link CheckFlag} object that
*/
@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
final Edge edge = (Edge) object;
final HighwayTag highwayTag = edge.highwayTag();
final CheckFlag flag = new CheckFlag(this.getTaskIdentifier(object));
// First find off ramps
edge.end().outEdges().stream().filter(connectedEdge -> isPossiblyRamp(edge, highwayTag, connectedEdge)).forEach(outEdge -> {
// Check to see if start node is missing junction tag
final Node start = outEdge.start();
if (!Validators.isOfType(start, HighwayTag.class, HighwayTag.MOTORWAY_JUNCTION)) {
flag.addInstruction(this.getLocalizedInstruction(0, start.getOsmIdentifier(), String.format("%s=%s", HighwayTag.KEY, HighwayTag.MOTORWAY_JUNCTION.getTagValue())));
flag.addObject(start);
}
// Check if edge is missing destination tag
if (!outEdge.getTag(DestinationTag.KEY).isPresent()) {
flag.addInstruction(this.getLocalizedInstruction(1, outEdge.getOsmIdentifier(), OFF_RAMP_KEY, DestinationTag.KEY));
flag.addObject(outEdge);
}
});
// Then repeat the work for on ramps
edge.start().inEdges().stream().filter(connectedEdge -> isPossiblyRamp(edge, highwayTag, connectedEdge)).forEach(inEdge -> {
// Find the source of in-ramp
final Edge rampEdge = findFirstRampEdge(inEdge);
// Check to see if start node is missing junction tag
final Node start = rampEdge.start();
if (!Validators.isOfType(start, HighwayTag.class, HighwayTag.MOTORWAY_JUNCTION)) {
flag.addInstruction(this.getLocalizedInstruction(0, start.getOsmIdentifier(), String.format("%s=%s", HighwayTag.KEY, HighwayTag.MOTORWAY_JUNCTION.getTagValue())));
flag.addObject(start);
}
// Check if edge is missing destination tag
if (!rampEdge.getTag(DestinationTag.KEY).isPresent()) {
flag.addInstruction(this.getLocalizedInstruction(1, rampEdge.getOsmIdentifier(), ON_RAMP_KEY, DestinationTag.KEY));
flag.addObject(rampEdge);
}
});
// Return the flag if it has any flagged objects in it
if (!flag.getFlaggedObjects().isEmpty()) {
return Optional.of(flag);
}
return Optional.empty();
}
use of org.openstreetmap.atlas.geography.atlas.items.Node in project atlas-checks by osmlab.
the class BuildingRoadIntersectionCheck method isValidIntersection.
/**
* An edge intersecting with a building that doesn't have the proper tags is only valid iff it
* intersects at one single node and that node is shared with an edge that has the proper tags
* and it is not enclosed in the building
*
* @param building
* the building being processed
* @param edge
* the edge being examined
* @return true if the intersection is valid, false otherwise
*/
private static boolean isValidIntersection(final Area building, final Edge edge) {
final Node edgeStart = edge.start();
final Node edgeEnd = edge.end();
final Set<Location> intersections = building.asPolygon().intersections(edge.asPolyLine());
if (intersections.size() == 1 && !building.asPolygon().fullyGeometricallyEncloses(edge.asPolyLine())) {
if (intersections.contains(edgeStart.getLocation()) && edge.inEdges().stream().anyMatch(ignoreTags().negate())) {
return true;
}
if (intersections.contains(edgeEnd.getLocation()) && edge.outEdges().stream().anyMatch(ignoreTags().negate())) {
return true;
}
}
return false;
}
Aggregations