Search in sources :

Example 16 with Line

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

the class GeometryIndexerTests method testLine.

public void testLine() {
    Line line = new Line(new double[] { 3, 4 }, new double[] { 1, 2 });
    Geometry indexed = line;
    assertEquals(indexed, indexer.prepareForIndexing(line));
    line = new Line(new double[] { 160, 200 }, new double[] { 10, 20 });
    indexed = 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(line));
    line = new Line(new double[] { 200, 160 }, new double[] { 10, 20 });
    indexed = 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(line));
    line = new Line(new double[] { 160, 200, 160 }, new double[] { 0, 10, 20 });
    indexed = new MultiLine(Arrays.asList(new Line(new double[] { 160, 180 }, new double[] { 0, 5 }), new Line(new double[] { -180, -160, -180 }, new double[] { 5, 10, 15 }), new Line(new double[] { 180, 160 }, new double[] { 15, 20 })));
    assertEquals(indexed, indexer.prepareForIndexing(line));
    line = new Line(new double[] { 0, 720 }, new double[] { 0, 20 });
    indexed = new MultiLine(Arrays.asList(new Line(new double[] { 0, 180 }, new double[] { 0, 5 }), new Line(new double[] { -180, 180 }, new double[] { 5, 15 }), new Line(new double[] { -180, 0 }, new double[] { 15, 20 })));
    assertEquals(indexed, indexer.prepareForIndexing(line));
    line = new Line(new double[] { 160, 180, 180, 200, 160, 140 }, new double[] { 0, 10, 20, 30, 30, 40 });
    indexed = new MultiLine(Arrays.asList(new Line(new double[] { 160, 180 }, new double[] { 0, 10 }), new Line(new double[] { -180, -180, -160, -180 }, new double[] { 10, 20, 30, 30 }), new Line(new double[] { 180, 160, 140 }, new double[] { 30, 30, 40 })));
    assertEquals(indexed, indexer.prepareForIndexing(line));
    line = new Line(new double[] { -70, 180, 900 }, new double[] { 0, 0, 4 });
    indexed = new MultiLine(Arrays.asList(new Line(new double[] { -70, 180 }, new double[] { 0, 0 }), new Line(new double[] { -180, 180 }, new double[] { 0, 2 }), new Line(new double[] { -180, 180 }, new double[] { 2, 4 })));
    assertEquals(indexed, indexer.prepareForIndexing(line));
    line = new Line(new double[] { 160, 200, 160, 200, 160, 200 }, new double[] { 0, 10, 20, 30, 40, 50 });
    indexed = new MultiLine(Arrays.asList(new Line(new double[] { 160, 180 }, new double[] { 0, 5 }), new Line(new double[] { -180, -160, -180 }, new double[] { 5, 10, 15 }), new Line(new double[] { 180, 160, 180 }, new double[] { 15, 20, 25 }), new Line(new double[] { -180, -160, -180 }, new double[] { 25, 30, 35 }), new Line(new double[] { 180, 160, 180 }, new double[] { 35, 40, 45 }), new Line(new double[] { -180, -160 }, new double[] { 45, 50 })));
    assertEquals(indexed, indexer.prepareForIndexing(line));
}
Also used : MultiLine(org.opensearch.geometry.MultiLine) Line(org.opensearch.geometry.Line) Geometry(org.opensearch.geometry.Geometry) MultiLine(org.opensearch.geometry.MultiLine)

Example 17 with Line

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

the class GeometryIO method readMultiLine.

private static MultiLine readMultiLine(StreamInput in) throws IOException {
    int size = in.readVInt();
    List<Line> lines = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        lines.add(readLine(in));
    }
    return new MultiLine(lines);
}
Also used : Line(org.opensearch.geometry.Line) MultiLine(org.opensearch.geometry.MultiLine) MultiLine(org.opensearch.geometry.MultiLine) ArrayList(java.util.ArrayList) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint)

Example 18 with Line

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

the class GeoPointShapeQueryTests method testQueryLine.

public void testQueryLine() throws Exception {
    XContentBuilder xcb = createDefaultMapping();
    client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get();
    ensureGreen();
    Line line = new Line(new double[] { -25, -25 }, new double[] { -35, -35 });
    try {
        client().prepareSearch("test").setQuery(QueryBuilders.geoShapeQuery(defaultGeoFieldName, line)).get();
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.getCause().getMessage(), containsString("does not support " + GeoShapeType.LINESTRING + " queries"));
    }
}
Also used : Line(org.opensearch.geometry.Line) MultiLine(org.opensearch.geometry.MultiLine) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 19 with Line

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

the class GeometryTestUtils method randomLine.

public static Line randomLine(boolean hasAlts) {
    // we use nextPolygon because it guarantees no duplicate points
    org.apache.lucene.geo.Polygon lucenePolygon = GeoTestUtil.nextPolygon();
    int size = lucenePolygon.numPoints() - 1;
    double[] lats = new double[size];
    double[] lons = new double[size];
    double[] alts = hasAlts ? new double[size] : null;
    for (int i = 0; i < size; i++) {
        lats[i] = lucenePolygon.getPolyLat(i);
        lons[i] = lucenePolygon.getPolyLon(i);
        if (hasAlts) {
            alts[i] = randomAlt();
        }
    }
    if (hasAlts) {
        return new Line(lons, lats, alts);
    }
    return new Line(lons, lats);
}
Also used : Line(org.opensearch.geometry.Line) MultiLine(org.opensearch.geometry.MultiLine) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint)

Aggregations

Line (org.opensearch.geometry.Line)19 MultiLine (org.opensearch.geometry.MultiLine)17 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)9 MultiPoint (org.opensearch.geometry.MultiPoint)9 Point (org.opensearch.geometry.Point)8 Geometry (org.opensearch.geometry.Geometry)7 ArrayList (java.util.ArrayList)5 Coordinate (org.locationtech.jts.geom.Coordinate)5 LineString (org.locationtech.jts.geom.LineString)4 MultiLineString (org.locationtech.jts.geom.MultiLineString)4 Point (org.locationtech.jts.geom.Point)3 JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)3 GeometryCollection (org.opensearch.geometry.GeometryCollection)3 IOException (java.io.IOException)2 List (java.util.List)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 Polygon (org.locationtech.jts.geom.Polygon)2 Shape (org.locationtech.spatial4j.shape.Shape)2 LineStringBuilder (org.opensearch.common.geo.builders.LineStringBuilder)2 MultiLineStringBuilder (org.opensearch.common.geo.builders.MultiLineStringBuilder)2