projects
/
gpl
/
argeo-suite.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
GeoShape to Geometry
[gpl/argeo-suite.git]
/
org.argeo.app.geo
/
src
/
org
/
argeo
/
app
/
geo
/
GpxUtils.java
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 15f6b89675e5a03cf16bc03882271baa36ce6f5b..2a946f48ac29998bc413187d421e5dde09a445f2 100644
(file)
--- 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.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;
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> T parseGpxTrackTo(InputStream in, Class<T> clss) throws IOException {
*/
@SuppressWarnings("unchecked")
public static <T> T parseGpxTrackTo(InputStream in, Class<T> clss) throws IOException {
- GeometryFactory geometryFactory =
GeoTools.GEOMETRY_FACTORY
;
+ GeometryFactory geometryFactory =
JTS.GEOMETRY_FACTORY_WGS84
;
List<Coordinate> coordinates = new ArrayList<>();
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
List<Coordinate> coordinates = new ArrayList<>();
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
@@
-81,14
+82,21
@@
public class GpxUtils {
LineString lineString = geometryFactory
.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
return (T) lineString;
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)) {
} else if (Polygon.class.isAssignableFrom(clss)) {
- // close the line string
- coordinates.add(coordinates.get(0));
+ Coordinate first = coordinates.get(0);
+ Coordinate last = coordinates.get(coordinates.size() - 1);
+ if (!(first.getX() == last.getX() && first.getY() == last.getY())) {
+ // close the line string
+ coordinates.add(first);
+ }
Polygon polygon = geometryFactory.createPolygon(coordinates.toArray(new Coordinate[coordinates.size()]));
return (T) polygon;
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()]));
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(LINESTRING_FEATURE_TYPE);
LineString lineString = geometryFactory
.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
@@
-99,7
+107,7
@@
public class GpxUtils {
throw new IllegalArgumentException("Unsupported format " + clss);
}
}
throw new IllegalArgumentException("Unsupported format " + clss);
}
}
-
+
/** @deprecated Use {@link #parseGpxTrackTo(InputStream, Class)} instead. */
@Deprecated
public static SimpleFeature parseGpxToPolygon(InputStream in) throws IOException {
/** @deprecated Use {@link #parseGpxTrackTo(InputStream, Class)} instead. */
@Deprecated
public static SimpleFeature parseGpxToPolygon(InputStream in) throws IOException {
@@
-110,7
+118,7
@@
public class GpxUtils {
return area;
}
return area;
}
- /** Write ODK Ge
p
Shape as a GPX file. */
+ /** Write ODK Ge
o
Shape as a GPX file. */
public static void writeGeoShapeAsGpx(String geoShape, OutputStream out) throws IOException {
Objects.requireNonNull(geoShape);
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
public static void writeGeoShapeAsGpx(String geoShape, OutputStream out) throws IOException {
Objects.requireNonNull(geoShape);
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);