Search in sources :

Example 11 with LineStringBuilder

use of org.opensearch.common.geo.builders.LineStringBuilder 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 12 with LineStringBuilder

use of org.opensearch.common.geo.builders.LineStringBuilder 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)

Example 13 with LineStringBuilder

use of org.opensearch.common.geo.builders.LineStringBuilder in project OpenSearch by opensearch-project.

the class ShapeBuilderTests method testShapeWithHoleAtEdgeEndPoints.

public void testShapeWithHoleAtEdgeEndPoints() {
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(-4, 2).coordinate(4, 2).coordinate(6, 0).coordinate(4, -2).coordinate(-4, -2).coordinate(-6, 0).coordinate(-4, 2));
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(4, 1).coordinate(4, -1).coordinate(-4, -1).coordinate(-4, 1).coordinate(4, 1)));
    assertPolygon(builder.close().buildS4J(), true);
    assertPolygon(buildGeometry(builder.close()), false);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder)

Example 14 with LineStringBuilder

use of org.opensearch.common.geo.builders.LineStringBuilder in project OpenSearch by opensearch-project.

the class ShapeBuilderTests method testDateline.

public void testDateline() {
    // tests that the following shape (defined in clockwise non-OGC order)
    // https://gist.github.com/anonymous/7f1bb6d7e9cd72f5977c crosses the dateline
    // expected results: 3 polygons, 1 with a hole
    // a giant c shape
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(-186, 0).coordinate(-176, 0).coordinate(-176, 3).coordinate(-183, 3).coordinate(-183, 5).coordinate(-176, 5).coordinate(-176, 8).coordinate(-186, 8).coordinate(-186, 0));
    // 3/4 of an embedded 'c', crossing dateline once
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-185, 1).coordinate(-181, 1).coordinate(-181, 2).coordinate(-184, 2).coordinate(-184, 6).coordinate(-178, 6).coordinate(-178, 7).coordinate(-185, 7).coordinate(-185, 1)));
    // embedded hole right of the dateline
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-179, 1).coordinate(-177, 1).coordinate(-177, 2).coordinate(-179, 2).coordinate(-179, 1)));
    assertMultiPolygon(builder.close().buildS4J(), true);
    assertMultiPolygon(buildGeometry(builder.close()), false);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder)

Example 15 with LineStringBuilder

use of org.opensearch.common.geo.builders.LineStringBuilder in project OpenSearch by opensearch-project.

the class ShapeBuilderTests method testComplexShapeWithHole.

public void testComplexShapeWithHole() {
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(-85.0018514, 37.1311314).coordinate(-85.0016645, 37.1315293).coordinate(-85.0016246, 37.1317069).coordinate(-85.0016526, 37.1318183).coordinate(-85.0017119, 37.1319196).coordinate(-85.0019371, 37.1321182).coordinate(-85.0019972, 37.1322115).coordinate(-85.0019942, 37.1323234).coordinate(-85.0019543, 37.1324336).coordinate(-85.001906, 37.1324985).coordinate(-85.001834, 37.1325497).coordinate(-85.0016965, 37.1325907).coordinate(-85.0016011, 37.1325873).coordinate(-85.0014816, 37.1325353).coordinate(-85.0011755, 37.1323509).coordinate(-85.000955, 37.1322802).coordinate(-85.0006241, 37.1322529).coordinate(-85.0000002, 37.1322307).coordinate(-84.9994, 37.1323001).coordinate(-84.999109, 37.1322864).coordinate(-84.998934, 37.1322415).coordinate(-84.9988639, 37.1321888).coordinate(-84.9987841, 37.1320944).coordinate(-84.9987208, 37.131954).coordinate(-84.998736, 37.1316611).coordinate(-84.9988091, 37.131334).coordinate(-84.9989283, 37.1311337).coordinate(-84.9991943, 37.1309198).coordinate(-84.9993573, 37.1308459).coordinate(-84.9995888, 37.1307924).coordinate(-84.9998746, 37.130806).coordinate(-85.0000002, 37.1308358).coordinate(-85.0004984, 37.1310658).coordinate(-85.0008008, 37.1311625).coordinate(-85.0009461, 37.1311684).coordinate(-85.0011373, 37.1311515).coordinate(-85.0016455, 37.1310491).coordinate(-85.0018514, 37.1311314));
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-85.0000002, 37.1317672).coordinate(-85.0001983, 37.1317538).coordinate(-85.0003378, 37.1317582).coordinate(-85.0004697, 37.131792).coordinate(-85.0008048, 37.1319439).coordinate(-85.0009342, 37.1319838).coordinate(-85.0010184, 37.1319463).coordinate(-85.0010618, 37.13184).coordinate(-85.0010057, 37.1315102).coordinate(-85.000977, 37.1314403).coordinate(-85.0009182, 37.1313793).coordinate(-85.0005366, 37.1312209).coordinate(-85.000224, 37.1311466).coordinate(-85.000087, 37.1311356).coordinate(-85.0000002, 37.1311433).coordinate(-84.9995021, 37.1312336).coordinate(-84.9993308, 37.1312859).coordinate(-84.9992567, 37.1313252).coordinate(-84.9991868, 37.1314277).coordinate(-84.9991593, 37.1315381).coordinate(-84.9991841, 37.1316527).coordinate(-84.9992329, 37.1317117).coordinate(-84.9993527, 37.1317788).coordinate(-84.9994931, 37.1318061).coordinate(-84.9996815, 37.1317979).coordinate(-85.0000002, 37.1317672)));
    assertPolygon(builder.close().buildS4J(), true);
    assertPolygon(buildGeometry(builder.close()), false);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder)

Aggregations

LineStringBuilder (org.opensearch.common.geo.builders.LineStringBuilder)23 CoordinatesBuilder (org.opensearch.common.geo.builders.CoordinatesBuilder)21 MultiLineStringBuilder (org.opensearch.common.geo.builders.MultiLineStringBuilder)20 PolygonBuilder (org.opensearch.common.geo.builders.PolygonBuilder)17 Coordinate (org.locationtech.jts.geom.Coordinate)7 MultiPolygonBuilder (org.opensearch.common.geo.builders.MultiPolygonBuilder)6 InvalidShapeException (org.locationtech.spatial4j.exception.InvalidShapeException)5 PointBuilder (org.opensearch.common.geo.builders.PointBuilder)5 ArrayList (java.util.ArrayList)4 MultiPointBuilder (org.opensearch.common.geo.builders.MultiPointBuilder)4 ShapeBuilder (org.opensearch.common.geo.builders.ShapeBuilder)4 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)4 OpenSearchException (org.opensearch.OpenSearchException)3 OpenSearchParseException (org.opensearch.OpenSearchParseException)3 MultiLine (org.opensearch.geometry.MultiLine)3 LineString (org.locationtech.jts.geom.LineString)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 MultiLineString (org.locationtech.jts.geom.MultiLineString)2 Point (org.locationtech.jts.geom.Point)2 Polygon (org.locationtech.jts.geom.Polygon)2