X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.geo%2Fsrc%2Forg%2Fargeo%2Fapp%2Fgeo%2FGpxUtils.java;h=5b07d1677fe72166ae9329327062812ddf35b37b;hb=b96d17f3eb275a97109cc160db1cfd3731a01d31;hp=2bcff158712a38eb5a32059ea2a48fcf2e2ddc1f;hpb=8b7dc8398a17d09c5e20857b4e1e5f82ad28e769;p=gpl%2Fargeo-suite.git diff --git a/org.argeo.app.geo/src/org/argeo/app/geo/GpxUtils.java b/org.argeo.app.geo/src/org/argeo/app/geo/GpxUtils.java index 2bcff15..5b07d16 100644 --- a/org.argeo.app.geo/src/org/argeo/app/geo/GpxUtils.java +++ b/org.argeo.app.geo/src/org/argeo/app/geo/GpxUtils.java @@ -22,6 +22,7 @@ import org.locationtech.jts.geom.Coordinate; 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; @@ -52,7 +53,7 @@ public class GpxUtils { */ @SuppressWarnings("unchecked") public static T parseGpxTrackTo(InputStream in, Class clss) throws IOException { - GeometryFactory geometryFactory = JTS.GEOMETRY_FACTORY; + GeometryFactory geometryFactory = JTS.GEOMETRY_FACTORY_WGS84; List coordinates = new ArrayList<>(); try { SAXParserFactory factory = SAXParserFactory.newInstance(); @@ -81,14 +82,17 @@ public class GpxUtils { 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()])); @@ -99,7 +103,7 @@ public class GpxUtils { throw new IllegalArgumentException("Unsupported format " + clss); } } - + /** @deprecated Use {@link #parseGpxTrackTo(InputStream, Class)} instead. */ @Deprecated public static SimpleFeature parseGpxToPolygon(InputStream in) throws IOException {