Search in sources :

Example 1 with ShapeType

use of org.opensearch.geometry.ShapeType in project OpenSearch by opensearch-project.

the class GeoJson method createGeometry.

private static Geometry createGeometry(String type, List<Geometry> geometries, CoordinateNode coordinates, Boolean orientation, boolean defaultOrientation, boolean coerce, DistanceUnit.Distance radius) {
    ShapeType shapeType;
    if ("bbox".equalsIgnoreCase(type)) {
        shapeType = ShapeType.ENVELOPE;
    } else {
        shapeType = ShapeType.forName(type);
    }
    if (shapeType == ShapeType.GEOMETRYCOLLECTION) {
        if (geometries == null) {
            throw new OpenSearchParseException("geometries not included");
        }
        if (coordinates != null) {
            throw new OpenSearchParseException("parameter coordinates is not supported for type " + type);
        }
        verifyNulls(type, null, orientation, radius);
        return new GeometryCollection<>(geometries);
    }
    // We expect to have coordinates for all the rest
    if (coordinates == null) {
        throw new OpenSearchParseException("coordinates not included");
    }
    switch(shapeType) {
        case CIRCLE:
            if (radius == null) {
                throw new OpenSearchParseException("radius is not specified");
            }
            verifyNulls(type, geometries, orientation, null);
            Point point = coordinates.asPoint();
            return new Circle(point.getX(), point.getY(), point.getZ(), radius.convert(DistanceUnit.METERS).value);
        case POINT:
            verifyNulls(type, geometries, orientation, radius);
            return coordinates.asPoint();
        case MULTIPOINT:
            verifyNulls(type, geometries, orientation, radius);
            return coordinates.asMultiPoint();
        case LINESTRING:
            verifyNulls(type, geometries, orientation, radius);
            return coordinates.asLineString(coerce);
        case MULTILINESTRING:
            verifyNulls(type, geometries, orientation, radius);
            return coordinates.asMultiLineString(coerce);
        case POLYGON:
            verifyNulls(type, geometries, null, radius);
            // handle possible null in orientation
            return coordinates.asPolygon(orientation != null ? orientation : defaultOrientation, coerce);
        case MULTIPOLYGON:
            verifyNulls(type, geometries, null, radius);
            // handle possible null in orientation
            return coordinates.asMultiPolygon(orientation != null ? orientation : defaultOrientation, coerce);
        case ENVELOPE:
            verifyNulls(type, geometries, orientation, radius);
            return coordinates.asRectangle();
        default:
            throw new OpenSearchParseException("unsupported shape type " + type);
    }
}
Also used : GeometryCollection(org.opensearch.geometry.GeometryCollection) Circle(org.opensearch.geometry.Circle) OpenSearchParseException(org.opensearch.OpenSearchParseException) ShapeType(org.opensearch.geometry.ShapeType) MultiPoint(org.opensearch.geometry.MultiPoint) Point(org.opensearch.geometry.Point)

Aggregations

OpenSearchParseException (org.opensearch.OpenSearchParseException)1 Circle (org.opensearch.geometry.Circle)1 GeometryCollection (org.opensearch.geometry.GeometryCollection)1 MultiPoint (org.opensearch.geometry.MultiPoint)1 Point (org.opensearch.geometry.Point)1 ShapeType (org.opensearch.geometry.ShapeType)1