private AtlasPrimitiveLocationItem convert(final LocationItem item) { return new AtlasPrimitiveLocationItem(item.getIdentifier(), item.getLocation(), item.getTags()); }
@SuppressWarnings("unchecked") private Map<String, String> initProperties(final LocationItem locationItem) { final Map<String, String> tags = locationItem.getTags(); tags.put(ITEM_IDENTIFIER_TAG, locationItem.getIdentifier() + ""); tags.put(OSM_IDENTIFIER_TAG, locationItem.getOsmIdentifier() + ""); if (locationItem instanceof Node) { tags.put(ITEM_TYPE_TAG, NODE_TAG); } else if (locationItem instanceof Point) { tags.put(ITEM_TYPE_TAG, POINT_TAG); } else { logger.warn("Flagged LocationItem with unknown item type {}", locationItem); } return tags; } }
@Override public JsonObject asGeoJsonFeature(final String flagIdentifier) { final JsonObject feature; final JsonObject properties; if (locationItem != null) { feature = locationItem.asGeoJsonGeometry(); properties = feature.getAsJsonObject("properties"); } else { properties = new JsonObject(); feature = GeoJsonUtils.feature(point.asGeoJsonGeometry(), properties); } properties.addProperty("flag:id", flagIdentifier); properties.addProperty("flag:type", FlaggedPoint.class.getSimpleName()); return feature; }
protected void validateLocationPresent() { for (final LocationItem locationItem : this.atlas.locationItems()) { if (locationItem.getLocation() == null) { throw new CoreException("{} {} is missing a Location.", locationItem.getType(), locationItem.getIdentifier()); } } } }
@Override public JsonObject asGeoJsonGeometry() { return GeoJsonUtils.feature(getLocation().asGeoJsonGeometry(), geoJsonProperties()); }
@Override public LocationIterableProperties toGeoJsonBuildingBlock() final Map<String, String> tags = getTags(); tags.put("identifier", String.valueOf(getIdentifier())); tags.put("osmIdentifier", String.valueOf(getOsmIdentifier())); tags.put("itemType", String.valueOf(getType())); final Location location = this.getLocation(); tags.put("latitude", String.valueOf(location.getLatitude().asDm7())); tags.put("longitude", String.valueOf(location.getLongitude().asDm7())); this.relations().forEach(relation -> final RelationMember member = relation.members().get(getIdentifier(), getType()); parentRelations.add(member.getRelationIdentifier() + "-" + member.getRole()); }); return new GeoJsonBuilder.LocationIterableProperties(getRawGeometry(), tags);
@Override public Iterable<Location> getRawGeometry() { return getLocation(); }
@Override public Rectangle bounds() { if (locationItem != null) { return locationItem.bounds(); } else { return point.bounds(); } }
@Override public JsonObject geoJsonProperties() { final JsonObject properties = super.geoJsonProperties(); final JsonArray inEdgesArray = new JsonArray(); final JsonArray outEdgesArray = new JsonArray(); for (final Edge edge : this.inEdges()) { inEdgesArray.add(new JsonPrimitive(edge.getIdentifier())); } for (final Edge edge : this.outEdges()) { outEdgesArray.add(new JsonPrimitive(edge.getIdentifier())); } // Adding a JSON array with the edge IDs. // In the RFC spec, nested objects are ok in properties. // https://tools.ietf.org/html/rfc7946#section-1.5 properties.add("inEdges", inEdgesArray); properties.add("outEdges", outEdgesArray); return properties; }
@Override public boolean intersects(final GeometricSurface surface) { return surface.fullyGeometricallyEncloses(getLocation()); }
@Override public String toWkt() { return this.getLocation().toWkt(); } }
@Override public byte[] toWkb() { return this.getLocation().toWkb(); }
/** * Default constructor * * @param locationItem * the {@link LocationItem} to flag */ public FlaggedPoint(final LocationItem locationItem) { this.locationItem = locationItem; this.point = locationItem.getLocation(); this.properties = initProperties(locationItem); }
@Override public Rectangle bounds() { return getLocation().bounds(); }
private boolean locationItemCoversInitialShardBounds(final LocationItem locationItem) { return this.policy.getInitialShardsBounds() .fullyGeometricallyEncloses(locationItem.getLocation()); }
public SnappedLocation snapTo(final LineItem other) { return this.getLocation().snapTo(other.asPolyLine()); }
public SnappedLocation snapTo(final Area other) { return this.getLocation().snapTo(other.asPolygon()); }
boolean locationItemCovered(final LocationItem item) { final Location location = item.getLocation(); final MultiPolygon initialShardsBounds = this.policy.getInitialShardsBounds(); if (!this.policy.isExtendIndefinitely() && !initialShardsBounds.fullyGeometricallyEncloses(location)) { // If the policy is to not extend indefinitely, then assume that the loading is not // necessary. return true; } final Iterable<? extends Shard> neededShards = this.sharding.shardsCovering(location); for (final Shard neededShard : neededShards) { if (!this.loadedShards.containsKey(neededShard)) { newLocation(location, item); return false; } } return true; }
@Override public GeometryPrintable convert(final AtlasEntity source) { GeometryPrintable result = null; if (source instanceof Area) { result = ((Area) source).asPolygon(); } else if (source instanceof LineItem) { result = ((LineItem) source).asPolyLine(); } else if (source instanceof LocationItem) { result = ((LocationItem) source).getLocation(); } else { // Relation result = ((Relation) source).bounds(); } if (result == null) { result = source.bounds(); } return result; } }
@Override public boolean multiPolygonEntityIntersecting(final MultiPolygon multiPolygon, final AtlasEntity entity) { if (entity instanceof LineItem) { return multiPolygon.overlaps(((LineItem) entity).asPolyLine()); } if (entity instanceof LocationItem) { return multiPolygon .fullyGeometricallyEncloses(((LocationItem) entity).getLocation()); } if (entity instanceof Area) { return multiPolygon.overlaps(((Area) entity).asPolygon()); } if (entity instanceof Relation) { return ((Relation) entity).members().stream().map(RelationMember::getEntity) .anyMatch(relationEntity -> this .multiPolygonEntityIntersecting(multiPolygon, relationEntity)); } else { return false; } }