import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import org.geotools.api.feature.simple.SimpleFeature;
+import org.geotools.api.feature.simple.SimpleFeatureType;
import org.geotools.data.DataUtilities;
import org.geotools.feature.SchemaException;
import org.geotools.feature.simple.SimpleFeatureBuilder;
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.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
// multiPoint.normalize();
return (T) multiPoint;
} 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;
} else if (SimpleFeature.class.isAssignableFrom(clss)) {
return area;
}
- /** Write ODK GepShape as a GPX file. */
+ /** Write ODK GeoShape 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);