PostGIS  2.5.7dev-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 1435 of file rt_raster.c.

1435  {
1436  rt_raster rast = NULL;
1437  int i = 0;
1438  int j = 0;
1439  int idx;
1440  int32_t flag;
1441  double gt[6] = {0.};
1442 
1443  assert(NULL != raster);
1444  assert(NULL != bandNums);
1445 
1446  RASTER_DEBUGF(3, "rt_raster_from_band: source raster has %d bands",
1448 
1449  /* create new raster */
1450  rast = rt_raster_new(raster->width, raster->height);
1451  if (NULL == rast) {
1452  rterror("rt_raster_from_band: Out of memory allocating new raster");
1453  return NULL;
1454  }
1455 
1456  /* copy raster attributes */
1459 
1460  /* srid */
1461  rt_raster_set_srid(rast, raster->srid);
1462 
1463  /* copy bands */
1464  for (i = 0; i < count; i++) {
1465  idx = bandNums[i];
1466  flag = rt_raster_copy_band(rast, raster, idx, i);
1467 
1468  if (flag < 0) {
1469  rterror("rt_raster_from_band: Could not copy band");
1470  for (j = 0; j < i; j++) rt_band_destroy(rast->bands[j]);
1472  return NULL;
1473  }
1474 
1475  RASTER_DEBUGF(3, "rt_raster_from_band: band created at index %d",
1476  flag);
1477  }
1478 
1479  RASTER_DEBUGF(3, "rt_raster_from_band: new raster has %d bands",
1481  return rast;
1482 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:340
int count
Definition: genraster.py:56
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
gt
Definition: window.py:77
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
Definition: rt_raster.c:727
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
Definition: rt_raster.c:363
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:1370
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_raster.c:706

References genraster::count, window::gt, rtpixdump::rast, rtrowdump::raster, 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(), and rterror().

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

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