Search in sources :

Example 1 with SpatialObject

use of com.geophile.z.SpatialObject in project fdb-record-layer by FoundationDB.

the class GeophileSpatialObjectQueryPlan method executeEntries.

@Nonnull
@Override
public <M extends Message> RecordCursor<IndexEntry> executeEntries(@Nonnull FDBRecordStoreBase<M> store, @Nonnull EvaluationContext context, @Nullable byte[] continuation, @Nonnull ExecuteProperties executeProperties) {
    if (continuation != null) {
        throw new RecordCoreException("continuations are not yet supported");
    }
    final SpatialObject spatialObject = getSpatialObject(context);
    if (spatialObject == null) {
        return RecordCursor.empty();
    }
    final SpatialJoin spatialJoin = SpatialJoin.newSpatialJoin(SpatialJoin.Duplicates.INCLUDE, getFilter(context));
    final GeophileSpatialJoin geophileSpatialJoin = new GeophileSpatialJoin(spatialJoin, store.getUntypedRecordStore(), context);
    final SpatialIndex<GeophileRecordImpl> spatialIndex = geophileSpatialJoin.getSpatialIndex(indexName, prefixComparisons, getRecordFunction());
    return geophileSpatialJoin.recordCursor(spatialObject, spatialIndex);
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) SpatialJoin(com.geophile.z.SpatialJoin) SpatialObject(com.geophile.z.SpatialObject) RecordWithSpatialObject(com.geophile.z.index.RecordWithSpatialObject) Nonnull(javax.annotation.Nonnull)

Example 2 with SpatialObject

use of com.geophile.z.SpatialObject in project fdb-record-layer by FoundationDB.

the class GeophilePointWithinDistanceQueryPlan method getFilter.

@Nullable
@Override
protected SpatialJoin.Filter<RecordWithSpatialObject, GeophileRecordImpl> getFilter(@Nonnull EvaluationContext context) {
    if (covering) {
        Double distanceValue = distance.getValue(context);
        Double centerLatitudeValue = centerLatitude.getValue(context);
        Double centerLongitudeValue = centerLongitude.getValue(context);
        if (distanceValue == null || centerLatitudeValue == null || centerLongitudeValue == null) {
            return null;
        }
        final GeometryFactory geometryFactory = new GeometryFactory();
        final Geometry center = geometryFactory.createPoint(new Coordinate(centerLatitudeValue, centerLongitudeValue));
        return (spatialObject, record) -> {
            Point point = (Point) record.spatialObject();
            Geometry geometry = geometryFactory.createPoint(new Coordinate(point.x(), point.y()));
            return geometry.isWithinDistance(center, distanceValue);
        };
    } else {
        return null;
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) IndexEntry(com.apple.foundationdb.record.IndexEntry) BiFunction(java.util.function.BiFunction) Coordinate(org.locationtech.jts.geom.Coordinate) RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) SpatialObject(com.geophile.z.SpatialObject) PlanHashable(com.apple.foundationdb.record.PlanHashable) Tuple(com.apple.foundationdb.tuple.Tuple) ImmutableList(com.google.common.collect.ImmutableList) Attribute(com.apple.foundationdb.record.query.plan.temp.explain.Attribute) Map(java.util.Map) AliasMap(com.apple.foundationdb.record.query.plan.temp.AliasMap) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) DoubleValueOrParameter(com.apple.foundationdb.record.spatial.common.DoubleValueOrParameter) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) SpatialJoin(com.geophile.z.SpatialJoin) RecordWithSpatialObject(com.geophile.z.index.RecordWithSpatialObject) ImmutableMap(com.google.common.collect.ImmutableMap) ScanComparisons(com.apple.foundationdb.record.query.plan.ScanComparisons) QueriedValue(com.apple.foundationdb.record.query.predicates.QueriedValue) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) Objects(java.util.Objects) Value(com.apple.foundationdb.record.query.predicates.Value) List(java.util.List) Point(com.geophile.z.spatialobject.d2.Point) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) ObjectPlanHash(com.apple.foundationdb.record.ObjectPlanHash) Geometry(org.locationtech.jts.geom.Geometry) API(com.apple.foundationdb.annotation.API) PlannerGraph(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph) NodeInfo(com.apple.foundationdb.record.query.plan.temp.explain.NodeInfo) AvailableFields(com.apple.foundationdb.record.query.plan.AvailableFields) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Point(com.geophile.z.spatialobject.d2.Point) Nullable(javax.annotation.Nullable)

Example 3 with SpatialObject

use of com.geophile.z.SpatialObject in project fdb-record-layer by FoundationDB.

the class GeophileSpatialFunctionKeyExpression method evaluateFunction.

@Nonnull
@Override
public <M extends Message> List<Key.Evaluated> evaluateFunction(@Nullable FDBRecord<M> record, @Nullable Message message, @Nonnull Key.Evaluated arguments) {
    SpatialObject spatialObject;
    try {
        spatialObject = parseSpatialObject(arguments);
    } catch (ParseException ex) {
        throw new RecordCoreException(ex);
    }
    if (spatialObject == null) {
        return Collections.singletonList(Key.Evaluated.NULL);
    }
    long[] zs = new long[spatialObject.maxZ()];
    GeophileSpatial.shuffle(space, spatialObject, zs);
    List<Key.Evaluated> result = new ArrayList<>(zs.length);
    for (long z : zs) {
        if (z == Space.Z_NULL) {
            break;
        }
        result.add(Key.Evaluated.scalar(z));
    }
    return result;
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) ArrayList(java.util.ArrayList) ParseException(org.locationtech.jts.io.ParseException) SpatialObject(com.geophile.z.SpatialObject) Nonnull(javax.annotation.Nonnull)

Aggregations

SpatialObject (com.geophile.z.SpatialObject)3 Nonnull (javax.annotation.Nonnull)3 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)2 SpatialJoin (com.geophile.z.SpatialJoin)2 RecordWithSpatialObject (com.geophile.z.index.RecordWithSpatialObject)2 API (com.apple.foundationdb.annotation.API)1 EvaluationContext (com.apple.foundationdb.record.EvaluationContext)1 IndexEntry (com.apple.foundationdb.record.IndexEntry)1 ObjectPlanHash (com.apple.foundationdb.record.ObjectPlanHash)1 PlanHashable (com.apple.foundationdb.record.PlanHashable)1 AvailableFields (com.apple.foundationdb.record.query.plan.AvailableFields)1 ScanComparisons (com.apple.foundationdb.record.query.plan.ScanComparisons)1 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)1 AliasMap (com.apple.foundationdb.record.query.plan.temp.AliasMap)1 RelationalExpression (com.apple.foundationdb.record.query.plan.temp.RelationalExpression)1 Attribute (com.apple.foundationdb.record.query.plan.temp.explain.Attribute)1 NodeInfo (com.apple.foundationdb.record.query.plan.temp.explain.NodeInfo)1 PlannerGraph (com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph)1 QueriedValue (com.apple.foundationdb.record.query.predicates.QueriedValue)1 Value (com.apple.foundationdb.record.query.predicates.Value)1