259{
263 LWGEOM *lwgeom_in, *lwgeom_out;
266 char dimension;
267 const char *func_name;
268 uint16_t num_bands;
270
271 text *resample_text = PG_GETARG_TEXT_P(2);
272
273
274
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
284 gser = (
GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
286 elog(ERROR, "Cannot copy value into an empty geometry");
287 PG_RETURN_NULL();
288 }
289
290
291 pgraster = (
rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
294 if (!raster) {
295 elog(ERROR, "Could not deserialize raster");
296 PG_RETURN_NULL();
297 }
298
299
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
308 elog(ERROR, "Raster and geometry do not have the same SRID");
309 PG_RETURN_NULL();
310 }
311
312
314
315
317
318
320 raster,
321 band - 1,
322 dimension,
323 resample_type,
324 lwgeom_in,
325 &lwgeom_out
326 );
327
330 if (err !=
ES_NONE || !lwgeom_out) {
331 PG_RETURN_NULL();
332 }
334}
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)
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_errorstate
Enum definitions.
uint16_t rt_raster_get_num_bands(rt_raster raster)
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.
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): ...
static rt_resample_type resample_text_to_type(text *txt)