Search in sources :

Example 6 with CheckFlag

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

Example 7 with CheckFlag

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

Example 8 with CheckFlag

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

Example 9 with CheckFlag

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();
    }
}
Also used : Arrays(java.util.Arrays) Set(java.util.Set) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) List(java.util.List) BaseCheck(org.openstreetmap.atlas.checks.base.BaseCheck) JunctionTag(org.openstreetmap.atlas.tags.JunctionTag) Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) AtlasObject(org.openstreetmap.atlas.geography.atlas.items.AtlasObject) Optional(java.util.Optional) Queue(java.util.Queue) LinkedList(java.util.LinkedList) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge)

Example 10 with CheckFlag

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();
}
Also used : Arrays(java.util.Arrays) TaggableFilter(org.openstreetmap.atlas.tags.filters.TaggableFilter) Strings(org.apache.directory.api.util.Strings) Set(java.util.Set) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) Heading(org.openstreetmap.atlas.geography.Heading) Validators(org.openstreetmap.atlas.tags.annotations.validation.Validators) TypePredicates(org.openstreetmap.atlas.checks.atlas.predicates.TypePredicates) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) List(java.util.List) BaseCheck(org.openstreetmap.atlas.checks.base.BaseCheck) Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) AtlasObject(org.openstreetmap.atlas.geography.atlas.items.AtlasObject) DestinationTag(org.openstreetmap.atlas.tags.DestinationTag) Angle(org.openstreetmap.atlas.utilities.scalars.Angle) Node(org.openstreetmap.atlas.geography.atlas.items.Node) Optional(java.util.Optional) Distance(org.openstreetmap.atlas.utilities.scalars.Distance) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) Node(org.openstreetmap.atlas.geography.atlas.items.Node) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge)

Aggregations

CheckFlag (org.openstreetmap.atlas.checks.flag.CheckFlag)17 Edge (org.openstreetmap.atlas.geography.atlas.items.Edge)6 HashSet (java.util.HashSet)4 List (java.util.List)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Test (org.junit.Test)4 AtlasObject (org.openstreetmap.atlas.geography.atlas.items.AtlasObject)4 HighwayTag (org.openstreetmap.atlas.tags.HighwayTag)4 Configuration (org.openstreetmap.atlas.utilities.configuration.Configuration)4 Arrays (java.util.Arrays)3 BaseCheck (org.openstreetmap.atlas.checks.base.BaseCheck)3 Location (org.openstreetmap.atlas.geography.Location)3 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)3 Area (org.openstreetmap.atlas.geography.atlas.items.Area)3 Queue (java.util.Queue)2 Collectors (java.util.stream.Collectors)2 PierTestCheck (org.openstreetmap.atlas.checks.base.checks.PierTestCheck)2 PolyLine (org.openstreetmap.atlas.geography.PolyLine)2 Polygon (org.openstreetmap.atlas.geography.Polygon)2