PostGIS  2.4.9dev-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 405 of file rt_raster.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().

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