Search in sources :

Example 11 with Line

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

the class GeoJsonParserTests method testParseMultiLineString.

@Override
public void testParseMultiLineString() throws IOException {
    XContentBuilder multilinesGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "MultiLineString").startArray("coordinates").startArray().startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().endArray().startArray().startArray().value(102.0).value(2.0).endArray().startArray().value(103.0).value(3.0).endArray().endArray().endArray().endObject();
    MultiLine expected = new MultiLine(Arrays.asList(new Line(new double[] { 100.0, 101.0 }, new double[] { 0.0, 1.0 }), new Line(new double[] { 102.0, 103.0 }, new double[] { 2.0, 3.0 })));
    assertGeometryEquals(expected, multilinesGeoJson);
}
Also used : MultiLine(org.opensearch.geometry.MultiLine) Line(org.opensearch.geometry.Line) MultiLine(org.opensearch.geometry.MultiLine) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 12 with Line

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

the class GeoJsonParserTests method testParseLineString.

@Override
public void testParseLineString() throws IOException {
    XContentBuilder lineGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "LineString").startArray("coordinates").startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().endArray().endObject();
    Line expected = new Line(new double[] { 100.0, 101.0 }, new double[] { 0.0, 1.0 });
    try (XContentParser parser = createParser(lineGeoJson)) {
        parser.nextToken();
        assertEquals(expected, new GeoJson(false, false, new GeographyValidator(true)).fromXContent(parser));
    }
}
Also used : Line(org.opensearch.geometry.Line) MultiLine(org.opensearch.geometry.MultiLine) GeographyValidator(org.opensearch.geometry.utils.GeographyValidator) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 13 with Line

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

the class GeometryTestUtils method randomMultiLine.

public static MultiLine randomMultiLine(boolean hasAlt) {
    int size = OpenSearchTestCase.randomIntBetween(3, 10);
    List<Line> lines = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        lines.add(randomLine(hasAlt));
    }
    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 14 with Line

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

the class GeoWKTShapeParserTests method testParseLineString.

@Override
public void testParseLineString() throws IOException, ParseException {
    List<Coordinate> coordinates = randomLineStringCoords();
    LineString expected = GEOMETRY_FACTORY.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
    assertExpected(jtsGeom(expected), new LineStringBuilder(coordinates), true);
    double[] lats = new double[coordinates.size()];
    double[] lons = new double[lats.length];
    for (int i = 0; i < lats.length; ++i) {
        lats[i] = coordinates.get(i).y;
        lons[i] = coordinates.get(i).x;
    }
    assertExpected(new Line(lons, lats), new LineStringBuilder(coordinates), false);
}
Also used : Line(org.opensearch.geometry.Line) MultiLine(org.opensearch.geometry.MultiLine) Coordinate(org.locationtech.jts.geom.Coordinate) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder) MultiPoint(org.opensearch.geometry.MultiPoint) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(org.locationtech.jts.geom.Point)

Example 15 with Line

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

the class GeoWKTShapeParserTests method testParseMultiLineString.

