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