Search in sources :

Example 1 with XShapeCollection

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

the class MultiPointBuilder method buildS4J.

@Override
public XShapeCollection<Point> buildS4J() {
    // Could wrap JtsGeometry but probably slower due to conversions to/from JTS in relate()
    // MultiPoint geometry = FACTORY.createMultiPoint(points.toArray(new Coordinate[points.size()]));
    List<Point> shapes = new ArrayList<>(coordinates.size());
    for (Coordinate coord : coordinates) {
        shapes.add(SPATIAL_CONTEXT.makePoint(coord.x, coord.y));
    }
    XShapeCollection<Point> multiPoints = new XShapeCollection<>(shapes, SPATIAL_CONTEXT);
    multiPoints.setPointsOnly(true);
    return multiPoints;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) XShapeCollection(org.opensearch.common.geo.XShapeCollection) ArrayList(java.util.ArrayList) Point(org.locationtech.spatial4j.shape.Point) MultiPoint(org.opensearch.geometry.MultiPoint)

Example 2 with XShapeCollection

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

the class LegacyGeoShapeIndexer method indexShape.

@Override
public List<IndexableField> indexShape(ParseContext context, Shape shape) {
    if (fieldType.pointsOnly()) {
        // index configured for pointsOnly
        if (shape instanceof XShapeCollection && XShapeCollection.class.cast(shape).pointsOnly()) {
            // MULTIPOINT data: index each point separately
            @SuppressWarnings("unchecked") List<Shape> shapes = ((XShapeCollection) shape).getShapes();
            List<IndexableField> fields = new ArrayList<>();
            for (Shape s : shapes) {
                fields.addAll(Arrays.asList(fieldType.defaultPrefixTreeStrategy().createIndexableFields(s)));
            }
            return fields;
        } else if (shape instanceof Point == false) {
            throw new MapperParsingException("[{" + fieldType.name() + "}] is configured for points only but a " + ((shape instanceof JtsGeometry) ? ((JtsGeometry) shape).getGeom().getGeometryType() : shape.getClass()) + " was found");
        }
    }
    return Arrays.asList(fieldType.defaultPrefixTreeStrategy().createIndexableFields(shape));
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) Shape(org.locationtech.spatial4j.shape.Shape) XShapeCollection(org.opensearch.common.geo.XShapeCollection) ArrayList(java.util.ArrayList) JtsGeometry(org.locationtech.spatial4j.shape.jts.JtsGeometry) Point(org.locationtech.spatial4j.shape.Point)

Aggregations

ArrayList (java.util.ArrayList)2 Point (org.locationtech.spatial4j.shape.Point)2 XShapeCollection (org.opensearch.common.geo.XShapeCollection)2 IndexableField (org.apache.lucene.index.IndexableField)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Shape (org.locationtech.spatial4j.shape.Shape)1 JtsGeometry (org.locationtech.spatial4j.shape.jts.JtsGeometry)1 MultiPoint (org.opensearch.geometry.MultiPoint)1