Search in sources :

Example 1 with JtsSpatialContextFactory

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;
}
Also used : ShapeFactory(org.locationtech.spatial4j.shape.ShapeFactory) JtsShapeFactory(org.locationtech.spatial4j.shape.jts.JtsShapeFactory) JtsShapeFactory(org.locationtech.spatial4j.shape.jts.JtsShapeFactory) JtsSpatialContextFactory(org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory)

Example 2 with JtsSpatialContextFactory

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;
}
Also used : SpatialContext(org.locationtech.spatial4j.context.SpatialContext) Shape(org.locationtech.spatial4j.shape.Shape) Point(org.locationtech.spatial4j.shape.Point) SpatialContext(org.locationtech.spatial4j.context.SpatialContext) JtsSpatialContextFactory(org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory)

Aggregations

JtsSpatialContextFactory (org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory)2 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)1 Point (org.locationtech.spatial4j.shape.Point)1 Shape (org.locationtech.spatial4j.shape.Shape)1 ShapeFactory (org.locationtech.spatial4j.shape.ShapeFactory)1 JtsShapeFactory (org.locationtech.spatial4j.shape.jts.JtsShapeFactory)1