Search in sources :

Example 6 with Location

use of org.openstreetmap.atlas.geography.Location 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 7 with Location

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

the class BuildingRoadIntersectionCheck method isValidIntersection.

/**
 * An edge intersecting with a building that doesn't have the proper tags is only valid iff it
 * intersects at one single node and that node is shared with an edge that has the proper tags
 * and it is not enclosed in the building
 *
 * @param building
 *            the building being processed
 * @param edge
 *            the edge being examined
 * @return true if the intersection is valid, false otherwise
 */
private static boolean isValidIntersection(final Area building, final Edge edge) {
    final Node edgeStart = edge.start();
    final Node edgeEnd = edge.end();
    final Set<Location> intersections = building.asPolygon().intersections(edge.asPolyLine());
    if (intersections.size() == 1 && !building.asPolygon().fullyGeometricallyEncloses(edge.asPolyLine())) {
        if (intersections.contains(edgeStart.getLocation()) && edge.inEdges().stream().anyMatch(ignoreTags().negate())) {
            return true;
        }
        if (intersections.contains(edgeEnd.getLocation()) && edge.outEdges().stream().anyMatch(ignoreTags().negate())) {
            return true;
        }
    }
    return false;
}
Also used : Node(org.openstreetmap.atlas.geography.atlas.items.Node) Location(org.openstreetmap.atlas.geography.Location)

Example 8 with Location

use of org.openstreetmap.atlas.geography.Location 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

Location (org.openstreetmap.atlas.geography.Location)8 Test (org.junit.Test)3 CheckFlag (org.openstreetmap.atlas.checks.flag.CheckFlag)3 PolyLine (org.openstreetmap.atlas.geography.PolyLine)3 Edge (org.openstreetmap.atlas.geography.atlas.items.Edge)3 FlaggedObject (org.openstreetmap.atlas.checks.flag.FlaggedObject)2 FlaggedPoint (org.openstreetmap.atlas.checks.flag.FlaggedPoint)2 Rectangle (org.openstreetmap.atlas.geography.Rectangle)2 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)2 JsonArray (com.google.gson.JsonArray)1 HashSet (java.util.HashSet)1 Task (org.openstreetmap.atlas.checks.maproulette.data.Task)1 CoreException (org.openstreetmap.atlas.exception.CoreException)1 Polygon (org.openstreetmap.atlas.geography.Polygon)1 Segment (org.openstreetmap.atlas.geography.Segment)1 Area (org.openstreetmap.atlas.geography.atlas.items.Area)1 Line (org.openstreetmap.atlas.geography.atlas.items.Line)1 Node (org.openstreetmap.atlas.geography.atlas.items.Node)1 PackedAtlasBuilder (org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasBuilder)1 GeoJsonBuilder (org.openstreetmap.atlas.geography.geojson.GeoJsonBuilder)1