use of org.openstreetmap.atlas.geography.atlas.items.Edge 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.Edge in project atlas-checks by osmlab.
the class SnakeRoadCheck method walkNetwork.
/**
* Recursively walks the network and uses {@link SnakeRoadNetworkWalk} to keep track of results
* at each step
*
* @param current
* the {@link Edge} we're currently traversing from
* @param walk
* the {@link SnakeRoadNetworkWalk} that contains the snake road status to this point
* @return {@link SnakeRoadNetworkWalk} with all Snake Road information
*/
private SnakeRoadNetworkWalk walkNetwork(final Edge current, final SnakeRoadNetworkWalk walk) {
while (!walk.getDirectConnections().isEmpty()) {
// Grab the next available edge
final Edge connection = walk.getDirectConnections().poll();
// Process it
walk.visitEdge(current, connection);
// Add its neighbors to the next layer
walk.populateOneLayerRemovedConnections(walk.getConnectedMasterEdgeOfTheSameWay(connection));
// If we've processed all directly connected edges, check the next layer of connections
if (walk.getDirectConnections().isEmpty()) {
if (walk.getOneLayerRemovedConnections().isEmpty()) {
// We've finished processing all direct connections and there are no connections
// in the next layer either, filter false positives and return
walk.filterFalsePositives();
return walk;
} else {
// We're done processing this layer, populate the direct connections using the
// next layer's edges and reset next layer's edges
walk.addDirectConnections(walk.getOneLayerRemovedConnections());
walk.clearOneLayerRemovedConnections();
}
}
}
return walk;
}
use of org.openstreetmap.atlas.geography.atlas.items.Edge in project atlas-checks by osmlab.
the class SnakeRoadCheck method flag.
@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
final Edge edge = (Edge) object;
// Mark edge (and all other edges that we may walk) as visited, irregardless
// of whether it's a snake road or not
this.markAsFlagged(object.getOsmIdentifier());
// Check the base case - edge must have connected edges
if (!edge.connectedEdges().isEmpty()) {
// Instantiate the network walk with the starting edge
SnakeRoadNetworkWalk walk = initializeNetworkWalk(edge);
// Walk the road
walk = walkNetwork(edge, walk);
// If we've found a snake road, create a flag
if (networkWalkQualifiesAsSnakeRoad(walk)) {
return Optional.of(createFlag(walk.getVisitedEdges(), this.getLocalizedInstruction(0, object.getOsmIdentifier())));
}
}
return Optional.empty();
}
use of org.openstreetmap.atlas.geography.atlas.items.Edge in project atlas-checks by osmlab.
the class SharpAngleCheck method flag.
@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
final Edge edge = (Edge) object;
// Ignore all types less significant than Tertiary
if (edge.highwayTag().isLessImportantThan(HighwayTag.TERTIARY)) {
return Optional.empty();
}
final List<Tuple<Angle, Location>> offendingAngles = edge.asPolyLine().anglesGreaterThanOrEqualTo(this.threshold);
if (!offendingAngles.isEmpty() && !hasBeenFlagged(edge)) {
flagEdge(edge);
final String checkMessage;
if (offendingAngles.size() == 1) {
// Single offending angle - output the location.
checkMessage = this.getLocalizedInstruction(0, object.getOsmIdentifier(), offendingAngles.get(0).getSecond());
} else {
// Multiple such angles - output the total count.
checkMessage = this.getLocalizedInstruction(1, object.getOsmIdentifier(), offendingAngles.size());
}
final List<Location> offendingLocations = buildLocationList(offendingAngles);
return Optional.of(createFlag(object, checkMessage, offendingLocations));
}
return Optional.empty();
}
use of org.openstreetmap.atlas.geography.atlas.items.Edge in project atlas-checks by osmlab.
the class SnakeRoadNetworkWalk method filterFalsePositives.
/**
* We filter false positives for two cases. 1) If the network walk has yielded a snake road with
* a name, we check all of the connected roads to see if that name is shared across any of them.
* If it is, highly likely that the snake road is a false positive, and we remove the snake road
* designation. An example is when we flag a portion of highway that behaves as a snake road. 2)
* We do the same for ref tags to avoid flagging section of highway that exhibit snake road
* behavior.
*/
protected void filterFalsePositives() {
if (isSnakeRoad() && (hasRoadName() || hasRefTag())) {
// Gather all connected edges for the first and last edge of this road
final Set<Edge> connections = new HashSet<>();
connections.addAll(getMasterEdgesForConnectedEdgesOfDifferentWays((Edge) getVisitedEdges().first()));
connections.addAll(getMasterEdgesForConnectedEdgesOfDifferentWays((Edge) getVisitedEdges().last()));
// Check their connections for connected names and ref tags
for (final Edge connection : connections) {
final Optional<String> connectionName = connection.getTag(NameTag.KEY);
final Optional<String> refTag = connection.getTag(ReferenceTag.KEY);
if (connectionName.equals(getRoadName()) || refTag.equals(getRefTag())) {
setSnakeRoadStatus(false);
break;
}
}
}
}
Aggregations