use of org.opensearch.common.geo.builders.CoordinatesBuilder in project OpenSearch by opensearch-project.
the class GeoWKTShapeParserTests method testParsePolyWithStoredZ.
public void testParsePolyWithStoredZ() throws IOException {
List<Coordinate> shellCoordinates = new ArrayList<>();
shellCoordinates.add(new Coordinate(100, 0, 0));
shellCoordinates.add(new Coordinate(101, 0, 0));
shellCoordinates.add(new Coordinate(101, 1, 0));
shellCoordinates.add(new Coordinate(100, 1, 5));
shellCoordinates.add(new Coordinate(100, 0, 5));
PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinates(shellCoordinates));
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 LegacyGeoShapeFieldMapper mapperBuilder = (LegacyGeoShapeFieldMapper) (new LegacyGeoShapeFieldMapper.Builder("test").ignoreZValue(true).build(mockBuilderContext));
ShapeBuilder<?, ?, ?> shapeBuilder = ShapeParser.parse(parser, mapperBuilder);
assertEquals(shapeBuilder.numDimensions(), 3);
}
use of org.opensearch.common.geo.builders.CoordinatesBuilder 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]")));
}
use of org.opensearch.common.geo.builders.CoordinatesBuilder in project OpenSearch by opensearch-project.
the class GeoWKTShapeParserTests method testParsePolygonWithHole.
public void testParsePolygonWithHole() throws IOException, ParseException {
// add 3d point to test ISSUE #10501
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));
List<Coordinate> holeCoordinates = new ArrayList<>();
holeCoordinates.add(new Coordinate(100.2, 0.2));
holeCoordinates.add(new Coordinate(100.8, 0.2));
holeCoordinates.add(new Coordinate(100.8, 0.8));
holeCoordinates.add(new Coordinate(100.2, 0.8));
holeCoordinates.add(new Coordinate(100.2, 0.2));
PolygonBuilder polygonWithHole = new PolygonBuilder(new CoordinatesBuilder().coordinates(shellCoordinates));
polygonWithHole.hole(new LineStringBuilder(holeCoordinates));
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(shellCoordinates.toArray(new Coordinate[shellCoordinates.size()]));
LinearRing[] holes = new LinearRing[1];
holes[0] = GEOMETRY_FACTORY.createLinearRing(holeCoordinates.toArray(new Coordinate[holeCoordinates.size()]));
Polygon expected = GEOMETRY_FACTORY.createPolygon(shell, holes);
assertExpected(jtsGeom(expected), polygonWithHole, true);
org.opensearch.geometry.LinearRing hole = new org.opensearch.geometry.LinearRing(new double[] { 100.2d, 100.8d, 100.8d, 100.2d, 100.2d }, new double[] { 0.8d, 0.8d, 0.2d, 0.2d, 0.8d });
org.opensearch.geometry.Polygon p = new org.opensearch.geometry.Polygon(new org.opensearch.geometry.LinearRing(new double[] { 101d, 101d, 100d, 100d, 101d }, new double[] { 0d, 1d, 1d, 0d, 0d }), Collections.singletonList(hole));
assertExpected(p, polygonWithHole, false);
assertMalformed(polygonWithHole);
}
use of org.opensearch.common.geo.builders.CoordinatesBuilder in project OpenSearch by opensearch-project.
the class GeoWKTShapeParserTests method testParseMixedDimensionPolyWithHoleStoredZ.
public void testParseMixedDimensionPolyWithHoleStoredZ() throws IOException {
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 LegacyGeoShapeFieldMapper mapperBuilder = (LegacyGeoShapeFieldMapper) (new LegacyGeoShapeFieldMapper.Builder("test").ignoreZValue(true).build(mockBuilderContext));
// test store z disabled
OpenSearchException e = expectThrows(OpenSearchException.class, () -> ShapeParser.parse(parser, mapperBuilder));
assertThat(e, hasToString(containsString("unable to add coordinate to CoordinateBuilder: coordinate dimensions do not match")));
}
use of org.opensearch.common.geo.builders.CoordinatesBuilder in project OpenSearch by opensearch-project.
the class GeoQueryTests method testIndexPointsPolygon.
public void testIndexPointsPolygon() throws Exception {
XContentBuilder xcb = createDefaultMapping();
client().admin().indices().prepareCreate(defaultIndexName).addMapping("_doc", xcb).get();
ensureGreen();
client().prepareIndex(defaultIndexName).setId("1").setSource(jsonBuilder().startObject().field(defaultGeoFieldName, "POINT(-30 -30)").endObject()).setRefreshPolicy(IMMEDIATE).get();
client().prepareIndex(defaultIndexName).setId("2").setSource(jsonBuilder().startObject().field(defaultGeoFieldName, "POINT(-45 -50)").endObject()).setRefreshPolicy(IMMEDIATE).get();
CoordinatesBuilder cb = new CoordinatesBuilder();
cb.coordinate(new Coordinate(-35, -35)).coordinate(new Coordinate(-35, -25)).coordinate(new Coordinate(-25, -25)).coordinate(new Coordinate(-25, -35)).coordinate(new Coordinate(-35, -35));
PolygonBuilder shape = new PolygonBuilder(cb);
GeometryCollectionBuilder builder = new GeometryCollectionBuilder().shape(shape);
Geometry geometry = builder.buildGeometry();
SearchResponse searchResponse = client().prepareSearch(defaultIndexName).setQuery(QueryBuilders.geoShapeQuery(defaultGeoFieldName, geometry).relation(ShapeRelation.INTERSECTS)).get();
assertSearchResponse(searchResponse);
assertHitCount(searchResponse, 1);
SearchHits searchHits = searchResponse.getHits();
assertThat(searchHits.getAt(0).getId(), equalTo("1"));
}
Aggregations