Search in sources :

Example 16 with Point

use of org.opensearch.geometry.Point 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)

Example 17 with Point

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

the class GeoJsonParserTests method testParseGeometryCollection.

@Override
public void testParseGeometryCollection() throws IOException {
    XContentBuilder geometryCollectionGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "GeometryCollection").startArray("geometries").startObject().field("type", "LineString").startArray("coordinates").startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().endArray().endObject().startObject().field("type", "Point").startArray("coordinates").value(102.0).value(2.0).endArray().endObject().startObject().field("type", "Polygon").startArray("coordinates").startArray().startArray().value(-177.0).value(10.0).endArray().startArray().value(176.0).value(15.0).endArray().startArray().value(172.0).value(0.0).endArray().startArray().value(176.0).value(-15.0).endArray().startArray().value(-177.0).value(-10.0).endArray().startArray().value(-177.0).value(10.0).endArray().endArray().endArray().endObject().endArray().endObject();
    GeometryCollection<Geometry> geometryExpected = new GeometryCollection<>(Arrays.asList(new Line(new double[] { 100d, 101d }, new double[] { 0d, 1d }), new Point(102d, 2d), new Polygon(new LinearRing(new double[] { -177, 176, 172, 176, -177, -177 }, new double[] { 10, 15, 0, -15, -10, 10 }))));
    assertGeometryEquals(geometryExpected, geometryCollectionGeoJson);
}
Also used : Geometry(org.opensearch.geometry.Geometry) GeometryCollection(org.opensearch.geometry.GeometryCollection) Line(org.opensearch.geometry.Line) MultiLine(org.opensearch.geometry.MultiLine) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint) Polygon(org.opensearch.geometry.Polygon) MultiPolygon(org.opensearch.geometry.MultiPolygon) LinearRing(org.opensearch.geometry.LinearRing) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 18 with Point

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

the class GeoJsonParserTests method testParseMultiPoint.

@Override
public void testParseMultiPoint() throws IOException {
    XContentBuilder multiPointGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "MultiPoint").startArray("coordinates").startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().endArray().endObject();
    assertGeometryEquals(new MultiPoint(Arrays.asList(new Point(100, 0), new Point(101, 1))), multiPointGeoJson);
}
Also used : MultiPoint(org.opensearch.geometry.MultiPoint) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 19 with Point

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

the class GeoPointShapeQueryTests method testQueryPoint.

public void testQueryPoint() throws Exception {
    XContentBuilder xcb = createDefaultMapping();
    client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get();
    ensureGreen();
    PointBuilder pb = new PointBuilder().coordinate(-35, -25);
    Point point = pb.buildGeometry();
    try {
        client().prepareSearch("test").setQuery(QueryBuilders.geoShapeQuery(defaultGeoFieldName, point)).get();
    } catch (Exception e) {
        assertThat(e.getCause().getMessage(), containsString("does not support " + GeoShapeType.POINT + " queries"));
    }
}
Also used : MultiPointBuilder(org.opensearch.common.geo.builders.MultiPointBuilder) PointBuilder(org.opensearch.common.geo.builders.PointBuilder) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException)

Example 20 with Point

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

the class GeometryTestUtils method randomMultiPoint.

public static MultiPoint randomMultiPoint(boolean hasAlt) {
    int size = OpenSearchTestCase.randomIntBetween(3, 10);
    List<Point> points = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        points.add(randomPoint(hasAlt));
    }
    return new MultiPoint(points);
}
Also used : MultiPoint(org.opensearch.geometry.MultiPoint) ArrayList(java.util.ArrayList) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint)

Aggregations

Point (org.opensearch.geometry.Point)34 MultiPoint (org.opensearch.geometry.MultiPoint)14 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)9 ArrayList (java.util.ArrayList)6 Geometry (org.opensearch.geometry.Geometry)5 IOException (java.io.IOException)4 InvalidShapeException (org.locationtech.spatial4j.exception.InvalidShapeException)4 XContentParser (org.opensearch.common.xcontent.XContentParser)4 Line (org.opensearch.geometry.Line)4 LinearRing (org.opensearch.geometry.LinearRing)4 Polygon (org.opensearch.geometry.Polygon)4 OpenSearchParseException (org.opensearch.OpenSearchParseException)3 GeometryCollection (org.opensearch.geometry.GeometryCollection)3 PointBuilder (org.opensearch.common.geo.builders.PointBuilder)2 MultiLine (org.opensearch.geometry.MultiLine)2 ParseException (java.text.ParseException)1 Collection (java.util.Collection)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1