Search in sources :

Example 11 with Edge

use of org.openstreetmap.atlas.geography.atlas.items.Edge in project atlas-checks by osmlab.

the class BuildingRoadIntersectionCheck method flag.

@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
    final Area building = (Area) object;
    final Iterable<Edge> intersectingEdges = Iterables.filter(building.getAtlas().edgesIntersecting(building.bounds(), intersectsCoreWayInvalidly(building)), ignoreTags());
    final CheckFlag flag = new CheckFlag(getTaskIdentifier(building));
    flag.addObject(building);
    this.handleIntersections(intersectingEdges, flag, building);
    if (flag.getPolyLines().size() > 1) {
        return Optional.of(flag);
    }
    return Optional.empty();
}
Also used : Area(org.openstreetmap.atlas.geography.atlas.items.Area) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge)

Example 12 with Edge

use of org.openstreetmap.atlas.geography.atlas.items.Edge in project atlas-checks by osmlab.

the class BuildingRoadIntersectionCheck method handleIntersections.

/**
 * Loops through all intersecting {@link Edge}s, and keeps track of reverse and already seen
 * intersections
 *
 * @param intersectingEdges
 *            all intersecting {@link Edge}s for given building
 * @param flag
 *            the {@link CheckFlag} we're updating
 * @param building
 *            the building being processed
 */
private void handleIntersections(final Iterable<Edge> intersectingEdges, final CheckFlag flag, final Area building) {
    final Set<Edge> knownIntersections = new HashSet<>();
    for (final Edge edge : intersectingEdges) {
        if (!knownIntersections.contains(edge)) {
            flag.addObject(edge, this.getLocalizedInstruction(0, building.getOsmIdentifier(), edge.getOsmIdentifier()));
            knownIntersections.add(edge);
            if (edge.hasReverseEdge()) {
                knownIntersections.add(edge.reversed().get());
            }
        }
    }
}
Also used : Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) HashSet(java.util.HashSet)

Example 13 with Edge

use of org.openstreetmap.atlas.geography.atlas.items.Edge in project atlas-checks by osmlab.

the class EdgeCrossingEdgeCheck method flag.

@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
    // Prepare the edge being tested for checks
    final Edge edge = (Edge) object;
    final PolyLine edgeAsPolyLine = edge.asPolyLine();
    final Rectangle edgeBounds = edge.bounds();
    final Optional<Long> edgeLayer = LayerTag.getTaggedOrImpliedValue(object, 0L);
    // Retrieve crossing edges
    final Atlas atlas = object.getAtlas();
    final Iterable<Edge> crossingEdges = atlas.edgesIntersecting(edgeBounds, // filter out the same edge, non-valid crossing edges and already flagged ones
    crossingEdge -> edge.getIdentifier() != crossingEdge.getIdentifier() && isValidCrossingEdge(crossingEdge) && !this.isFlagged(generateAtlasObjectPairIdentifier(edge, crossingEdge)));
    List<Edge> invalidEdges = null;
    // each edge will be marked explicitly.
    for (final Edge crossingEdge : crossingEdges) {
        final PolyLine crossingEdgeAsPolyLine = crossingEdge.asPolyLine();
        final Optional<Long> crossingEdgeLayer = LayerTag.getTaggedOrImpliedValue(crossingEdge, 0L);
        final Set<Location> intersections = edgeAsPolyLine.intersections(crossingEdgeAsPolyLine);
        // Check whether crossing edge can actually cross
        for (final Location intersection : intersections) {
            // Add this set to flagged pairs to skip it next time
            this.markAsFlagged(generateAtlasObjectPairIdentifier(edge, crossingEdge));
            // Check if crossing is valid or not
            if (canCross(edgeAsPolyLine, edgeLayer, crossingEdgeAsPolyLine, crossingEdgeLayer, intersection)) {
                continue;
            }
            if (invalidEdges == null) {
                // Normally we expect 1 or 2 edges in the list
                invalidEdges = new LinkedList<>();
            }
            invalidEdges.add(crossingEdge);
        }
    }
    if (invalidEdges != null) {
        final CheckFlag newFlag = new CheckFlag(getTaskIdentifier(object));
        newFlag.addObject(object);
        newFlag.addInstruction(this.getLocalizedInstruction(0, object.getOsmIdentifier()));
        invalidEdges.forEach(invalidEdge -> {
            newFlag.addObject(invalidEdge);
            newFlag.addInstruction(this.getLocalizedInstruction(1, invalidEdge.getOsmIdentifier()));
        });
        return Optional.of(newFlag);
    }
    return Optional.empty();
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) Rectangle(org.openstreetmap.atlas.geography.Rectangle) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) PolyLine(org.openstreetmap.atlas.geography.PolyLine) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) Location(org.openstreetmap.atlas.geography.Location)

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