import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
+import org.locationtech.jts.geom.MultiPoint;
import org.locationtech.jts.geom.Polygon;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
*/
@SuppressWarnings("unchecked")
public static <T> T parseGpxTrackTo(InputStream in, Class<T> clss) throws IOException {
- GeometryFactory geometryFactory = JTS.GEOMETRY_FACTORY;
+ GeometryFactory geometryFactory = JTS.GEOMETRY_FACTORY_WGS84;
List<Coordinate> coordinates = new ArrayList<>();
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
LineString lineString = geometryFactory
.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
return (T) lineString;
+ } else if (MultiPoint.class.isAssignableFrom(clss)) {
+ MultiPoint multiPoint = geometryFactory
+ .createMultiPointFromCoords(coordinates.toArray(new Coordinate[coordinates.size()]));
+ // multiPoint.normalize();
+ return (T) multiPoint;
} else if (Polygon.class.isAssignableFrom(clss)) {
// close the line string
coordinates.add(coordinates.get(0));
Polygon polygon = geometryFactory.createPolygon(coordinates.toArray(new Coordinate[coordinates.size()]));
return (T) polygon;
- }
- // TODO MultiPoint? MultiLine? etc.
- else if (SimpleFeature.class.isAssignableFrom(clss)) {
+ } else if (SimpleFeature.class.isAssignableFrom(clss)) {
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(LINESTRING_FEATURE_TYPE);
LineString lineString = geometryFactory
.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
throw new IllegalArgumentException("Unsupported format " + clss);
}
}
-
+
/** @deprecated Use {@link #parseGpxTrackTo(InputStream, Class)} instead. */
@Deprecated
public static SimpleFeature parseGpxToPolygon(InputStream in) throws IOException {