com.github.filosganga.geogson.jts.JtsPolygonIterable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geogson-jts Show documentation
Show all versions of geogson-jts Show documentation
GeoJSON support for Google Gson - JTS
package com.github.filosganga.geogson.jts;
import com.google.common.collect.UnmodifiableIterator;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Polygon;
/**
* @author Filippo De Luca - [email protected]
*/
class JtsPolygonIterable implements Iterable {
private final PolygonProvider src;
private JtsPolygonIterable(PolygonProvider src) {
this.src = src;
}
public static JtsPolygonIterable of(final MultiPolygon src) {
return new JtsPolygonIterable(new PolygonProvider() {
@Override
public int getNumPolygons() {
return src.getNumGeometries();
}
@Override
public Polygon getPolygonN(int n) {
return (Polygon) src.getGeometryN(n);
}
});
}
@Override
public UnmodifiableIterator iterator() {
return new Iterator(src);
}
private static class Iterator extends UnmodifiableIterator {
private final PolygonProvider src;
private int index = 0;
private Iterator(PolygonProvider src) {
this.src = src;
}
@Override
public boolean hasNext() {
return src.getNumPolygons() > index;
}
@Override
public Polygon next() {
return src.getPolygonN(index++);
}
}
private interface PolygonProvider {
int getNumPolygons();
Polygon getPolygonN(int n);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy