PostGIS  2.1.10dev-r@@SVN_REVISION@@
int rt_raster_copy_band ( rt_raster  torast,
rt_raster  fromrast,
int  fromindex,
int  toindex 
)

Copy one band from one raster to another.

Bands are duplicated from fromrast to torast using rt_band_duplicate. The caller will need to ensure that the copied band's data or path remains allocated for the lifetime of the copied bands.

Parameters
torast: raster to copy band to
fromrast: raster to copy band from
fromindex: index of band in source raster, 0-based
toindex: index of new band in destination raster, 0-based
Returns
The band index of the second raster where the new band is copied. -1 if error

Definition at line 8582 of file rt_api.c.

References rt_raster_t::height, rt_raster_t::numBands, rt_band_duplicate(), rt_raster_add_band(), rt_raster_get_band(), rtwarn(), and rt_raster_t::width.

Referenced by RASTER_addBandRasterArray(), RASTER_copyBand(), RASTER_mapAlgebraExpr(), RASTER_union_finalfn(), and rt_raster_from_band().

8585  {
8586  rt_band srcband = NULL;
8587  rt_band dstband = NULL;
8588 
8589  assert(NULL != torast);
8590  assert(NULL != fromrast);
8591 
8592  /* Check raster dimensions */
8593  if (torast->height != fromrast->height || torast->width != fromrast->width) {
8594  rtwarn("rt_raster_copy_band: Attempting to add a band with different width or height");
8595  return -1;
8596  }
8597 
8598  /* Check bands limits */
8599  if (fromrast->numBands < 1) {
8600  rtwarn("rt_raster_copy_band: Second raster has no band");
8601  return -1;
8602  }
8603  else if (fromindex < 0) {
8604  rtwarn("rt_raster_copy_band: Band index for second raster < 0. Defaulted to 0");
8605  fromindex = 0;
8606  }
8607  else if (fromindex >= fromrast->numBands) {
8608  rtwarn("rt_raster_copy_band: Band index for second raster > number of bands, truncated from %u to %u", fromindex, fromrast->numBands - 1);
8609  fromindex = fromrast->numBands - 1;
8610  }
8611 
8612  if (toindex < 0) {
8613  rtwarn("rt_raster_copy_band: Band index for first raster < 0. Defaulted to 0");
8614  toindex = 0;
8615  }
8616  else if (toindex > torast->numBands) {
8617  rtwarn("rt_raster_copy_band: Band index for first raster > number of bands, truncated from %u to %u", toindex, torast->numBands);
8618  toindex = torast->numBands;
8619  }
8620 
8621  /* Get band from source raster */
8622  srcband = rt_raster_get_band(fromrast, fromindex);
8623 
8624  /* duplicate band */
8625  dstband = rt_band_duplicate(srcband);
8626 
8627  /* Add band to the second raster */
8628  return rt_raster_add_band(torast, dstband, toindex);
8629 }
uint16_t numBands
Definition: rt_api.h:2215
rt_band rt_band_duplicate(rt_band band)
Create a new band duplicated from source band.
Definition: rt_api.c:1594
uint16_t height
Definition: rt_api.h:2227
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
Definition: rt_api.c:5706
void rtwarn(const char *fmt,...)
Definition: rt_api.c:920
uint16_t width
Definition: rt_api.h:2226
rt_band rt_raster_get_band(rt_raster raster, int n)
Return Nth band, or NULL if unavailable.
Definition: rt_api.c:5686

Here is the call graph for this function:

Here is the caller graph for this function: