public GeoJsonObject asGeoJson() { return new GeoJsonBuilder().create(this); }
/** * @deprecated use {@link MultiPolygon#asGeoJsonFeatureCollection()} instead, for geojson that * represents the same geometry * @return multiple geojson polygon features in a feature collection */ @Deprecated public GeoJsonObject asGeoJson() { return new GeoJsonBuilder().create(asLocationIterableProperties()); }
public static GeoJsonObject asGeoJson(final Iterable<? extends Iterable<Location>> geometries) { return new GeoJsonBuilder().create(Iterables.translate(geometries, geometry -> new LocationIterableProperties(geometry, new HashMap<>()))); }
public GeoJsonObject asGeoJson() { return new GeoJsonBuilder().create(Iterables.from(asGeoJsonBigNode())); }
@Override public GeoJsonObject convert(final Atlas atlas) { return new GeoJsonBuilder().create( Iterables.translate(new BigNodeFinder().find(atlas), BigNode::asGeoJsonBigNode)); } }
@Override public GeoJsonObject convert(final Atlas atlas) { return new GeoJsonBuilder(this.logFrequency).create(Iterables .translateMulti(new BigNodeFinder().find(atlas), BigNode::asGeoJsonRestrictedPath)); } }
@Override public GeoJsonObject asGeoJson(final Predicate<AtlasEntity> matcher) { return new GeoJsonBuilder().create(Iterables.filterTranslate(entities(), atlasEntity -> atlasEntity.toGeoJsonBuildingBlock(), matcher)); }
public GeoJsonObject asGeoJsonFeatureCollection() { final GeoJsonBuilder builder = new GeoJsonBuilder(); return builder.createFeatureCollection(Iterables.translate(outers(), outerPolygon -> builder.createOneOuterMultiPolygon( new MultiIterable<>(Collections.singleton(outerPolygon), this.outerToInners.get(outerPolygon))))); }
/** * Find the big nodes and save them as geojson in a resource * * @param atlas * The atlas to look at * @param writableResource * Where to save the geojson */ public void findAndSaveBigNodesAsGeoJson(final Atlas atlas, final WritableResource writableResource) { final List<LocationIterableProperties> features = new ArrayList<>(); Iterables.stream(this.find(atlas)).map(BigNode::asGeoJsonBigNode).forEach(features::add); new GeoJsonBuilder().create(features).save(writableResource); }
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); }
@Override public GeoJsonObject convert(final Atlas atlas) { return new GeoJsonBuilder() .create(Iterables.translate(new ComplexTurnRestrictionFinder().find(atlas), turnRestriction -> turnRestriction.getTurnRestriction().asGeoJson())); } }
/** * @param diffs * An {@link Iterable} of {@link Diff} * @param filter * The filter to apply to the diff * @return A GeoJSON String representation of all the {@link Diff} items in the {@link Iterable} * , which match the filter. */ public static String toGeoJson(final Iterable<Diff> diffs, final Predicate<Diff> filter) { return new GeoJsonBuilder().create( Iterables.stream(diffs).filter(diff -> diff.getItemType() != ItemType.RELATION) .filter(filter).flatMap(Diff::processDiff).collect()) .jsonObject().toString(); }
public void saveAsGeoJson(final WritableResource resource) { final JsonWriter writer = new JsonWriter(resource); final GeoJsonObject geoJson = new GeoJsonBuilder().create(Iterables .translate(this.root.leafNodes(Rectangle.MAXIMUM), Node::toGeoJsonBuildingBlock)); writer.write(geoJson.jsonObject()); writer.close(); }
@Test public void testMultiLineString() { final List<PolyLine> polyLines = new ArrayList<>(); polyLines.add(new PolyLine(Location.TEST_5, Location.TEST_2)); polyLines.add(new PolyLine(Location.COLOSSEUM, Location.EIFFEL_TOWER)); final GeoJsonObject object = new GeoJsonBuilder().createMultiLineStrings(polyLines); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiLineString\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628]],[[12.49234,41.890224],[2.294495,48.858241]]]}}", object.toString()); }
@Test public void testMultiPolygon() { final List<Polygon> polygons = new ArrayList<>(); polygons.add(new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6)); polygons.add(new Polygon(Location.COLOSSEUM, Location.EIFFEL_TOWER, Location.TEST_7)); final GeoJsonObject object = new GeoJsonBuilder().createMultiPolygons(polygons); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-122.031007,37.390535],[-122.028464,37.321628],[-122.033948,37.32544],[-122.031007,37.390535]]],[[[12.49234,41.890224],[2.294495,48.858241],[-122.0304871,37.3314171],[12.49234,41.890224]]]]}}", object.toString()); }
@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()); }
@Test public void testGeometryCollectionFeatureSingularForm() { final Map<String, Object> properties = new HashMap<>(); final List<GeometryWithProperties> items = new ArrayList<>(); items.add(new GeometryWithProperties(Location.TEST_1, properties)); items.add(new GeometryWithProperties( new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6), properties)); items.add(new GeometryWithProperties(new PolyLine(Location.TEST_5, Location.TEST_2), properties)); final GeoJsonObject object = new GeoJsonBuilder().createGeometryCollectionFeature(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()); }
@Test public void testConsistency() { final Polygon polygon = new Polygon(Location.TEST_5, Location.TEST_2, Location.TEST_6); final GeoJsonObject object = new GeoJsonBuilder().create(polygon); final Map<String, String> properties = new HashMap<>(); properties.put("property", "value"); properties.put("property2", "value2"); object.withNewProperties(properties); // The GeoJsonReader reads Feature collections only object.makeFeatureCollection(); final GeoJsonReader reader = new GeoJsonReader(new StringResource(object.toString())); final PropertiesLocated item = reader.next(); Assert.assertEquals(polygon, item.getItem()); }
@Test public void testLocation() { final GeoJsonObject object = new GeoJsonBuilder().create(Location.TEST_5); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.031007,37.390535]}}", object.toString()); object.withNewProperty("property", "value"); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.031007,37.390535]},\"properties\":{\"property\":\"value\"}}", object.toString()); object.withNewProperty("property2", "value2"); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.031007,37.390535]},\"properties\":{\"property\":\"value\",\"property2\":\"value2\"}}", object.toString()); }
@Override protected int onRun(final CommandMap command) { final File folder = (File) command.get(INPUT_FOLDER); final Atlas atlas = loadAtlas(command); final File bigNodesFile = folder.child("improved.bigNodes.geojson"); final JsonWriter writer = new JsonWriter(bigNodesFile); writer.write(new GeoJsonBuilder().create( Iterables.translate(new BigNodeFinder().find(atlas), BigNode::asGeoJsonBigNode)) .jsonObject()); writer.close(); return 0; } }