use of org.locationtech.jts.io.geojson.GeoJsonWriter in project dhis2-core by dhis2.
the class CoordinateUtils method getCoordinatesFromGeometry.
public static String getCoordinatesFromGeometry(Geometry geometry) {
String coordinatesKey = "\"coordinates\":";
String crsKey = ",\"crs\":";
GeoJsonWriter gjw = new GeoJsonWriter();
String geojson = gjw.write(geometry).trim();
return geojson.substring(geojson.indexOf(coordinatesKey) + coordinatesKey.length(), geojson.indexOf(crsKey));
}
use of org.locationtech.jts.io.geojson.GeoJsonWriter in project jts by locationtech.
the class GeoJsonTest method setUp.
@Override
public void setUp() throws Exception {
this.geoJsonWriter = new GeoJsonWriter();
this.geoJsonReader = new GeoJsonReader();
}
use of org.locationtech.jts.io.geojson.GeoJsonWriter in project jts by locationtech.
the class GeometryOutput method writeGeoJSON.
private static String writeGeoJSON(Geometry geom) {
GeoJsonWriter writer = new GeoJsonWriter();
writer.setEncodeCRS(false);
return writer.write(geom);
}
use of org.locationtech.jts.io.geojson.GeoJsonWriter in project ARLAS-server by gisaia.
the class GeoTypeMapper method getGeoJsonObject.
public static GeoJsonObject getGeoJsonObject(Object elasticsearchGeoField, GeoTypeEnum type) throws ArlasException {
GeoJsonObject geoObject = null;
String parseExceptionMsg = "Unable to parse " + elasticsearchGeoField.toString() + "as valid " + type;
String loggerMsg = "Unable to parse " + elasticsearchGeoField.toString() + "as valid " + type + " from " + elasticsearchGeoField.getClass();
switch(type) {
case GEOPOINT_AS_STRING:
case GEOHASH:
try {
GeoPoint geoPoint = new GeoPoint(elasticsearchGeoField.toString());
geoObject = new Point(geoPoint.getLon(), geoPoint.getLat());
} catch (Exception e) {
LOGGER.error(loggerMsg, e);
throw new ParseException(parseExceptionMsg);
}
break;
case GEOPOINT_AS_ARRAY:
try {
geoObject = new Point(((Number) ((ArrayList) elasticsearchGeoField).get(0)).doubleValue(), ((Number) ((ArrayList) elasticsearchGeoField).get(1)).doubleValue());
} catch (Exception e) {
LOGGER.error(loggerMsg, e);
throw new ParseException(parseExceptionMsg);
}
break;
case GEOHASH_ARRAY:
try {
List geohashes = (ArrayList) elasticsearchGeoField;
int middleIndex = (geohashes.size() / 2);
GeoPoint geoPoint = new GeoPoint(geohashes.get(middleIndex).toString());
geoObject = new Point(geoPoint.getLon(), geoPoint.getLat());
} catch (Exception e) {
LOGGER.error(loggerMsg, e);
throw new ParseException(parseExceptionMsg);
}
break;
case GEOPOINT:
try {
geoObject = new Point(((Number) ((HashMap) elasticsearchGeoField).get("lon")).doubleValue(), ((Number) ((HashMap) elasticsearchGeoField).get("lat")).doubleValue());
} catch (Exception e) {
LOGGER.error(loggerMsg, e);
throw new ParseException(parseExceptionMsg);
}
break;
case GEOJSON:
// Standard GeoJSON object
try {
geoObject = reader.readValue(mapper.writer().writeValueAsString(elasticsearchGeoField));
} catch (IOException e) {
LOGGER.error(loggerMsg, e);
throw new ParseException(parseExceptionMsg);
}
break;
case WKT:
try {
GeoJsonWriter geoJsonWriter = new GeoJsonWriter();
Geometry g = GeoUtil.readWKT(elasticsearchGeoField.toString());
geoObject = reader.readValue(geoJsonWriter.write(g));
} catch (IOException e) {
LOGGER.error(loggerMsg, e);
throw new ParseException(parseExceptionMsg);
}
break;
}
return geoObject;
}
Aggregations