@Override public String toWkt() { return bounds().toWkt(); }
@Override public JsonElement serialize(final Change source, final Type typeOfSource, final JsonSerializationContext context) { final JsonObject result = new JsonObject(); result.addProperty("type", "FeatureCollection"); final Rectangle bounds = source.bounds(); result.add("bbox", bounds.asGeoJsonBbox()); final JsonArray features = new JsonArray(); source.changes().map(featureChangeTypeHierarchyAdapter::serialize) .forEach(features::add); result.add("features", features); final JsonObject properties = new JsonObject(); properties.addProperty("bboxWKT", source.bounds().toWkt()); result.add("properties", properties); return result; } }
public JsonElement serialize(final FeatureChange source) { final JsonObject result = new JsonObject(); result.addProperty("type", "Feature"); final Rectangle bounds = source.bounds(); result.add("bbox", bounds.asGeoJsonBbox()); final GeometryPrintable geometryPrintable = new AtlasEntityGeometryPrintableConverter() .convert(source.getReference()); addGeometryGeojson(result, geometryPrintable); final JsonObject properties = new JsonObject(); properties.addProperty("featureChangeType", source.getChangeType().toString()); new AtlasEntityPropertiesConverter().convert(source.getReference()).entrySet() .forEach(entry -> properties.add(entry.getKey(), entry.getValue())); addGeometryWkt(properties, geometryPrintable); properties.addProperty("bboxWKT", source.bounds().toWkt()); result.add("properties", properties); return result; }
@Override protected int onRun(final CommandMap command) { final Sharding sharding = (Sharding) command.get(SHARDING); Location location = (Location) command.get(LOCATION); if (location == null) { location = (Location) command.get(WKT_POINT); } if (location == null) { System.err.println("No location found! Make sure to use either the -" + LOCATION.getName() + " or -" + WKT_POINT.getName() + " switch."); return 0; } final Set<? extends Shard> shards = Iterables.asSet(sharding.shardsCovering(location)); if (shards.size() > 0) { System.out.println("Shard(s) covering " + location.toCompactString() + ":"); shards.forEach( shard -> System.out.println(shard.getName() + "; " + shard.bounds().toWkt())); } else { System.err.println("No shard found!"); return 1; } return 0; }
@Test public void testBounds() { final Atlas atlas = this.rule.getAtlas(); Assert.assertEquals( "POLYGON ((-122.2450237 37.5920679, -122.2450237 37.5938783, " + "-122.2412753 37.5938783, -122.2412753 37.5920679, -122.2450237 37.5920679))", atlas.bounds().toWkt()); final ChangeBuilder changeBuilder = new ChangeBuilder(); // One-way motorway final Edge source = atlas.edge(39004000002L); final PolyLine newPolyLine = source.asPolyLine().shiftLastAlongGreatCircle(Heading.NORTH, Distance.ONE_METER); final Location end = newPolyLine.last(); final FeatureChange featureChange = new FeatureChange(ChangeType.ADD, CompleteEdge.shallowFrom(source).withPolyLine(newPolyLine)); changeBuilder.add(featureChange); changeBuilder.add(new FeatureChange(ChangeType.ADD, CompleteNode.shallowFrom(atlas.node(38990000000L)).withLocation(end))); final Change change = changeBuilder.get(); final Atlas changeAtlas = new ChangeAtlas(atlas, change); Assert.assertEquals( "POLYGON ((-122.2450237 37.5920679, -122.2450237 37.5938873, " + "-122.2412753 37.5938873, -122.2412753 37.5920679, -122.2450237 37.5920679))", changeAtlas.bounds().toWkt()); }