private static List<LocationIterableProperties> processRelationForGeoJson( final Relation relation, final Map<String, String> parentTags) { final Map<String, String> relationTags = relation.getTags(); final Map<String, String> modifiedRelationTags = new HashMap<>(parentTags); for (final String key : relationTags.keySet()) { modifiedRelationTags.put("[REL_ID:" + relation.getIdentifier() + "]" + key, relationTags.get(key)); } final List<LocationIterableProperties> result = new ArrayList<>(); for (final RelationMember member : relation.members()) { if (member.getEntity() instanceof Relation) { final Relation subRelation = (Relation) member.getEntity(); result.addAll(processRelationForGeoJson(subRelation, modifiedRelationTags)); } else { final AtlasItem item = (AtlasItem) member.getEntity(); final Map<String, String> modifiedTags = item.getTags(); modifiedTags.putAll(modifiedRelationTags); result.add(new LocationIterableProperties(item.getRawGeometry(), modifiedTags)); } } return result; }
/** * Converts deprecated LocationIterableProperties to GeometryWithProperties. * * @param locationIterableProperties * LocationIterableProperties object * @return GeometryWithProperties object */ protected static final GeometryWithProperties toGeometryWithProperties( final LocationIterableProperties locationIterableProperties) { final Map<String, Object> propertiesObjects = new HashMap<>(); propertiesObjects.putAll(locationIterableProperties.getProperties()); return new GeometryWithProperties(locationIterableProperties.getLocations(), propertiesObjects); }
final Set<JsonElement> featureOsmIds = new HashSet<>(); geometries.stream().forEach( geometry -> Optional.ofNullable(geometry.getProperties()).ifPresent(propertyMap ->
return new GeoJsonBuilder.LocationIterableProperties(getRawGeometry(), tags);
@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 Optional<String> shardName = getAtlas().metaData().getShardName(); shardName.ifPresent(shard -> tags.put("shard", shard)); if (this instanceof Edge) { tags.put("startNode", String.valueOf(((Edge) this).start().getIdentifier())); tags.put("endNode", String.valueOf(((Edge) this).end().getIdentifier())); } final StringList parentRelations = new StringList(); this.relations().forEach(relation -> { final RelationMember member = relation.members().get(getIdentifier(), getType()); parentRelations.add(member.getRelationIdentifier() + "-" + member.getRole()); }); if (!parentRelations.isEmpty()) { tags.put("parentRelations", parentRelations.join(", ")); } return new GeoJsonBuilder.LocationIterableProperties(getRawGeometry(), tags); }
@Test public void testFeatureCollection() { final Map<String, String> properties = new HashMap<>(); properties.put("property", "value"); properties.put("property2", "value2"); final List<LocationIterableProperties> items = new ArrayList<>(); items.add(new LocationIterableProperties(Location.TEST_1, properties)); items.add(new LocationIterableProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new LocationIterableProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().create(items); Assert.assertEquals( "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\"" + ":[-122.009566,37.33531]},\"properties\":{\"property2\":\"value2\",\"property\":\"value\"}},{\"type\":\"Feature\",\"geometry\"" + ":{\"type\":\"Polygon\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]]},\"properties\"" + ":{\"property2\":\"value2\",\"property\":\"value\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"LineString\",\"coordinates\"" + ":[[-122.031007,37.390535],[-122.028464,37.321628]]},\"properties\":{\"property2\":\"value2\",\"property\":\"value\"}}]}", object.toString()); }
@Test public void testGeometryCollectionMultipleForm() { final Map<String, String> properties = new HashMap<>(); final List<LocationIterableProperties> items = new ArrayList<>(); items.add(new LocationIterableProperties(Location.TEST_1, properties)); items.add(new LocationIterableProperties(Location.TEST_1, properties)); items.add(new LocationIterableProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new LocationIterableProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new LocationIterableProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); items.add(new LocationIterableProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().createGeometryCollection(items); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"MultiPoint\",\"coordinates\":[[-122.009566,37.33531],[-122.009566,37.33531]]},{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]],[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]]]},{\"type\":\"MultiLineString\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628]],[[-122.031007,37.390535],[-122.028464,37.321628]]]}]}}", object.toString()); }
public static void saveAsGeojson(final Iterable<ComplexBoundary> complexBoundaries, final WritableResource output) { try (JsonWriter writer = new JsonWriter(output)) { final Iterable<LocationIterableProperties> geojsonObjects = Iterables .stream(complexBoundaries).flatMap(boundary -> { final Map<String, String> tags = boundary.getSource().getTags(); return Iterables .stream(boundary.getOutline().asLocationIterableProperties()) .map(locationIterableProperties -> { locationIterableProperties.getProperties().putAll(tags); return locationIterableProperties; }); }); writer.write(new GeoJsonBuilder().create(geojsonObjects).jsonObject()); } }
@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 Optional<String> shardName = getAtlas().metaData().getShardName(); shardName.ifPresent(shard -> tags.put("shard", shard)); final StringList parentRelations = new StringList(); this.relations().forEach(relation -> { final RelationMember member = relation.members().get(getIdentifier(), getType()); parentRelations.add(member.getRelationIdentifier() + "-" + member.getRole()); }); if (!parentRelations.isEmpty()) { tags.put("parentRelations", parentRelations.join(", ")); } return new GeoJsonBuilder.LocationIterableProperties(getClosedGeometry(), tags); }
private static void processDiffEntity(final Diff diff, final AtlasEntity entity, final List<LocationIterableProperties> items, final String diffStage) { // Depending on if it is a before or after for a given diff type, an entity may be null. if (entity != null) { final Map<String, String> tags = entity.getTags(); tags.put("diff", diffStage); tags.put("diff:type", diff.getDiffType().name()); tags.put("diff:reason", diff.getDiffReason().name()); if (diff.getItemType() == ItemType.RELATION) { items.addAll(processRelationForGeoJson((Relation) entity, tags)); } else { items.add(new LocationIterableProperties(((AtlasItem) entity).getRawGeometry(), tags)); } } }
public GeoJsonObject toGeoJson(final ChangeSet changeSet) { final List<GeoJsonBuilder.LocationIterableProperties> collection = new ArrayList<>(); changeSet.iterator().forEachRemaining(changeItem -> { if (changeItem.getGeometry() == null) { return; } changeItem.getTags().put("action", changeItem.getAction().name()); changeItem.getTags().put("id", String.valueOf(changeItem.getIdentifier())); collection.add(new GeoJsonBuilder.LocationIterableProperties(changeItem.getGeometry(), changeItem.getTags())); }); final GeoJsonBuilder builder = new GeoJsonBuilder(); return builder.create(collection); } }
@Test public void testToGeometryWithProperties() { final Map<String, String> stringProperties = new HashMap<>(); stringProperties.put("prop1", "val1"); stringProperties.put("prop2", "val2"); final LocationIterableProperties locationIterableProperties = new LocationIterableProperties( PolyLine.TEST_POLYLINE, stringProperties); final GeometryWithProperties geometryWithProperties = GeoJsonBuilder .toGeometryWithProperties(locationIterableProperties); Assert.assertEquals(PolyLine.TEST_POLYLINE, geometryWithProperties.getGeometry()); for (final Entry<String, String> stringPropertiesEntry : stringProperties.entrySet()) { Assert.assertEquals(stringPropertiesEntry.getValue(), geometryWithProperties.getProperties().get(stringPropertiesEntry.getKey())); } } }
public Iterable<LocationIterableProperties> asLocationIterableProperties() { final Iterable<LocationIterableProperties> outers = Iterables.translate(outers(), polygon -> { final Map<String, String> tags = new HashMap<>(); tags.put("MultiPolygon", "outer"); return new LocationIterableProperties(polygon, tags); }); final Iterable<LocationIterableProperties> inners = Iterables.translate(inners(), polygon -> { final Map<String, String> tags = new HashMap<>(); tags.put("MultiPolygon", "inner"); return new LocationIterableProperties(polygon, tags); }); return new MultiIterable<>(outers, inners); }
@Test public void testGeometryCollectionSingularForm() { final Map<String, String> properties = new HashMap<>(); final List<LocationIterableProperties> items = new ArrayList<>(); items.add(new LocationIterableProperties(Location.TEST_1, properties)); items.add(new LocationIterableProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new LocationIterableProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().createGeometryCollection(items); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[-122.009566,37.33531]},{\"type\":\"Polygon\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544]]]},{\"type\":\"LineString\",\"coordinates\":[[-122.031007,37.390535],[-122.028464,37.321628]]}]}}", object.toString()); }
/** * @return a list of {@link GeoJsonBuilder.LocationIterableProperties} representing all flagged * geometries */ public List<GeoJsonBuilder.LocationIterableProperties> getLocationIterableProperties() { return this.flaggedObjects.stream() .map(flaggedObject -> new GeoJsonBuilder.LocationIterableProperties( flaggedObject.getGeometry(), flaggedObject.getProperties())) .collect(Collectors.toList()); }
public static void save(final Iterable<? extends Iterable<Location>> geometries, final WritableResource destination) { final GeoJsonObject object = new GeoJsonBuilder().create(Iterables.translate(geometries, polyLine -> new GeoJsonBuilder.LocationIterableProperties(polyLine, Maps.hashMap()))); save(object, destination); }
public Iterable<LocationIterableProperties> asGeoJsonRestrictedPath() { return this.turnRestrictions().stream() .map(turnRestriction -> new LocationIterableProperties( turnRestriction.getRoute().asPolyLine(), Maps.hashMap("highway", "motorway", "oneway", "yes", "route", turnRestriction.getRoute().toString()))) .collect(Collectors.toList()); }
@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())); tags.put("relation", this.toSimpleString()); final Optional<String> shardName = getAtlas().metaData().getShardName(); shardName.ifPresent(shard -> tags.put("shard", shard)); return new GeoJsonBuilder.LocationIterableProperties(bounds().center(), tags); }
public LocationIterableProperties toGeoJsonBuildingBlock() { final Map<String, String> tags = new HashMap<>(); tags.put("tile", this.name()); return new GeoJsonBuilder.LocationIterableProperties(bounds(), tags); }
public Iterable<GeoJsonBuilder.LocationIterableProperties> asLocationIterableProperties() { return this.polyLineList.stream() .map(polyLine -> new GeoJsonBuilder.LocationIterableProperties(polyLine, new HashMap<>())) .collect(Collectors.toList()); }