use of org.opensearch.geometry.Geometry in project OpenSearch by opensearch-project.
the class GeoPoint method resetFromWKT.
private GeoPoint resetFromWKT(String value, boolean ignoreZValue) {
Geometry geometry;
try {
geometry = new WellKnownText(false, new GeographyValidator(ignoreZValue)).fromWKT(value);
} catch (Exception e) {
throw new OpenSearchParseException("Invalid WKT format", e);
}
if (geometry.type() != ShapeType.POINT) {
throw new OpenSearchParseException("[geo_point] supports only POINT among WKT primitives, " + "but found " + geometry.type());
}
Point point = (Point) geometry;
return reset(point.getY(), point.getX());
}
use of org.opensearch.geometry.Geometry in project OpenSearch by opensearch-project.
the class GeoShapeParser method parseAndFormatObject.
@Override
public Object parseAndFormatObject(Object value, String format) {
try (XContentParser parser = new MapXContentParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, Collections.singletonMap("dummy_field", value), XContentType.JSON)) {
// start object
parser.nextToken();
// field name
parser.nextToken();
// field value
parser.nextToken();
GeometryFormat<Geometry> geometryFormat = geometryParser.geometryFormat(parser);
if (geometryFormat.name().equals(format)) {
return value;
}
Geometry geometry = geometryFormat.fromXContent(parser);
return format(geometry, format);
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
use of org.opensearch.geometry.Geometry in project OpenSearch by opensearch-project.
the class GeometryIndexerTests method testCollection.
public void testCollection() {
assertEquals(GeometryCollection.EMPTY, indexer.prepareForIndexing(GeometryCollection.EMPTY));
GeometryCollection<Geometry> collection = new GeometryCollection<>(Collections.singletonList(new Point(2, 1)));
Geometry indexed = new Point(2, 1);
assertEquals(indexed, indexer.prepareForIndexing(collection));
collection = new GeometryCollection<>(Arrays.asList(new Point(2, 1), new Point(4, 3), new Line(new double[] { 160, 200 }, new double[] { 10, 20 })));
indexed = new GeometryCollection<>(Arrays.asList(new Point(2, 1), new Point(4, 3), 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(collection));
}
use of org.opensearch.geometry.Geometry in project OpenSearch by opensearch-project.
the class GeometryIndexerTests method testMultiPoint.
public void testMultiPoint() {
MultiPoint multiPoint = MultiPoint.EMPTY;
Geometry indexed = multiPoint;
assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
multiPoint = new MultiPoint(Collections.singletonList(new Point(2, 1)));
indexed = new Point(2, 1);
assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
multiPoint = new MultiPoint(Arrays.asList(new Point(2, 1), new Point(4, 3)));
indexed = multiPoint;
assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
multiPoint = new MultiPoint(Arrays.asList(new Point(2, 1, 10), new Point(4, 3, 10)));
assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
}
use of org.opensearch.geometry.Geometry in project OpenSearch by opensearch-project.
the class GeometryIndexerTests method testPoint.
public void testPoint() {
Point point = new Point(2, 1);
Geometry indexed = point;
assertEquals(indexed, indexer.prepareForIndexing(point));
point = new Point(2, 1, 3);
assertEquals(indexed, indexer.prepareForIndexing(point));
point = new Point(362, 1);
assertEquals(indexed, indexer.prepareForIndexing(point));
point = new Point(-178, 179);
assertEquals(indexed, indexer.prepareForIndexing(point));
point = new Point(180, 180);
assertEquals(new Point(0, 0), indexer.prepareForIndexing(point));
point = new Point(-180, -180);
assertEquals(new Point(0, 0), indexer.prepareForIndexing(point));
}
Aggregations