354 bool appendband =
FALSE;
372 if (!PG_ARGISNULL(0)) {
373 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
378 PG_FREE_IF_COPY(pgraster, 0);
379 elog(ERROR,
"RASTER_addBandRasterArray: Could not deserialize destination raster");
387 if (!PG_ARGISNULL(2))
388 srcnband = PG_GETARG_INT32(2);
390 elog(NOTICE,
"Invalid band index for source rasters (must be 1-based). Returning original raster");
391 if (raster != NULL) {
393 PG_RETURN_POINTER(pgraster);
401 if (!PG_ARGISNULL(3)) {
402 dstnband = PG_GETARG_INT32(3);
406 elog(NOTICE,
"Invalid band index for destination raster (must be 1-based). Returning original raster");
407 if (raster != NULL) {
409 PG_RETURN_POINTER(pgraster);
419 if (raster != NULL) {
422 if (dstnumbands < 1) {
427 dstnband = dstnumbands + 1;
428 else if (dstnband > dstnumbands) {
429 elog(NOTICE,
"Band index provided for destination raster is greater than the number of bands in the raster. Bands will be appended");
431 dstnband = dstnumbands + 1;
439 array = PG_GETARG_ARRAYTYPE_P(1);
440 etype = ARR_ELEMTYPE(array);
441 get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
443 deconstruct_array(array, etype, typlen, typbyval, typalign, &e,
452 for (i = 0; i < n; i++) {
453 if (nulls[i])
continue;
463 if (pgraster != NULL)
464 PG_FREE_IF_COPY(pgraster, 0);
465 elog(ERROR,
"RASTER_addBandRasterArray: Could not deserialize source raster at index %d", i + 1);
473 if (srcnband > srcnumbands - 1) {
474 elog(NOTICE,
"Invalid band index for source raster at index %d. Returning original raster", i + 1);
478 if (raster != NULL) {
480 PG_RETURN_POINTER(pgraster);
487 if (raster == NULL) {
494 if (raster == NULL) {
497 if (pgraster != NULL)
498 PG_FREE_IF_COPY(pgraster, 0);
499 elog(ERROR,
"RASTER_addBandRasterArray: Could not create raster from source raster at index %d", i + 1);
512 elog(NOTICE,
"Could not add band from source raster at index %d to destination raster. Returning original raster", i + 1);
516 if (pgraster != NULL)
517 PG_RETURN_POINTER(pgraster);
527 if (raster != NULL) {
530 if (pgraster != NULL)
531 PG_FREE_IF_COPY(pgraster, 0);
535 SET_VARSIZE(pgrtn, pgrtn->
size);
536 PG_RETURN_POINTER(pgrtn);
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,...)
int rt_raster_copy_band(rt_raster torast, rt_raster fromrast, int fromindex, int toindex)
Copy one band from one raster to another.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
#define POSTGIS_RT_DEBUG(level, msg)
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.