@Override
public void testParseMultiLineString() throws IOException, ParseException {
    int numLineStrings = randomIntBetween(0, 8);
    List<LineString> lineStrings = new ArrayList<>(numLineStrings);
    MultiLineStringBuilder builder = new MultiLineStringBuilder();
    for (int j = 0; j < numLineStrings; ++j) {
        List<Coordinate> lsc = randomLineStringCoords();
        Coordinate[] coords = lsc.toArray(new Coordinate[lsc.size()]);
        lineStrings.add(GEOMETRY_FACTORY.createLineString(coords));
        builder.linestring(new LineStringBuilder(lsc));
    }
    List<Line> lines = new ArrayList<>(lineStrings.size());
    for (int j = 0; j < lineStrings.size(); ++j) {
        Coordinate[] c = lineStrings.get(j).getCoordinates();
        lines.add(new Line(Arrays.stream(c).mapToDouble(i -> i.x).toArray(), Arrays.stream(c).mapToDouble(i -> i.y).toArray()));
    }
    Geometry expectedGeom;
    if (lines.isEmpty()) {
        expectedGeom = GeometryCollection.EMPTY;
    } else if (lines.size() == 1) {
        expectedGeom = new Line(lines.get(0).getX(), lines.get(0).getY());
    } else {
        expectedGeom = new MultiLine(lines);
    }
    assertExpected(expectedGeom, builder, false);
    assertMalformed(builder);
    MultiLineString expected = GEOMETRY_FACTORY.createMultiLineString(lineStrings.toArray(new LineString[lineStrings.size()]));
    assumeTrue("JTS test path cannot handle empty multilinestrings", numLineStrings > 1);
    assertExpected(jtsGeom(expected), builder, true);
}
Also used : Matchers.hasToString(org.hamcrest.Matchers.hasToString) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) Arrays(java.util.Arrays) GeometryCollectionBuilder(org.opensearch.common.geo.builders.GeometryCollectionBuilder) MultiPointBuilder(org.opensearch.common.geo.builders.MultiPointBuilder) ShapeParser(org.opensearch.common.geo.parsers.ShapeParser) ContentPath(org.opensearch.index.mapper.ContentPath) Coordinate(org.locationtech.jts.geom.Coordinate) Version(org.opensearch.Version) OpenSearchException(org.opensearch.OpenSearchException) RandomShapeGenerator(org.opensearch.test.geo.RandomShapeGenerator) MultiPoint(org.opensearch.geometry.MultiPoint) XContentParser(org.opensearch.common.xcontent.XContentParser) SPATIAL_CONTEXT(org.opensearch.common.geo.builders.ShapeBuilder.SPATIAL_CONTEXT) EnvelopeBuilder(org.opensearch.common.geo.builders.EnvelopeBuilder) XContentFactory(org.opensearch.common.xcontent.XContentFactory) MultiPolygonBuilder(org.opensearch.common.geo.builders.MultiPolygonBuilder) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) ParseException(java.text.ParseException) ShapeCollection(org.locationtech.spatial4j.shape.ShapeCollection) GeoShapeFieldMapper(org.opensearch.index.mapper.GeoShapeFieldMapper) MultiLineString(org.locationtech.jts.geom.MultiLineString) OpenSearchParseException(org.opensearch.OpenSearchParseException) Settings(org.opensearch.common.settings.Settings) Point(org.locationtech.jts.geom.Point) Geometry(org.opensearch.geometry.Geometry) Shape(org.locationtech.spatial4j.shape.Shape) GeoShapeIndexer(org.opensearch.index.mapper.GeoShapeIndexer) List(java.util.List) InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException) Polygon(org.locationtech.jts.geom.Polygon) Line(org.opensearch.geometry.Line) Matchers.containsString(org.hamcrest.Matchers.containsString) ShapeBuilder(org.opensearch.common.geo.builders.ShapeBuilder) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder) GeoTestUtil(org.apache.lucene.geo.GeoTestUtil) LinearRing(org.locationtech.jts.geom.LinearRing) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder) LegacyGeoShapeFieldMapper(org.opensearch.index.mapper.LegacyGeoShapeFieldMapper) ArrayList(java.util.ArrayList) PointBuilder(org.opensearch.common.geo.builders.PointBuilder) Rectangle(org.locationtech.spatial4j.shape.Rectangle) CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) UUIDs(org.opensearch.common.UUIDs) MultiLine(org.opensearch.geometry.MultiLine) GeometryCollection(org.opensearch.geometry.GeometryCollection) IOException(java.io.IOException) Mapper(org.opensearch.index.mapper.Mapper) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) GeoWKTParser(org.opensearch.common.geo.parsers.GeoWKTParser) LineString(org.locationtech.jts.geom.LineString) Collections(java.util.Collections) MultiLineString(org.locationtech.jts.geom.MultiLineString) ArrayList(java.util.ArrayList) MultiPoint(org.opensearch.geometry.MultiPoint) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(org.locationtech.jts.geom.Point) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder) Line(org.opensearch.geometry.Line) MultiLine(org.opensearch.geometry.MultiLine) Geometry(org.opensearch.geometry.Geometry) MultiLine(org.opensearch.geometry.MultiLine) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder)

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