org.openstreetmap.atlas.geography.geojson.GeoJsonSaver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atlas Show documentation
Show all versions of atlas Show documentation
"Library to load OSM data into an Atlas format"
package org.openstreetmap.atlas.geography.geojson;
import org.openstreetmap.atlas.geography.Location;
import org.openstreetmap.atlas.geography.MultiPolygon;
import org.openstreetmap.atlas.geography.Polygon;
import org.openstreetmap.atlas.streaming.resource.WritableResource;
import org.openstreetmap.atlas.streaming.writers.JsonWriter;
import org.openstreetmap.atlas.utilities.collections.Iterables;
import org.openstreetmap.atlas.utilities.collections.Maps;
import org.openstreetmap.atlas.utilities.collections.MultiIterable;
/**
* Save some geometry items to a resource, as GeoJson
*
* @author matthieun
*/
public final class GeoJsonSaver
{
public static void save(final Iterable extends Iterable> geometries,
final WritableResource destination)
{
final GeoJsonObject object = new GeoJsonBuilder().create(Iterables.translate(geometries,
polyLine -> new GeoJsonBuilder.LocationIterableProperties(polyLine,
Maps.hashMap())));
save(object, destination);
}
public static void saveMultipolygon(final Iterable geometries,
final WritableResource destination)
{
final Iterable outers = Iterables.translateMulti(geometries,
multiPolygon -> multiPolygon.outers());
final Iterable inners = Iterables.translateMulti(geometries,
multiPolygon -> multiPolygon.inners());
final Iterable multi = new MultiIterable<>(outers, inners);
save(multi, destination);
}
private static void save(final GeoJsonObject object, final WritableResource destination)
{
final JsonWriter writer = new JsonWriter(destination);
writer.write(object.jsonObject());
writer.close();
}
private GeoJsonSaver()
{
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy