Search in sources :

Example 1 with Node

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

use of org.openstreetmap.atlas.geography.atlas.items.Node 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)

Aggregations

Node (org.openstreetmap.atlas.geography.atlas.items.Node)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Strings (org.apache.directory.api.util.Strings)1 TypePredicates (org.openstreetmap.atlas.checks.atlas.predicates.TypePredicates)1 BaseCheck (org.openstreetmap.atlas.checks.base.BaseCheck)1 CheckFlag (org.openstreetmap.atlas.checks.flag.CheckFlag)1 Heading (org.openstreetmap.atlas.geography.Heading)1 Location (org.openstreetmap.atlas.geography.Location)1 AtlasObject (org.openstreetmap.atlas.geography.atlas.items.AtlasObject)1 Edge (org.openstreetmap.atlas.geography.atlas.items.Edge)1 DestinationTag (org.openstreetmap.atlas.tags.DestinationTag)1 HighwayTag (org.openstreetmap.atlas.tags.HighwayTag)1 Validators (org.openstreetmap.atlas.tags.annotations.validation.Validators)1 TaggableFilter (org.openstreetmap.atlas.tags.filters.TaggableFilter)1 Configuration (org.openstreetmap.atlas.utilities.configuration.Configuration)1 Angle (org.openstreetmap.atlas.utilities.scalars.Angle)1 Distance (org.openstreetmap.atlas.utilities.scalars.Distance)1