PostGIS  2.1.10dev-r@@SVN_REVISION@@
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.

Parameters
raster: the source raster
bandNums: array of band numbers to extract from source raster and add to the new raster (0 based)
count: number of elements in bandNums
Returns
a new rt_raster or NULL on error

Definition at line 8643 of file rt_api.c.

References rt_raster_t::bands, genraster::count, window::gt, rt_raster_t::height, rtpixdump::rast, RASTER_DEBUGF, rt_band_destroy(), rt_raster_copy_band(), rt_raster_destroy(), rt_raster_get_geotransform_matrix(), rt_raster_get_num_bands(), rt_raster_new(), rt_raster_set_geotransform_matrix(), rt_raster_set_srid(), rterror(), rt_raster_t::srid, and rt_raster_t::width.

Referenced by RASTER_addBandRasterArray(), RASTER_band(), RASTER_union_finalfn(), rt_raster_clone(), and test_raster_from_band().

8643  {
8644  rt_raster rast = NULL;
8645  int i = 0;
8646  int j = 0;
8647  int idx;
8648  int32_t flag;
8649  double gt[6] = {0.};
8650 
8651  assert(NULL != raster);
8652  assert(NULL != bandNums);
8653 
8654  RASTER_DEBUGF(3, "rt_raster_from_band: source raster has %d bands",
8655  rt_raster_get_num_bands(raster));
8656 
8657  /* create new raster */
8658  rast = rt_raster_new(raster->width, raster->height);
8659  if (NULL == rast) {
8660  rterror("rt_raster_from_band: Out of memory allocating new raster");
8661  return NULL;
8662  }
8663 
8664  /* copy raster attributes */
8667 
8668  /* srid */
8669  rt_raster_set_srid(rast, raster->srid);
8670 
8671  /* copy bands */
8672  for (i = 0; i < count; i++) {
8673  idx = bandNums[i];
8674  flag = rt_raster_copy_band(rast, raster, idx, i);
8675 
8676  if (flag < 0) {
8677  rterror("rt_raster_from_band: Could not copy band");
8678  for (j = 0; j < i; j++) rt_band_destroy(rast->bands[j]);
8679  rt_raster_destroy(rast);
8680  return NULL;
8681  }
8682 
8683  RASTER_DEBUGF(3, "rt_raster_from_band: band created at index %d",
8684  flag);
8685  }
8686 
8687  RASTER_DEBUGF(3, "rt_raster_from_band: new raster has %d bands",
8688  rt_raster_get_num_bands(rast));
8689  return rast;
8690 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_api.c:5677
int32_t srid
Definition: rt_api.h:2225
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
int rt_raster_copy_band(rt_raster torast, rt_raster fromrast, int fromindex, int toindex)
Copy one band from one raster to another.
Definition: rt_api.c:8582
tuple gt
Definition: window.py:79
tuple rast
Definition: rtpixdump.py:62
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
Definition: rt_api.c:5668
uint16_t height
Definition: rt_api.h:2227
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_api.c:6005
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
uint16_t width
Definition: rt_api.h:2226
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
Definition: rt_api.c:6026
int count
Definition: genraster.py:57
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_api.c:1650
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
rt_band * bands
Definition: rt_api.h:2228
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_api.c:5353

Here is the call graph for this function:

Here is the caller graph for this function: