com.github.filosganga.geogson.jts.JtsPointIterable 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.LineString;
import com.vividsolutions.jts.geom.MultiPoint;
import com.vividsolutions.jts.geom.Point;
/**
* @author Filippo De Luca - [email protected]
*/
class JtsPointIterable implements Iterable {
private final PointProvider src;
private JtsPointIterable(PointProvider src) {
this.src = src;
}
public static JtsPointIterable of(final LineString src) {
return new JtsPointIterable(new PointProvider() {
@Override
public int getNumPoints() {
return src.getNumPoints();
}
@Override
public Point getPointN(int n) {
return src.getPointN(n);
}
});
}
public static JtsPointIterable of(final MultiPoint src) {
return new JtsPointIterable(new PointProvider() {
@Override
public int getNumPoints() {
return src.getNumGeometries();
}
@Override
public Point getPointN(int n) {
return (Point) src.getGeometryN(n);
}
});
}
@Override
public UnmodifiableIterator iterator() {
return new JtsPointIterator(src);
}
private class JtsPointIterator extends UnmodifiableIterator {
private final PointProvider src;
private int index = 0;
private JtsPointIterator(PointProvider src) {
this.src = src;
}
@Override
public boolean hasNext() {
return src.getNumPoints() > index;
}
@Override
public Point next() {
return src.getPointN(index++);
}
}
private interface PointProvider {
int getNumPoints();
Point getPointN(int n);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy