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.
405 {
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
417 rterror(
"rt_raster_add_band: Can't add a %dx%d band to a %dx%d raster",
419 return -1;
420 }
421
422 if (index >
raster->numBands)
424
425 if (index < 0)
426 index = 0;
427
429
431
434 );
435
437
438 if (NULL ==
raster->bands) {
439 rterror(
"rt_raster_add_band: Out of virtual memory "
440 "reallocating band pointers");
442 return -1;
443 }
444
446
447 for (i = 0; i <=
raster->numBands; ++i) {
448 if (i == index) {
449 oldband =
raster->bands[i];
451 } else if (i > index) {
452 tmpband =
raster->bands[i];
453 raster->bands[i] = oldband;
454 oldband = tmpband;
455 }
456 }
457
459
461
463
464 return index;
465}
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
#define RASTER_DEBUG(level, msg)
#define RASTER_DEBUGF(level, msg,...)
void * rtrealloc(void *mem, size_t size)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
References RASTER_DEBUG, RASTER_DEBUGF, rterror(), and rtrealloc().
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().