use of org.openstreetmap.atlas.tags.HighwayTag in project atlas-checks by osmlab.
the class CheckFlagEvent method featureDecorator.
/**
* Extracts a decorator based on the collective features properties. Currently the only
* decoration is the highest class highway tag withing all of the feature properties for flags
* involving Edges.
*/
private static Optional<String> featureDecorator(final JsonArray featureProperties) {
HighwayTag highestHighwayTag = null;
for (final JsonElement featureProperty : featureProperties) {
final HighwayTag baslineHighwayTag = highestHighwayTag == null ? HighwayTag.NO : highestHighwayTag;
highestHighwayTag = Optional.ofNullable(((JsonObject) featureProperty).getAsJsonPrimitive(HighwayTag.KEY)).map(JsonPrimitive::getAsString).map(String::toUpperCase).map(HighwayTag::valueOf).filter(baslineHighwayTag::isLessImportantThan).orElse(highestHighwayTag);
}
return Optional.ofNullable(highestHighwayTag).map(tag -> String.format("%s=%s", HighwayTag.KEY, tag.getTagValue()));
}
use of org.openstreetmap.atlas.tags.HighwayTag in project atlas-checks by osmlab.
the class SignPostCheck method findFirstRampEdge.
/**
* Given a final {@link Edge}, hops back and finds the first edge that was forming the ramp.
*
* @param finalEdge
* {@link Edge} that is the last/final piece of the ramp
* @return {@link Edge} that possibly is the first {@link Edge} forming the ramp
*/
private Edge findFirstRampEdge(final Edge finalEdge) {
int count = 0;
// Go back and collect edges
Edge nextEdge = finalEdge;
while (count < MAX_EDGE_COUNT_FOR_RAMP) {
count++;
// Break if edge has no heading
final Optional<Heading> initialHeading = nextEdge.asPolyLine().initialHeading();
if (!initialHeading.isPresent()) {
break;
}
// Collect in edges and make sure there is not more than one
final Set<Edge> inEdges = nextEdge.inEdges();
if (inEdges.isEmpty() || inEdges.size() > 1) {
break;
}
// Find the edge that precedes nextEdge
final HighwayTag highwayTag = nextEdge.highwayTag();
final Edge precedingEdge = inEdges.iterator().next();
// Ignore if edge has a different classification
if (!highwayTag.isIdenticalClassification(precedingEdge.highwayTag())) {
break;
}
// Break if given edge has no heading
final Optional<Heading> finalHeading = precedingEdge.asPolyLine().finalHeading();
if (!finalHeading.isPresent() || initialHeading.get().asPositiveAngle().difference(finalHeading.get().asPositiveAngle()).isGreaterThan(this.rampAngleDifference)) {
break;
}
nextEdge = precedingEdge;
}
return nextEdge;
}
use of org.openstreetmap.atlas.tags.HighwayTag 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.tags.HighwayTag 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();
}
Aggregations