]>
git.argeo.org Git - gpl/argeo-suite.git/blob - org.argeo.app.geo/src/org/argeo/app/geo/GeoShapeUtils.java
1 package org
.argeo
.app
.geo
;
3 import org
.locationtech
.jts
.geom
.Coordinate
;
4 import org
.locationtech
.jts
.geom
.Geometry
;
5 import org
.locationtech
.jts
.geom
.LineString
;
6 import org
.locationtech
.jts
.geom
.Point
;
7 import org
.locationtech
.jts
.geom
.Polygon
;
9 /** Utilities around ODK's GeoShape format */
10 public class GeoShapeUtils
{
12 /** Converts a {@link Geometry} with WGS84 coordinates to a GeoShape. */
13 public static String
geometryToGeoShape(Geometry geometry
) {
14 if (geometry
instanceof Point point
) {
15 Coordinate coordinate
= point
.getCoordinate();
16 StringBuilder sb
= new StringBuilder();
17 appendToGeoShape(sb
, coordinate
.getX(), coordinate
.getY(), coordinate
.getZ());
19 } else if (geometry
instanceof Polygon
|| geometry
instanceof LineString
) {
20 StringBuilder sb
= new StringBuilder();
21 for (Coordinate coordinate
: geometry
.getCoordinates()) {
22 appendToGeoShape(sb
, coordinate
.getX(), coordinate
.getY(), coordinate
.getZ());
27 throw new IllegalArgumentException("Unsupported geometry " + geometry
.getClass());
31 public static String
geoPointToGeoShape(double lon
, double lat
, double alt
) {
32 StringBuilder sb
= new StringBuilder();
33 appendToGeoShape(sb
, lon
, lat
, alt
);
37 private static void appendToGeoShape(StringBuilder sb
, double lon
, double lat
, double alt
) {
38 sb
.append(lat
).append(' ');
39 sb
.append(lon
).append(' ');
40 if (alt
!= Double
.NaN
)
41 sb
.append(alt
).append(' ');
48 private GeoShapeUtils() {