use of org.opensearch.common.geo.builders.LineStringBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testLineStringWrapping.
public void testLineStringWrapping() {
LineStringBuilder lsb = new LineStringBuilder(new CoordinatesBuilder().coordinate(-150.0, 65.0).coordinate(-250.0, 65.0).coordinate(-250.0, -65.0).coordinate(-150.0, -65.0).close());
assertMultiLineString(lsb.buildS4J(), true);
assertMultiLineString(buildGeometry(lsb), false);
}
use of org.opensearch.common.geo.builders.LineStringBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testDatelineOGC.
public void testDatelineOGC() {
// tests that the following shape (defined in counterclockwise 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(174, 0).coordinate(-176, 0).coordinate(-176, 3).coordinate(177, 3).coordinate(177, 5).coordinate(-176, 5).coordinate(-176, 8).coordinate(174, 8).coordinate(174, 0));
// 3/4 of an embedded 'c', crossing dateline once
builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(175, 1).coordinate(175, 7).coordinate(-178, 7).coordinate(-178, 6).coordinate(176, 6).coordinate(176, 2).coordinate(179, 2).coordinate(179, 1).coordinate(175, 1)));
// embedded hole right of the dateline
builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-179, 1).coordinate(-179, 2).coordinate(-177, 2).coordinate(-177, 1).coordinate(-179, 1)));
assertMultiPolygon(builder.close().buildS4J(), true);
assertMultiPolygon(buildGeometry(builder.close()), false);
}
use of org.opensearch.common.geo.builders.LineStringBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testBoundaryShapeWithInvalidTangentialHole.
public void testBoundaryShapeWithInvalidTangentialHole() {
// test shape with two tangential (shared) vertices (should throw exception)
PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(-177, 10).coordinate(176, 15).coordinate(172, 0).coordinate(176, -15).coordinate(-177, -10).coordinate(-177, 10));
builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-177, 10).coordinate(172, 0).coordinate(180, -5).coordinate(176, -10).coordinate(-177, 10)));
Exception e;
e = expectThrows(InvalidShapeException.class, () -> builder.close().buildS4J());
assertThat(e.getMessage(), containsString("interior cannot share more than one point with the exterior"));
e = expectThrows(IllegalArgumentException.class, () -> buildGeometry(builder.close()));
assertThat(e.getMessage(), containsString("interior cannot share more than one point with the exterior"));
}
use of org.opensearch.common.geo.builders.LineStringBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testLineStringBuilder.
public void testLineStringBuilder() {
// Building a simple LineString
LineStringBuilder lsb = new LineStringBuilder(new CoordinatesBuilder().coordinate(-130.0, 55.0).coordinate(-130.0, -40.0).coordinate(-15.0, -40.0).coordinate(-20.0, 50.0).coordinate(-45.0, 50.0).coordinate(-45.0, -15.0).coordinate(-110.0, -15.0).coordinate(-110.0, 55.0));
lsb.buildS4J();
buildGeometry(lsb);
// Building a linestring that needs to be wrapped
lsb = new LineStringBuilder(new CoordinatesBuilder().coordinate(100.0, 50.0).coordinate(110.0, -40.0).coordinate(240.0, -40.0).coordinate(230.0, 60.0).coordinate(200.0, 60.0).coordinate(200.0, -30.0).coordinate(130.0, -30.0).coordinate(130.0, 60.0));
lsb.buildS4J();
buildGeometry(lsb);
// Building a lineString on the dateline
lsb = new LineStringBuilder(new CoordinatesBuilder().coordinate(-180.0, 80.0).coordinate(-180.0, 40.0).coordinate(-180.0, -40.0).coordinate(-180.0, -80.0));
lsb.buildS4J();
buildGeometry(lsb);
// Building a lineString on the dateline
lsb = new LineStringBuilder(new CoordinatesBuilder().coordinate(180.0, 80.0).coordinate(180.0, 40.0).coordinate(180.0, -40.0).coordinate(180.0, -80.0));
lsb.buildS4J();
buildGeometry(lsb);
}
use of org.opensearch.common.geo.builders.LineStringBuilder in project OpenSearch by opensearch-project.
the class GeoWKTShapeParserTests method testParseMixedDimensionPolyWithHole.
public void testParseMixedDimensionPolyWithHole() throws IOException, ParseException {
List<Coordinate> shellCoordinates = new ArrayList<>();
shellCoordinates.add(new Coordinate(100, 0));
shellCoordinates.add(new Coordinate(101, 0));
shellCoordinates.add(new Coordinate(101, 1));
shellCoordinates.add(new Coordinate(100, 1));
shellCoordinates.add(new Coordinate(100, 0));
// add 3d point to test ISSUE #10501
List<Coordinate> holeCoordinates = new ArrayList<>();
holeCoordinates.add(new Coordinate(100.2, 0.2, 15.0));
holeCoordinates.add(new Coordinate(100.8, 0.2));
holeCoordinates.add(new Coordinate(100.8, 0.8));
holeCoordinates.add(new Coordinate(100.2, 0.8, 10.0));
holeCoordinates.add(new Coordinate(100.2, 0.2));
PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinates(shellCoordinates));
builder.hole(new LineStringBuilder(holeCoordinates));
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().value(builder.toWKT());
XContentParser parser = createParser(xContentBuilder);
parser.nextToken();
Settings indexSettings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build();
Mapper.BuilderContext mockBuilderContext = new Mapper.BuilderContext(indexSettings, new ContentPath());
final GeoShapeFieldMapper mapperBuilder = (GeoShapeFieldMapper) (new GeoShapeFieldMapper.Builder("test").ignoreZValue(false).build(mockBuilderContext));
// test store z disabled
OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> ShapeParser.parse(parser, mapperBuilder));
assertThat(e, hasToString(containsString("but [ignore_z_value] parameter is [false]")));
}
Aggregations