Search in sources :

Example 6 with Edge

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

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

Example 8 with Edge

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

Example 9 with Edge

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();
}
Also used : Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) Tuple(org.openstreetmap.atlas.utilities.tuples.Tuple) Location(org.openstreetmap.atlas.geography.Location)

Example 10 with Edge

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;
            }
        }
    }
}
Also used : Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) HashSet(java.util.HashSet)

Aggregations

Edge (org.openstreetmap.atlas.geography.atlas.items.Edge)13 CheckFlag (org.openstreetmap.atlas.checks.flag.CheckFlag)6 HashSet (java.util.HashSet)5 HighwayTag (org.openstreetmap.atlas.tags.HighwayTag)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 Location (org.openstreetmap.atlas.geography.Location)3 AtlasObject (org.openstreetmap.atlas.geography.atlas.items.AtlasObject)3 Configuration (org.openstreetmap.atlas.utilities.configuration.Configuration)3 LinkedList (java.util.LinkedList)2 Queue (java.util.Queue)2 Collectors (java.util.stream.Collectors)2 Heading (org.openstreetmap.atlas.geography.Heading)2 PolyLine (org.openstreetmap.atlas.geography.PolyLine)2 Area (org.openstreetmap.atlas.geography.atlas.items.Area)2 Validators (org.openstreetmap.atlas.tags.annotations.validation.Validators)2 ArrayDeque (java.util.ArrayDeque)1