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