use of org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory in project traccar by tananaev.
the class GeofencePolygon method calculateArea.
@Override
public double calculateArea() {
JtsShapeFactory jtsShapeFactory = new JtsSpatialContextFactory().newSpatialContext().getShapeFactory();
ShapeFactory.PolygonBuilder polygonBuilder = jtsShapeFactory.polygon();
for (Coordinate coordinate : coordinates) {
polygonBuilder.pointXY(coordinate.getLon(), coordinate.getLat());
}
return polygonBuilder.build().getArea(SpatialContext.GEO) * DEG_TO_KM * DEG_TO_KM;
}
use of org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory in project ddf by codice.
the class GeoNamesWebService method createPointFromWkt.
Point createPointFromWkt(String wkt) {
try {
JtsSpatialContextFactory contextFactory = new JtsSpatialContextFactory();
contextFactory.allowMultiOverlap = true;
SpatialContext spatialContext = contextFactory.newSpatialContext();
Shape shape = (Shape) spatialContext.readShapeFromWkt(wkt);
Point center = shape.getCenter();
return center;
} catch (java.text.ParseException parseException) {
LOGGER.debug(parseException.getMessage(), parseException);
}
return null;
}
Aggregations