Search in sources :

Example 11 with CheckFlag

use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.

the class InvalidTurnRestrictionCheck method flag.

@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
    final Optional<CheckFlag> result;
    final Relation relation = (Relation) object;
    if (!TurnRestriction.from(relation).isPresent()) {
        final Set<AtlasObject> members = relation.members().stream().map(RelationMember::getEntity).collect(Collectors.toSet());
        result = Optional.of(createFlag(members, this.getLocalizedInstruction(0, relation.getOsmIdentifier())));
    } else {
        result = Optional.empty();
    }
    return result;
}
Also used : AtlasObject(org.openstreetmap.atlas.geography.atlas.items.AtlasObject) Relation(org.openstreetmap.atlas.geography.atlas.items.Relation) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag)

Example 12 with CheckFlag

use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.

the class CheckFlagEvent method flagToFeature.

/**
 * Converts give {@link CheckFlag} to {@link GeoJsonObject} with additional key-value parameters
 *
 * @param flag
 *            {@link CheckFlag} to convert to {@link GeoJsonObject}
 * @param additionalProperties
 *            additional key-value parameters to be added in "properties" element of the
 *            top-level JSON object
 * @return {@link GeoJsonObject} created from {@link CheckFlag}
 */
public static JsonObject flagToFeature(final CheckFlag flag, final Map<String, String> additionalProperties) {
    final JsonObject flagProperties = new JsonObject();
    flagProperties.addProperty("instructions", flag.getInstructions());
    // Add additional properties
    additionalProperties.forEach(flagProperties::addProperty);
    final JsonObject feature;
    final List<LocationIterableProperties> geometries = flag.getLocationIterableProperties();
    if (geometries.size() == 1) {
        feature = GEOJSON_BUILDER.create(geometries.get(0));
    } else {
        feature = GEOJSON_BUILDER.createGeometryCollection(geometries).jsonObject();
    }
    final JsonArray featureProperties = new JsonArray();
    final Set<JsonElement> featureOsmIds = new HashSet<>();
    geometries.stream().forEach(geometry -> Optional.ofNullable(geometry.getProperties()).ifPresent(propertyMap -> {
        final JsonObject properties = new JsonObject();
        propertyMap.forEach(properties::addProperty);
        featureProperties.add(properties);
        Optional.ofNullable(properties.get("osmid")).ifPresent(featureOsmIds::add);
    }));
    final JsonArray uniqueFeatureOsmIds = new JsonArray();
    featureOsmIds.forEach(uniqueFeatureOsmIds::add);
    // Override name property if able to add a decorator to the name
    CheckFlagEvent.featureDecorator(featureProperties).ifPresent(decorator -> flagProperties.addProperty("name", String.format("%s (%s)", Optional.ofNullable(flagProperties.getAsJsonPrimitive("name")).map(JsonPrimitive::getAsString).orElse("Task"), decorator)));
    // Reference properties lost during GeoJson conversion
    flagProperties.add("feature_properties", featureProperties);
    flagProperties.add("feature_osmids", uniqueFeatureOsmIds);
    flagProperties.addProperty("feature_count", geometries.size());
    feature.addProperty("id", flag.getIdentifier());
    feature.add("properties", flagProperties);
    return feature;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Check(org.openstreetmap.atlas.checks.base.Check) GeoJsonObject(org.openstreetmap.atlas.geography.geojson.GeoJsonObject) GeoJsonBuilder(org.openstreetmap.atlas.geography.geojson.GeoJsonBuilder) LocationIterableProperties(org.openstreetmap.atlas.geography.geojson.GeoJsonBuilder.LocationIterableProperties) Set(java.util.Set) HashMap(java.util.HashMap) HashSet(java.util.HashSet) JsonElement(com.google.gson.JsonElement) HighwayTag(org.openstreetmap.atlas.tags.HighwayTag) List(java.util.List) JsonArray(com.google.gson.JsonArray) Map(java.util.Map) Optional(java.util.Optional) JsonPrimitive(com.google.gson.JsonPrimitive) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) GeoJsonObject(org.openstreetmap.atlas.geography.geojson.GeoJsonObject) LocationIterableProperties(org.openstreetmap.atlas.geography.geojson.GeoJsonBuilder.LocationIterableProperties) HashSet(java.util.HashSet)

Example 13 with CheckFlag

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

Example 14 with CheckFlag

use of org.openstreetmap.atlas.checks.flag.CheckFlag 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();
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) Rectangle(org.openstreetmap.atlas.geography.Rectangle) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) PolyLine(org.openstreetmap.atlas.geography.PolyLine) Edge(org.openstreetmap.atlas.geography.atlas.items.Edge) Location(org.openstreetmap.atlas.geography.Location)

Example 15 with CheckFlag

use of org.openstreetmap.atlas.checks.flag.CheckFlag in project atlas-checks by osmlab.

the class AbbreviatedNameCheck method flag.

/**
 * Flags {@link AtlasObject}s that has names with abbreviations.
 */
@Override
protected Optional<CheckFlag> flag(final AtlasObject object) {
    // Mark OSM identifier as we are processing it
    this.markAsFlagged(this.getUniqueOSMIdentifier((AtlasEntity) object));
    // Fetch the name
    final Optional<String> optionalName = NameTag.getNameOf(object);
    if (!optionalName.isPresent()) {
        return Optional.empty();
    }
    // Lowercase name and parse it into tokens
    final String name = optionalName.get();
    final String lowercaseName = name.toLowerCase(this.getLocale());
    final Set<String> tokens = Sets.newHashSet(NAME_SPLITTER.split(lowercaseName));
    // Flag if it has any abbreviations
    if (tokens.stream().anyMatch(this.abbreviations::contains)) {
        final CheckFlag flag = this.createFlag(object, this.getLocalizedInstruction(0, object.getOsmIdentifier(), name));
        return Optional.of(flag);
    }
    return Optional.empty();
}
Also used : AtlasEntity(org.openstreetmap.atlas.geography.atlas.items.AtlasEntity) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag)

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