org.openstreetmap.atlas.geography.converters.jts.GeometryStreamer 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.converters.jts;
import java.util.Iterator;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryCollection;
import org.locationtech.jts.geom.Polygon;
import org.openstreetmap.atlas.utilities.collections.Iterables;
/**
* Transform a JTS {@link GeometryCollection} into a real {@link Iterable}.
*
* @author matthieun
*/
public final class GeometryStreamer
{
/**
* @param collection
* The collection to stream
* @return The JTS {@link Geometry} {@link Iterable}
*/
public static Iterable stream(final GeometryCollection collection)
{
final int size = collection.getNumGeometries();
return () -> new Iterator()
{
private int index = 0;
@Override
public boolean hasNext()
{
return this.index < size;
}
@Override
public Geometry next()
{
return collection.getGeometryN(this.index++);
}
};
}
/**
* @param collection
* The collection to stream
* @return The JTS {@link Geometry} {@link Iterable} as JTS {@link Polygon}s
*/
public static Iterable streamPolygons(final GeometryCollection collection)
{
return Iterables.translate(stream(collection), geometry -> (Polygon) geometry);
}
private GeometryStreamer()
{
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy