PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 5706 of file rt_api.c.

References ovdump::band, rt_raster_t::bands, rt_raster_t::height, rt_band_t::height, rt_raster_t::numBands, rtrowdump::raster, rt_band_t::raster, RASTER_DEBUG, RASTER_DEBUGF, rterror(), rtrealloc(), rt_raster_t::width, and rt_band_t::width.

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

5706  {
5707  rt_band *oldbands = NULL;
5708  rt_band oldband = NULL;
5709  rt_band tmpband = NULL;
5710  uint16_t i = 0;
5711 
5712 
5713 
5714  assert(NULL != raster);
5715  assert(NULL != band);
5716 
5717  RASTER_DEBUGF(3, "Adding band %p to raster %p", band, raster);
5718 
5719  if (band->width != raster->width || band->height != raster->height) {
5720  rterror("rt_raster_add_band: Can't add a %dx%d band to a %dx%d raster",
5721  band->width, band->height, raster->width, raster->height);
5722  return -1;
5723  }
5724 
5725  if (index > raster->numBands)
5726  index = raster->numBands;
5727 
5728  if (index < 0)
5729  index = 0;
5730 
5731  oldbands = raster->bands;
5732 
5733  RASTER_DEBUGF(3, "Oldbands at %p", oldbands);
5734 
5735  raster->bands = (rt_band*) rtrealloc(raster->bands,
5736  sizeof (rt_band)*(raster->numBands + 1)
5737  );
5738 
5739  RASTER_DEBUG(3, "Checking bands");
5740 
5741  if (NULL == raster->bands) {
5742  rterror("rt_raster_add_band: Out of virtual memory "
5743  "reallocating band pointers");
5744  raster->bands = oldbands;
5745  return -1;
5746  }
5747 
5748  RASTER_DEBUGF(4, "realloc returned %p", raster->bands);
5749 
5750  for (i = 0; i <= raster->numBands; ++i) {
5751  if (i == index) {
5752  oldband = raster->bands[i];
5753  raster->bands[i] = band;
5754  } else if (i > index) {
5755  tmpband = raster->bands[i];
5756  raster->bands[i] = oldband;
5757  oldband = tmpband;
5758  }
5759  }
5760 
5761  band->raster = raster;
5762 
5763  raster->numBands++;
5764 
5765  RASTER_DEBUGF(4, "Raster now has %d bands", raster->numBands);
5766 
5767  return index;
5768 }
uint16_t numBands
Definition: rt_api.h:2215
rt_raster raster
Definition: rt_api.h:2249
tuple band
Definition: ovdump.py:57
uint16_t height
Definition: rt_api.h:2242
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
uint16_t height
Definition: rt_api.h:2227
#define RASTER_DEBUG(level, msg)
Definition: rt_api.h:281
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
uint16_t width
Definition: rt_api.h:2226
uint16_t width
Definition: rt_api.h:2241
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
rt_band * bands
Definition: rt_api.h:2228
void * rtrealloc(void *mem, size_t size)
Definition: rt_api.c:875

Here is the call graph for this function:

Here is the caller graph for this function: