PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ rt_raster_add_band()

int rt_raster_add_band ( rt_raster  raster,
rt_band  band,
int  index 
)

Add band data to a raster.

Parameters
raster: the raster to add a band to
band: the band to add, ownership left to caller. Band dimensions are required to match with raster ones.
index: the position where to insert the new band (0 based)
Returns
identifier (position) for the just-added raster, or -1 on error

Definition at line 409 of file rt_raster.c.

409  {
410  rt_band *oldbands = NULL;
411  rt_band oldband = NULL;
412  rt_band tmpband = NULL;
413  uint16_t i = 0;
414 
415  assert(NULL != raster);
416  assert(NULL != band);
417 
418  RASTER_DEBUGF(3, "Adding band %p to raster %p", band, raster);
419 
420  if (band->width != raster->width || band->height != raster->height) {
421  rterror("rt_raster_add_band: Can't add a %dx%d band to a %dx%d raster",
422  band->width, band->height, raster->width, raster->height);
423  return -1;
424  }
425 
426  if (index > raster->numBands)
427  index = raster->numBands;
428 
429  if (index < 0)
430  index = 0;
431 
432  oldbands = raster->bands;
433 
434  RASTER_DEBUGF(3, "Oldbands at %p", oldbands);
435 
436  raster->bands = (rt_band*) rtrealloc(raster->bands,
437  sizeof (rt_band)*(raster->numBands + 1)
438  );
439 
440  RASTER_DEBUG(3, "Checking bands");
441 
442  if (NULL == raster->bands) {
443  rterror("rt_raster_add_band: Out of virtual memory "
444  "reallocating band pointers");
445  raster->bands = oldbands;
446  return -1;
447  }
448 
449  RASTER_DEBUGF(4, "realloc returned %p", raster->bands);
450 
451  for (i = 0; i <= raster->numBands; ++i) {
452  if (i == index) {
453  oldband = raster->bands[i];
454  raster->bands[i] = band;
455  } else if (i > index) {
456  tmpband = raster->bands[i];
457  raster->bands[i] = oldband;
458  oldband = tmpband;
459  }
460  }
461 
462  band->raster = raster;
463 
464  raster->numBands++;
465 
466  RASTER_DEBUGF(4, "Raster now has %d bands", raster->numBands);
467 
468  return index;
469 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:219
#define RASTER_DEBUG(level, msg)
Definition: librtcore.h:302
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:306
void * rtrealloc(void *mem, size_t size)
Definition: rt_context.c:199
band
Definition: ovdump.py:58
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121

References ovdump::band, rtrowdump::raster, RASTER_DEBUG, RASTER_DEBUGF, rterror(), and rtrealloc().

Referenced by cu_add_band(), RASTER_addBandOutDB(), RASTER_tile(), rt_raster_colormap(), rt_raster_copy_band(), rt_raster_generate_new_band(), and test_band_metadata().

Here is the call graph for this function:
Here is the caller graph for this function: