The following SQL-defined operators compose rasterValue with the standard MobilityDB temporal restriction and predicate functions. They accept an optional band argument (default 1) and call rasterValue exactly once per invocation.
Return the instants of a trajectory where the sampled raster value falls inside a float range
atRasterValue(tgeompoint,raster,floatspan,band integer DEFAULT 1) → tgeompoint
Evaluates rasterValue at every instant of traj and returns the sub-trajectory restricted to the times when the pixel value lies within vspan. Returns NULL when no instant satisfies the condition.
WITH rast AS (
SELECT ST_SetValues(
ST_AddBand(
ST_MakeEmptyRaster(3, 3, 0.0, 3.0, 1.0, -1.0, 0.0, 0.0, 4326),
'32BF'::text, 0.0::float8, NULL::float8),
1, 1, 1,
ARRAY[[10.0::float4, 20.0::float4, 30.0::float4],
[40.0::float4, 50.0::float4, 60.0::float4],
[70.0::float4, 80.0::float4, 90.0::float4]]) AS r
)
SELECT asText(atRasterValue(tgeompoint 'SRID=4326;[POINT(0.5 2.5)@2000-01-01,
POINT(1.5 1.5)@2000-01-02, POINT(0.5 0.5)@2000-01-03]', r, floatspan '[40, 90]'))
FROM rast;
-- {[POINT(1.5 1.5)@2000-01-02], [POINT(0.5 0.5)@2000-01-03]}
Return the instants of a trajectory where the sampled raster value falls outside a float range
minusRasterValue(tgeompoint,raster,floatspan,band integer DEFAULT 1) → tgeompoint
The complement of atRasterValue: returns the sub-trajectory restricted to the times when the pixel value lies outside vspan. Returns NULL when every instant satisfies the condition.
-- Keep only the instant whose raster value (10) is below 40 SELECT asText(minusRasterValue(traj, elev_raster, floatspan '[40, 9999]')) FROM trips, elevation_raster;
Return true if the trajectory ever samples a raster pixel value inside a float range
eRasterValue(tgeompoint,raster,floatspan,band integer DEFAULT 1) → boolean
Returns true when at least one in-extent instant of traj samples a pixel value within vspan, false otherwise. Returns NULL only when the input is NULL.
-- Trips that ever crossed terrain above 200 m SELECT tripid FROM trips, elevation_raster WHERE eRasterValue(trip, elev_raster, floatspan '[200, 9999]');
Return true if every in-raster-extent instant of the trajectory samples a pixel value inside a float range
aRasterValue(tgeompoint,raster,floatspan,band integer DEFAULT 1) → boolean
Returns true when every in-extent instant of traj samples a pixel value within vspan, false when at least one does not. Returns NULL only when the input is NULL.
-- Trips that stayed entirely below 100 m elevation SELECT tripid FROM trips, elevation_raster WHERE aRasterValue(trip, elev_raster, floatspan '[0, 100]');