use of org.openstreetmap.atlas.geography.atlas.items.AtlasObject in project atlas-checks by osmlab.
the class SinkIslandCheck method flag.
@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
// Flag to keep track of whether we found an issue or not
boolean emptyFlag = false;
// The current edge to be explored
Edge candidate = (Edge) object;
// A set of all edges that we have already explored
final Set<AtlasObject> explored = new HashSet<>(this.storeSize, LOAD_FACTOR);
// A set of all edges that we explore that have no outgoing edges
final Set<AtlasObject> terminal = new HashSet<>();
// Current queue of candidates that we can draw from
final Queue<Edge> candidates = new ArrayDeque<>(this.storeSize);
// Start edge always explored
explored.add(candidate);
// Keep looping while we still have a valid candidate to explore
while (candidate != null) {
// process
if (this.isFlagged(candidate.getIdentifier())) {
emptyFlag = true;
break;
}
// Retrieve all the valid outgoing edges to explore
final Set<Edge> outEdges = candidate.outEdges().stream().filter(this::validEdge).collect(Collectors.toSet());
if (outEdges.isEmpty()) {
// Sink edge. Don't mark the edge explored until we know how big the tree is
terminal.add(candidate);
} else {
// Add the current candidate to the set of already explored edges
explored.add(candidate);
// From the list of outgoing edges from the current candidate filter out any edges
// that have already been explored and add all the rest to the queue of possible
// candidates
outEdges.stream().filter(outEdge -> !explored.contains(outEdge)).forEach(candidates::add);
// loop and assume that this is not a SinkIsland
if (candidates.size() + explored.size() > this.treeSize) {
emptyFlag = true;
break;
}
}
// Get the next candidate
candidate = candidates.poll();
}
// flag.
if (!emptyFlag) {
// Include all touched edges
explored.addAll(terminal);
}
// Set every explored edge as flagged for any other processes to know that we have already
// process all those edges
explored.forEach(marked -> this.markAsFlagged(marked.getIdentifier()));
// Create the flag if and only if the empty flag value is not set to false
return emptyFlag ? Optional.empty() : Optional.of(createFlag(explored, this.getLocalizedInstruction(0)));
}
use of org.openstreetmap.atlas.geography.atlas.items.AtlasObject in project atlas-checks by osmlab.
the class RoundaboutValenceCheck 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;
// Get all edges in the roundabout
final Set<Edge> roundaboutEdges = getAllRoundaboutEdges(edge);
final Set<Edge> connectedEdges = roundaboutEdges.stream().flatMap(roundaboutEdge -> roundaboutEdge.connectedEdges().stream()).filter(HighwayTag::isCarNavigableHighway).filter(Edge::isMasterEdge).filter(currentEdge -> !JunctionTag.isRoundabout(currentEdge)).filter(currentEdge -> !roundaboutEdges.contains(currentEdge)).collect(Collectors.toSet());
final int totalRoundaboutValence = connectedEdges.size();
// or greater than or equal to the maximum configured number of connections
if (totalRoundaboutValence < this.minimumValence || totalRoundaboutValence > this.maximumValence) {
this.markAsFlagged(object.getIdentifier());
// If the roundabout valence is 1, this should be labelled as a turning loop instead
if (totalRoundaboutValence == 1) {
return Optional.of(this.createFlag(roundaboutEdges, this.getLocalizedInstruction(1, edge.getOsmIdentifier())));
}
// Otherwise, we want to flag and given information about identifier and valence
return Optional.of(this.createFlag(roundaboutEdges, this.getLocalizedInstruction(0, edge.getOsmIdentifier(), totalRoundaboutValence)));
} else // If the totalRoundaboutValence is not unusual, we don't flag the object
{
return Optional.empty();
}
}
use of org.openstreetmap.atlas.geography.atlas.items.AtlasObject 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.AtlasObject in project atlas-checks by osmlab.
the class InvalidTurnRestrictionCheck method flag.
@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
final Optional<CheckFlag> result;
final Relation relation = (Relation) object;
if (!TurnRestriction.from(relation).isPresent()) {
final Set<AtlasObject> members = relation.members().stream().map(RelationMember::getEntity).collect(Collectors.toSet());
result = Optional.of(createFlag(members, this.getLocalizedInstruction(0, relation.getOsmIdentifier())));
} else {
result = Optional.empty();
}
return result;
}
Aggregations