Search in sources :

Example 1 with Geometry

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

the class GeoPoint method resetFromWKT.

private GeoPoint resetFromWKT(String value, boolean ignoreZValue) {
    Geometry geometry;
    try {
        geometry = new WellKnownText(false, new GeographyValidator(ignoreZValue)).fromWKT(value);
    } catch (Exception e) {
        throw new OpenSearchParseException("Invalid WKT format", e);
    }
    if (geometry.type() != ShapeType.POINT) {
        throw new OpenSearchParseException("[geo_point] supports only POINT among WKT primitives, " + "but found " + geometry.type());
    }
    Point point = (Point) geometry;
    return reset(point.getY(), point.getX());
}
Also used : Geometry(org.opensearch.geometry.Geometry) OpenSearchParseException(org.opensearch.OpenSearchParseException) GeographyValidator(org.opensearch.geometry.utils.GeographyValidator) LatLonPoint(org.apache.lucene.document.LatLonPoint) EffectivePoint(org.opensearch.common.geo.GeoUtils.EffectivePoint) Point(org.opensearch.geometry.Point) WellKnownText(org.opensearch.geometry.utils.WellKnownText) OpenSearchParseException(org.opensearch.OpenSearchParseException) IOException(java.io.IOException)

Example 2 with Geometry

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

the class GeoShapeParser method parseAndFormatObject.

@Override
public Object parseAndFormatObject(Object value, String format) {
    try (XContentParser parser = new MapXContentParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, Collections.singletonMap("dummy_field", value), XContentType.JSON)) {
        // start object
        parser.nextToken();
        // field name
        parser.nextToken();
        // field value
        parser.nextToken();
        GeometryFormat<Geometry> geometryFormat = geometryParser.geometryFormat(parser);
        if (geometryFormat.name().equals(format)) {
            return value;
        }
        Geometry geometry = geometryFormat.fromXContent(parser);
        return format(geometry, format);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
Also used : Geometry(org.opensearch.geometry.Geometry) MapXContentParser(org.opensearch.common.xcontent.support.MapXContentParser) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ParseException(java.text.ParseException) XContentParser(org.opensearch.common.xcontent.XContentParser) MapXContentParser(org.opensearch.common.xcontent.support.MapXContentParser)

Example 3 with Geometry

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

the class GeometryIndexerTests method testCollection.

public void testCollection() {
    assertEquals(GeometryCollection.EMPTY, indexer.prepareForIndexing(GeometryCollection.EMPTY));
    GeometryCollection<Geometry> collection = new GeometryCollection<>(Collections.singletonList(new Point(2, 1)));
    Geometry indexed = new Point(2, 1);
    assertEquals(indexed, indexer.prepareForIndexing(collection));
    collection = new GeometryCollection<>(Arrays.asList(new Point(2, 1), new Point(4, 3), new Line(new double[] { 160, 200 }, new double[] { 10, 20 })));
    indexed = new GeometryCollection<>(Arrays.asList(new Point(2, 1), new Point(4, 3), new MultiLine(Arrays.asList(new Line(new double[] { 160, 180 }, new double[] { 10, 15 }), new Line(new double[] { -180, -160 }, new double[] { 15, 20 })))));
    assertEquals(indexed, indexer.prepareForIndexing(collection));
}
Also used : Geometry(org.opensearch.geometry.Geometry) GeometryCollection(org.opensearch.geometry.GeometryCollection) MultiLine(org.opensearch.geometry.MultiLine) Line(org.opensearch.geometry.Line) MultiLine(org.opensearch.geometry.MultiLine) MultiPoint(org.opensearch.geometry.MultiPoint) Point(org.opensearch.geometry.Point)

Example 4 with Geometry

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

the class GeometryIndexerTests method testMultiPoint.

public void testMultiPoint() {
    MultiPoint multiPoint = MultiPoint.EMPTY;
    Geometry indexed = multiPoint;
    assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
    multiPoint = new MultiPoint(Collections.singletonList(new Point(2, 1)));
    indexed = new Point(2, 1);
    assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
    multiPoint = new MultiPoint(Arrays.asList(new Point(2, 1), new Point(4, 3)));
    indexed = multiPoint;
    assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
    multiPoint = new MultiPoint(Arrays.asList(new Point(2, 1, 10), new Point(4, 3, 10)));
    assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
}
Also used : MultiPoint(org.opensearch.geometry.MultiPoint) Geometry(org.opensearch.geometry.Geometry) MultiPoint(org.opensearch.geometry.MultiPoint) Point(org.opensearch.geometry.Point)

Example 5 with Geometry

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

the class GeometryIndexerTests method testPoint.

public void testPoint() {
    Point point = new Point(2, 1);
    Geometry indexed = point;
    assertEquals(indexed, indexer.prepareForIndexing(point));
    point = new Point(2, 1, 3);
    assertEquals(indexed, indexer.prepareForIndexing(point));
    point = new Point(362, 1);
    assertEquals(indexed, indexer.prepareForIndexing(point));
    point = new Point(-178, 179);
    assertEquals(indexed, indexer.prepareForIndexing(point));
    point = new Point(180, 180);
    assertEquals(new Point(0, 0), indexer.prepareForIndexing(point));
    point = new Point(-180, -180);
    assertEquals(new Point(0, 0), indexer.prepareForIndexing(point));
}
Also used : Geometry(org.opensearch.geometry.Geometry) MultiPoint(org.opensearch.geometry.MultiPoint) Point(org.opensearch.geometry.Point)

Aggregations

Geometry (org.opensearch.geometry.Geometry)28 MultiPoint (org.opensearch.geometry.MultiPoint)10 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)9 Point (org.opensearch.geometry.Point)9 Coordinate (org.locationtech.jts.geom.Coordinate)7 GeometryCollection (org.opensearch.geometry.GeometryCollection)7 Line (org.opensearch.geometry.Line)7 MultiLine (org.opensearch.geometry.MultiLine)7 ArrayList (java.util.ArrayList)6 XContentParser (org.opensearch.common.xcontent.XContentParser)6 IOException (java.io.IOException)5 GeometryCollectionBuilder (org.opensearch.common.geo.builders.GeometryCollectionBuilder)5 ParseException (java.text.ParseException)4 OpenSearchParseException (org.opensearch.OpenSearchParseException)4 Point (org.locationtech.jts.geom.Point)3 Shape (org.locationtech.spatial4j.shape.Shape)3 JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)3 SearchResponse (org.opensearch.action.search.SearchResponse)3 CoordinatesBuilder (org.opensearch.common.geo.builders.CoordinatesBuilder)3 MultiPolygonBuilder (org.opensearch.common.geo.builders.MultiPolygonBuilder)3