PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ rt_raster_from_band()

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 1439 of file rt_raster.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().

1439  {
1440  rt_raster rast = NULL;
1441  int i = 0;
1442  int j = 0;
1443  int idx;
1444  int32_t flag;
1445  double gt[6] = {0.};
1446 
1447  assert(NULL != raster);
1448  assert(NULL != bandNums);
1449 
1450  RASTER_DEBUGF(3, "rt_raster_from_band: source raster has %d bands",
1451  rt_raster_get_num_bands(raster));
1452 
1453  /* create new raster */
1454  rast = rt_raster_new(raster->width, raster->height);
1455  if (NULL == rast) {
1456  rterror("rt_raster_from_band: Out of memory allocating new raster");
1457  return NULL;
1458  }
1459 
1460  /* copy raster attributes */
1463 
1464  /* srid */
1465  rt_raster_set_srid(rast, raster->srid);
1466 
1467  /* copy bands */
1468  for (i = 0; i < count; i++) {
1469  idx = bandNums[i];
1470  flag = rt_raster_copy_band(rast, raster, idx, i);
1471 
1472  if (flag < 0) {
1473  rterror("rt_raster_from_band: Could not copy band");
1474  for (j = 0; j < i; j++) rt_band_destroy(rast->bands[j]);
1475  rt_raster_destroy(rast);
1476  return NULL;
1477  }
1478 
1479  RASTER_DEBUGF(3, "rt_raster_from_band: band created at index %d",
1480  flag);
1481  }
1482 
1483  RASTER_DEBUGF(3, "rt_raster_from_band: new raster has %d bands",
1484  rt_raster_get_num_bands(rast));
1485  return rast;
1486 }
int32_t srid
Definition: librtcore.h:2251
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster&#39;s SRID.
Definition: rt_raster.c:363
gt
Definition: window.py:77
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:242
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster&#39;s geotransform using 6-element array.
Definition: rt_raster.c:727
uint16_t height
Definition: librtcore.h:2253
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_raster.c:1374
uint16_t width
Definition: librtcore.h:2252
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_raster.c:706
int count
Definition: genraster.py:56
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
rt_band * bands
Definition: librtcore.h:2254
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
Here is the call graph for this function:
Here is the caller graph for this function: