1516 if (PG_ARGISNULL(0))
1518 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1522 PG_FREE_IF_COPY(pgraster, 0);
1523 elog(ERROR,
"RASTER_band: Could not deserialize raster");
1528 if (PG_ARGISNULL(1)) {
1529 elog(NOTICE,
"Band number(s) not provided. Returning original raster");
1537 array = PG_GETARG_ARRAYTYPE_P(1);
1538 etype = ARR_ELEMTYPE(array);
1539 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
1547 PG_FREE_IF_COPY(pgraster, 0);
1548 elog(ERROR,
"RASTER_band: Invalid data type for band number(s)");
1553 deconstruct_array(array, etype, typlen, typbyval, typalign, &e,
1556 bandNums = palloc(
sizeof(
uint32_t) * n);
1557 for (i = 0, j = 0; i < n; i++) {
1558 if (nulls[i])
continue;
1562 idx = (
uint32_t) DatumGetInt16(e[i]);
1565 idx = (
uint32_t) DatumGetInt32(e[i]);
1570 if (idx > numBands || idx < 1) {
1571 elog(NOTICE,
"Invalid band index (must use 1-based). Returning original raster");
1576 bandNums[j] = idx - 1;
1581 if (skip || j < 1) {
1592 PG_FREE_IF_COPY(pgraster, 0);
1594 elog(ERROR,
"RASTER_band: Could not create new raster");
1604 SET_VARSIZE(pgrast, pgrast->
size);
1605 PG_RETURN_POINTER(pgrast);
1608 PG_RETURN_POINTER(pgraster);
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
int rt_raster_get_num_bands(rt_raster raster)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums, int count)
Construct a new rt_raster from an existing rt_raster and an array of band numbers.
#define POSTGIS_RT_DEBUGF(level, msg,...)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.