PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ rt_raster_copy_band()

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 1365 of file rt_raster.c.

1368  {
1369  rt_band srcband = NULL;
1370  rt_band dstband = NULL;
1371 
1372  assert(NULL != torast);
1373  assert(NULL != fromrast);
1374 
1375  /* Check raster dimensions */
1376  if (torast->height != fromrast->height || torast->width != fromrast->width) {
1377  rtwarn("rt_raster_copy_band: Attempting to add a band with different width or height");
1378  return -1;
1379  }
1380 
1381  /* Check bands limits */
1382  if (fromrast->numBands < 1) {
1383  rtwarn("rt_raster_copy_band: Second raster has no band");
1384  return -1;
1385  }
1386  else if (fromindex < 0) {
1387  rtwarn("rt_raster_copy_band: Band index for second raster < 0. Defaulted to 0");
1388  fromindex = 0;
1389  }
1390  else if (fromindex >= fromrast->numBands) {
1391  rtwarn("rt_raster_copy_band: Band index for second raster > number of bands, truncated from %u to %u", fromindex, fromrast->numBands - 1);
1392  fromindex = fromrast->numBands - 1;
1393  }
1394 
1395  if (toindex < 0) {
1396  rtwarn("rt_raster_copy_band: Band index for first raster < 0. Defaulted to 0");
1397  toindex = 0;
1398  }
1399  else if (toindex > torast->numBands) {
1400  rtwarn("rt_raster_copy_band: Band index for first raster > number of bands, truncated from %u to %u", toindex, torast->numBands);
1401  toindex = torast->numBands;
1402  }
1403 
1404  /* Get band from source raster */
1405  srcband = rt_raster_get_band(fromrast, fromindex);
1406 
1407  /* duplicate band */
1408  dstband = rt_band_duplicate(srcband);
1409 
1410  /* Add band to the second raster */
1411  return rt_raster_add_band(torast, dstband, toindex);
1412 }
rt_band rt_band_duplicate(rt_band band)
Create a new band duplicated from source band.
Definition: rt_band.c:287
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
Definition: rt_raster.c:405
rt_band rt_raster_get_band(rt_raster raster, int n)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
uint16_t width
Definition: librtcore.h:2302
uint16_t numBands
Definition: librtcore.h:2291
uint16_t height
Definition: librtcore.h:2303

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().

Here is the call graph for this function:
Here is the caller graph for this function: