Search in sources :

Example 1 with HighwayTag

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()));
}
Also used : JsonElement(com.google.gson.JsonElement) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag)

Example 2 with HighwayTag

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;
}
Also used : Heading(org.openstreetmap.atlas.geography.Heading) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge)

Example 3 with HighwayTag

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();
    }
}
Also used : Arrays(java.util.Arrays) Set(java.util.Set) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) List(java.util.List) BaseCheck(org.openstreetmap.atlas.checks.base.BaseCheck) JunctionTag(org.openstreetmap.atlas.tags.JunctionTag) Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) AtlasObject(org.openstreetmap.atlas.geography.atlas.items.AtlasObject) Optional(java.util.Optional) Queue(java.util.Queue) LinkedList(java.util.LinkedList) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge)

Example 4 with HighwayTag

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();
}
Also used : Arrays(java.util.Arrays) TaggableFilter(org.openstreetmap.atlas.tags.filters.TaggableFilter) Strings(org.apache.directory.api.util.Strings) Set(java.util.Set) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) Heading(org.openstreetmap.atlas.geography.Heading) Validators(org.openstreetmap.atlas.tags.annotations.validation.Validators) TypePredicates(org.openstreetmap.atlas.checks.atlas.predicates.TypePredicates) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) List(java.util.List) BaseCheck(org.openstreetmap.atlas.checks.base.BaseCheck) Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) AtlasObject(org.openstreetmap.atlas.geography.atlas.items.AtlasObject) DestinationTag(org.openstreetmap.atlas.tags.DestinationTag) Angle(org.openstreetmap.atlas.utilities.scalars.Angle) Node(org.openstreetmap.atlas.geography.atlas.items.Node) Optional(java.util.Optional) Distance(org.openstreetmap.atlas.utilities.scalars.Distance) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) Node(org.openstreetmap.atlas.geography.atlas.items.Node) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge)

Aggregations

HighwayTag (org.openstreetmap.atlas.tags.HighwayTag)4 Edge (org.openstreetmap.atlas.geography.atlas.items.Edge)3 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 BaseCheck (org.openstreetmap.atlas.checks.base.BaseCheck)2 CheckFlag (org.openstreetmap.atlas.checks.flag.CheckFlag)2 Heading (org.openstreetmap.atlas.geography.Heading)2 AtlasObject (org.openstreetmap.atlas.geography.atlas.items.AtlasObject)2 Configuration (org.openstreetmap.atlas.utilities.configuration.Configuration)2 JsonElement (com.google.gson.JsonElement)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Queue (java.util.Queue)1 Collectors (java.util.stream.Collectors)1 Strings (org.apache.directory.api.util.Strings)1 TypePredicates (org.openstreetmap.atlas.checks.atlas.predicates.TypePredicates)1 Node (org.openstreetmap.atlas.geography.atlas.items.Node)1 DestinationTag (org.openstreetmap.atlas.tags.DestinationTag)1