use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.
the class IntersectingBuildingsCheckTest method testSeveralDuplicateBuildingsAtlas.
@Test
public void testSeveralDuplicateBuildingsAtlas() {
this.verifier.actual(this.setup.severalDuplicateBuildingsAtlas(), CHECK);
this.verifier.verifyNotEmpty();
this.verifier.verifyExpectedSize(3);
this.verifier.globallyVerify(flags -> {
// First building overlaps with all other buildings
final CheckFlag firstFlag = flags.get(0);
Assert.assertEquals(4, firstFlag.getFlaggedObjects().size());
// Second building overlaps with the third and fourth one (it's overlap with first is
// already flagged)
final CheckFlag secondFlag = flags.get(1);
Assert.assertEquals(3, secondFlag.getFlaggedObjects().size());
// Third building's overlap with fourth building will be flagged with the third flag
final CheckFlag thirdFlag = flags.get(2);
Assert.assertEquals(2, thirdFlag.getFlaggedObjects().size());
});
}
use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.
the class SelfIntersectingPolylineCheck method flag.
@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
final Optional<CheckFlag> response;
final int localizedInstructionIndex;
final PolyLine polyline;
if (object instanceof Edge) {
polyline = ((Edge) object).asPolyLine();
// Send building instructions if building tag exists
localizedInstructionIndex = (TagPredicates.IS_BUILDING.test(object)) ? 2 : 0;
} else if (object instanceof Line) {
polyline = ((Line) object).asPolyLine();
// Send building instructions if building tag exists
localizedInstructionIndex = (TagPredicates.IS_BUILDING.test(object)) ? 2 : 0;
} else if (object instanceof Area) {
polyline = ((Area) object).asPolygon();
// Send duplicate Edge instructions if duplicate Edges exist
localizedInstructionIndex = hasDuplicateSegments(polyline) ? THREE : 1;
} else {
throw new CoreException("Invalid item type {}", object.getClass().toString());
}
// First, find shape point intersections
final Set<Location> selfIntersections = polyline.selfIntersections();
if (selfIntersections.size() > 0) {
final CheckFlag flag = new CheckFlag(Long.toString(object.getIdentifier()));
flag.addObject(object);
flag.addInstruction(this.getLocalizedInstruction(localizedInstructionIndex, object.getOsmIdentifier(), selfIntersections.toString()));
selfIntersections.forEach(flag::addPoint);
response = Optional.of(flag);
} else {
// Next, find intersections occurring at non-shape points using JTS verification
boolean isJtsValid = true;
try {
if (object instanceof Area) {
isJtsValid = GeometryValidator.isValidPolygon((Polygon) polyline);
} else {
isJtsValid = GeometryValidator.isValidPolyLine(polyline);
}
} catch (final IllegalArgumentException e) {
// Invalid geometry found when converting the PolyLine/Polygon.
// This can be a number of cases. For example, a LineString expects exactly 0 or >=2
// points or a Polygon expects 0 or >= 4 points. This isn't self-intersecting
// geometry, but rather inconsistent geometry, according to JTS.
logger.error("Encountered invalid geometry for feature {}", object.getOsmIdentifier(), e);
}
if (!isJtsValid) {
response = Optional.of(createFlag(object, this.getLocalizedInstruction(localizedInstructionIndex)));
} else {
response = Optional.empty();
}
}
return response;
}
use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.
the class IntersectingBuildingsCheck method flag.
@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
final Area building = (Area) object;
// Fetch building's area as polygon and make sure it has at least 3 points
final Polygon buildingPolygon = building.asPolygon();
if (buildingPolygon.size() < MINIMUM_POINT_COUNT_FOR_POLYGON) {
return Optional.empty();
}
// Fetch possibly intersecting buildings
final Iterable<Area> possiblyIntersectingBuildings = object.getAtlas().areasIntersecting(building.bounds(), area -> BuildingTag.isBuilding(area) && building.getIdentifier() != area.getIdentifier() && area.intersects(buildingPolygon));
// Assuming that we'd find intersections/overlaps below, create a flag
final CheckFlag flag = new CheckFlag(this.getTaskIdentifier(object));
flag.addObject(object);
boolean hadIntersection = false;
// Go over possible intersections
for (final Area otherBuilding : possiblyIntersectingBuildings) {
// Fetch other building's area as polygon and make sure it has at least 3 points
final Polygon otherBuildingsPolygon = otherBuilding.asPolygon();
if (otherBuildingsPolygon.size() < MINIMUM_POINT_COUNT_FOR_POLYGON) {
continue;
}
// Create a unique identifier for building tuple to avoid processing same buildings more
// than once
final String uniqueIdentifier = getIdentifierTuple(building, otherBuilding);
if (this.isFlagged(getIdentifierTuple(building, otherBuilding))) {
continue;
}
// Find intersection type
final IntersectionType resultType = this.findIntersectionType(buildingPolygon, otherBuildingsPolygon);
// Flag based on intersection type
if (resultType == IntersectionType.OVERLAP) {
flag.addObject(otherBuilding, this.getLocalizedInstruction(0, object.getOsmIdentifier(), otherBuilding.getOsmIdentifier()));
this.markAsFlagged(uniqueIdentifier);
hadIntersection = true;
} else if (resultType == IntersectionType.INTERSECT) {
flag.addObject(otherBuilding, this.getLocalizedInstruction(1, object.getOsmIdentifier(), otherBuilding.getOsmIdentifier()));
this.markAsFlagged(uniqueIdentifier);
hadIntersection = true;
}
}
if (hadIntersection) {
return Optional.of(flag);
}
return Optional.empty();
}
use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.
the class RoundaboutValenceCheck 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;
// Get all edges in the roundabout
final Set<Edge> roundaboutEdges = getAllRoundaboutEdges(edge);
final Set<Edge> connectedEdges = roundaboutEdges.stream().flatMap(roundaboutEdge -> roundaboutEdge.connectedEdges().stream()).filter(HighwayTag::isCarNavigableHighway).filter(Edge::isMasterEdge).filter(currentEdge -> !JunctionTag.isRoundabout(currentEdge)).filter(currentEdge -> !roundaboutEdges.contains(currentEdge)).collect(Collectors.toSet());
final int totalRoundaboutValence = connectedEdges.size();
// or greater than or equal to the maximum configured number of connections
if (totalRoundaboutValence < this.minimumValence || totalRoundaboutValence > this.maximumValence) {
this.markAsFlagged(object.getIdentifier());
// If the roundabout valence is 1, this should be labelled as a turning loop instead
if (totalRoundaboutValence == 1) {
return Optional.of(this.createFlag(roundaboutEdges, this.getLocalizedInstruction(1, edge.getOsmIdentifier())));
}
// Otherwise, we want to flag and given information about identifier and valence
return Optional.of(this.createFlag(roundaboutEdges, this.getLocalizedInstruction(0, edge.getOsmIdentifier(), totalRoundaboutValence)));
} else // If the totalRoundaboutValence is not unusual, we don't flag the object
{
return Optional.empty();
}
}
use of org.openstreetmap.atlas.checks.flag.CheckFlag 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();
}
Aggregations