Search in sources :

Example 1 with Location

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;
}
Also used : JsonArray(com.google.gson.JsonArray) Task(org.openstreetmap.atlas.checks.maproulette.data.Task) PolyLine(org.openstreetmap.atlas.geography.PolyLine) GeoJsonBuilder(org.openstreetmap.atlas.geography.geojson.GeoJsonBuilder) Location(org.openstreetmap.atlas.geography.Location)

Example 2 with Location

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);
    });
}
Also used : FlaggedObject(org.openstreetmap.atlas.checks.flag.FlaggedObject) FlaggedPoint(org.openstreetmap.atlas.checks.flag.FlaggedPoint) Location(org.openstreetmap.atlas.geography.Location) Test(org.junit.Test)

Example 3 with Location

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);
    });
}
Also used : FlaggedObject(org.openstreetmap.atlas.checks.flag.FlaggedObject) FlaggedPoint(org.openstreetmap.atlas.checks.flag.FlaggedPoint) Location(org.openstreetmap.atlas.geography.Location) Test(org.junit.Test)

Example 4 with Location

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));
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) PackedAtlasBuilder(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasBuilder) Rectangle(org.openstreetmap.atlas.geography.Rectangle) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) Segment(org.openstreetmap.atlas.geography.Segment) Location(org.openstreetmap.atlas.geography.Location) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Location

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;
}
Also used : PolyLine(org.openstreetmap.atlas.geography.PolyLine) PolyLine(org.openstreetmap.atlas.geography.PolyLine) Line(org.openstreetmap.atlas.geography.atlas.items.Line) Area(org.openstreetmap.atlas.geography.atlas.items.Area) CoreException(org.openstreetmap.atlas.exception.CoreException) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) Polygon(org.openstreetmap.atlas.geography.Polygon) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) Location(org.openstreetmap.atlas.geography.Location)

Aggregations

Location (org.openstreetmap.atlas.geography.Location)8 Test (org.junit.Test)3 CheckFlag (org.openstreetmap.atlas.checks.flag.CheckFlag)3 PolyLine (org.openstreetmap.atlas.geography.PolyLine)3 Edge (org.openstreetmap.atlas.geography.atlas.items.Edge)3 FlaggedObject (org.openstreetmap.atlas.checks.flag.FlaggedObject)2 FlaggedPoint (org.openstreetmap.atlas.checks.flag.FlaggedPoint)2 Rectangle (org.openstreetmap.atlas.geography.Rectangle)2 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)2 JsonArray (com.google.gson.JsonArray)1 HashSet (java.util.HashSet)1 Task (org.openstreetmap.atlas.checks.maproulette.data.Task)1 CoreException (org.openstreetmap.atlas.exception.CoreException)1 Polygon (org.openstreetmap.atlas.geography.Polygon)1 Segment (org.openstreetmap.atlas.geography.Segment)1 Area (org.openstreetmap.atlas.geography.atlas.items.Area)1 Line (org.openstreetmap.atlas.geography.atlas.items.Line)1 Node (org.openstreetmap.atlas.geography.atlas.items.Node)1 PackedAtlasBuilder (org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasBuilder)1 GeoJsonBuilder (org.openstreetmap.atlas.geography.geojson.GeoJsonBuilder)1