use of org.openstreetmap.atlas.geography.Location in project atlas-checks by osmlab.
the class CheckFlag method getMapRouletteTask.
/**
* Builds a MapRouletted {@link Task} from this {@link CheckFlag}
*
* @return a {@link Task}
*/
public Task getMapRouletteTask() {
final Task task = new Task();
task.setInstruction(this.getInstructions());
task.setProjectName(this.getCountryISO());
task.setChallengeName(this.getChallengeName().orElse(this.getClass().getSimpleName()));
task.setTaskIdentifier(this.identifier);
// Add custom pin point(s), if supplied.
final Set<Location> points = getPoints();
if (!points.isEmpty()) {
task.setPoints(points);
} else {
final Set<PolyLine> polyLines = getPolyLines();
if (!polyLines.isEmpty()) {
// Retrieve the first item in the list and retrieve the first point in the
// geometry for the object
task.setPoint(polyLines.iterator().next().iterator().next());
}
}
final JsonArray features = new JsonArray();
this.getLocationIterableProperties().forEach(shape -> features.add(new GeoJsonBuilder().create(shape)));
task.setGeoJson(Optional.of(features));
return task;
}
use of org.openstreetmap.atlas.geography.Location in project atlas-checks by osmlab.
the class SignPostCheckTest method primaryLinkTrunkMissingJunctionAndDestinationAtlas.
@Test
public void primaryLinkTrunkMissingJunctionAndDestinationAtlas() {
this.verifier.actual(this.setup.primaryLinkTrunkMissingJunctionAndDestinationAtlas(), CHECK);
this.verifier.verifyExpectedSize(1);
this.verifier.verify(flag -> verify(flag, 2, true, true));
// Verify that we flagged starting node of the ramp (formed by 2 edges)
this.verifier.verify(flag -> {
final FlaggedObject flaggedPoint = flag.getFlaggedObjects().stream().filter(object -> object instanceof FlaggedPoint).findFirst().get();
final Location flaggedLocation = flaggedPoint.getGeometry().iterator().next();
Assert.assertEquals(Location.forString(SignPostCheckTestRule.LINK_1), flaggedLocation);
});
}
use of org.openstreetmap.atlas.geography.Location in project atlas-checks by osmlab.
the class SignPostCheckTest method motorwayLinkMotorwayMissingJunctionAndDestinationAtlas.
@Test
public void motorwayLinkMotorwayMissingJunctionAndDestinationAtlas() {
this.verifier.actual(this.setup.motorwayLinkMotorwayMissingJunctionAndDestinationAtlas(), CHECK);
this.verifier.verifyExpectedSize(1);
this.verifier.verify(flag -> verify(flag, 2, true, true));
// Verify that we flagged starting node of the ramp (formed by single edge)
this.verifier.verify(flag -> {
final FlaggedObject flaggedPoint = flag.getFlaggedObjects().stream().filter(object -> object instanceof FlaggedPoint).findFirst().get();
final Location flaggedLocation = flaggedPoint.getGeometry().iterator().next();
Assert.assertEquals(Location.forString(SignPostCheckTestRule.LINK_1), flaggedLocation);
});
}
use of org.openstreetmap.atlas.geography.Location in project atlas-checks by osmlab.
the class DuplicateNodeCheckTest method testCheck.
@Test
public void testCheck() {
final Rectangle bounds = Rectangle.TEST_RECTANGLE;
final Set<Location> nodes = new HashSet<>();
while (nodes.size() < 10) {
nodes.add(Location.random(bounds));
}
final PackedAtlasBuilder builder = new PackedAtlasBuilder();
int identifier = 0;
for (final Location node : nodes) {
// for first node make it a duplicate
if (identifier == 0) {
builder.addNode(identifier++, node, RandomTagsSupplier.randomTags(5));
}
builder.addNode(identifier++, node, RandomTagsSupplier.randomTags(5));
}
final Iterator<Location> locationIterator = nodes.iterator();
final Location start = locationIterator.next();
identifier = 0;
while (locationIterator.hasNext()) {
if (identifier == 0) {
builder.addEdge(identifier++, new Segment(start, locationIterator.next()), RandomTagsSupplier.randomTags(5));
}
builder.addEdge(identifier++, new Segment(start, locationIterator.next()), RandomTagsSupplier.randomTags(5));
}
final Atlas atlas = builder.get();
final Iterable<CheckFlag> flags = new DuplicateNodeCheck(ConfigurationResolver.emptyConfiguration()).flags(atlas);
Assert.assertEquals(1, Iterables.size(flags));
}
use of org.openstreetmap.atlas.geography.Location 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;
}
Aggregations