1480 if (PG_ARGISNULL(0))
1482 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1486 PG_FREE_IF_COPY(pgraster, 0);
1487 elog(ERROR,
"RASTER_band: Could not deserialize raster");
1492 if (PG_ARGISNULL(1)) {
1493 elog(NOTICE,
"Band number(s) not provided. Returning original raster");
1499 array = PG_GETARG_ARRAYTYPE_P(1);
1500 etype = ARR_ELEMTYPE(array);
1501 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
1509 PG_FREE_IF_COPY(pgraster, 0);
1510 elog(ERROR,
"RASTER_band: Invalid data type for band number(s)");
1515 deconstruct_array(array, etype, typlen, typbyval, typalign, &e,
1518 bandNums = palloc(
sizeof(uint32_t) * n);
1519 for (i = 0, j = 0; i < n; i++) {
1520 if (nulls[i])
continue;
1524 idx = (uint32_t) DatumGetInt16(e[i]);
1527 idx = (uint32_t) DatumGetInt32(e[i]);
1532 if (idx > numBands || idx < 1) {
1533 elog(NOTICE,
"Invalid band index (must use 1-based). Returning original raster");
1538 bandNums[j] = idx - 1;
1543 if (skip || j < 1) {
1553 PG_FREE_IF_COPY(pgraster, 0);
1555 elog(ERROR,
"RASTER_band: Could not create new raster");
1565 SET_VARSIZE(pgrast, pgrast->
size);
1566 PG_RETURN_POINTER(pgrast);
1569 PG_RETURN_POINTER(pgraster);
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
uint16_t rt_raster_get_num_bands(rt_raster raster)
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.
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): ...
#define POSTGIS_RT_DEBUGF(level, msg,...)