PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ RASTER_getGeometryValues()

Datum RASTER_getGeometryValues ( PG_FUNCTION_ARGS  )

Definition at line 258 of file rtpg_pixel.c.

259{
260 rt_raster raster = NULL;
261 rt_pgraster *pgraster = NULL;
262 GSERIALIZED *gser;
263 LWGEOM *lwgeom_in, *lwgeom_out;
264 rt_resample_type resample_type = RT_NEAREST;
265 rt_errorstate err;
266 char dimension;
267 const char *func_name;
268 uint16_t num_bands;
269 int32_t band;
270
271 text *resample_text = PG_GETARG_TEXT_P(2);
272
273 /* Dimension depends on the name of calling SQL function */
274 /* ST_SetZ()? or ST_SetM()? */
275 func_name = get_func_name(fcinfo->flinfo->fn_oid);
276 if (strcmp(func_name, "st_setz") == 0)
277 dimension = 'z';
278 else if (strcmp(func_name, "st_setm") == 0)
279 dimension = 'm';
280 else
281 elog(ERROR, "%s called from unexpected SQL signature", __func__);
282
283 /* Geometry */
284 gser = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
285 if (gserialized_is_empty(gser)) {
286 elog(ERROR, "Cannot copy value into an empty geometry");
287 PG_RETURN_NULL();
288 }
289
290 /* Raster */
291 pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
293 num_bands = rt_raster_get_num_bands(raster);
294 if (!raster) {
295 elog(ERROR, "Could not deserialize raster");
296 PG_RETURN_NULL();
297 }
298
299 /* Bandnidex is 1-based */
300 band = PG_GETARG_INT32(3);
301 if (band < 1 || band > num_bands) {
302 elog(NOTICE, "Invalid band index %d. Must be between 1 and %u", band, num_bands);
303 PG_RETURN_NULL();
304 }
305
306 /* SRID consistency */
307 if (gserialized_get_srid(gser) != rt_raster_get_srid(raster)) {
308 elog(ERROR, "Raster and geometry do not have the same SRID");
309 PG_RETURN_NULL();
310 }
311
312 /* Process arguments */
313 resample_type = resample_text_to_type(resample_text);
314
315 /* Get the geometry */
316 lwgeom_in = lwgeom_from_gserialized(gser);
317
318 /* Run the sample */
320 raster,
321 band - 1, /* rtcore uses 0-based band number */
322 dimension, /* 'z' or 'm' */
323 resample_type, /* bilinear or nearest */
324 lwgeom_in,
325 &lwgeom_out
326 );
327
328 rt_raster_destroy(raster);
329 lwgeom_free(lwgeom_in);
330 if (err != ES_NONE || !lwgeom_out) {
331 PG_RETURN_NULL();
332 }
333 PG_RETURN_POINTER(gserialized_from_lwgeom(lwgeom_out, NULL));
334}
#define FALSE
Definition dbfopen.c:72
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition rt_raster.c:360
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition rt_raster.c:86
rt_resample_type
Definition librtcore.h:1478
@ RT_NEAREST
Definition librtcore.h:1479
rt_errorstate
Enum definitions.
Definition librtcore.h:181
@ ES_NONE
Definition librtcore.h:182
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition rt_raster.c:376
rt_errorstate rt_raster_copy_to_geometry(rt_raster raster, uint32_t bandnum, char dim, rt_resample_type resample, const LWGEOM *lwgeom_in, LWGEOM **lwgeom_out)
Copy values from a raster to the points on a geometry using the requested interpolation type.
Definition rt_raster.c:1492
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition rtrowdump.py:125
static rt_resample_type resample_text_to_type(text *txt)
Definition rtpg_pixel.c:142
Struct definitions.
Definition librtcore.h:2452

References ES_NONE, FALSE, gserialized_from_lwgeom(), gserialized_get_srid(), gserialized_is_empty(), lwgeom_free(), lwgeom_from_gserialized(), resample_text_to_type(), RT_NEAREST, rt_raster_copy_to_geometry(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_num_bands(), and rt_raster_get_srid().

Here is the call graph for this function: