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