Search in sources :

Example 1 with AtlasObject

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)));
}
Also used : Arrays(java.util.Arrays) Set(java.util.Set) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) RouteTag(org.openstreetmap.atlas.tags.RouteTag) Collectors(java.util.stream.Collectors) Validators(org.openstreetmap.atlas.tags.annotations.validation.Validators) HashSet(java.util.HashSet) 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) TagPredicates(org.openstreetmap.atlas.checks.atlas.predicates.TagPredicates) SyntheticBoundaryNodeTag(org.openstreetmap.atlas.tags.SyntheticBoundaryNodeTag) Optional(java.util.Optional) AerowayTag(org.openstreetmap.atlas.tags.AerowayTag) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) AtlasObject(org.openstreetmap.atlas.geography.atlas.items.AtlasObject) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet)

Example 2 with AtlasObject

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();
    }
}
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 3 with AtlasObject

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();
}
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)

Example 4 with AtlasObject

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;
}
Also used : AtlasObject(org.openstreetmap.atlas.geography.atlas.items.AtlasObject) Relation(org.openstreetmap.atlas.geography.atlas.items.Relation) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag)

Aggregations

CheckFlag (org.openstreetmap.atlas.checks.flag.CheckFlag)4 AtlasObject (org.openstreetmap.atlas.geography.atlas.items.AtlasObject)4 Arrays (java.util.Arrays)3 List (java.util.List)3 Optional (java.util.Optional)3 Set (java.util.Set)3 BaseCheck (org.openstreetmap.atlas.checks.base.BaseCheck)3 Edge (org.openstreetmap.atlas.geography.atlas.items.Edge)3 HighwayTag (org.openstreetmap.atlas.tags.HighwayTag)3 Configuration (org.openstreetmap.atlas.utilities.configuration.Configuration)3 HashSet (java.util.HashSet)2 Queue (java.util.Queue)2 Collectors (java.util.stream.Collectors)2 Validators (org.openstreetmap.atlas.tags.annotations.validation.Validators)2 ArrayDeque (java.util.ArrayDeque)1 LinkedList (java.util.LinkedList)1 Strings (org.apache.directory.api.util.Strings)1 TagPredicates (org.openstreetmap.atlas.checks.atlas.predicates.TagPredicates)1 TypePredicates (org.openstreetmap.atlas.checks.atlas.predicates.TypePredicates)1 Heading (org.openstreetmap.atlas.geography.Heading)1