PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ _rti_iterator_arg_populate()

static int _rti_iterator_arg_populate ( _rti_iterator_arg  _param,
rt_iterator  itrset,
uint16_t  itrcount,
uint16_t  distancex,
uint16_t  distancey,
int *  allnull,
int *  allempty 
)
static

Definition at line 531 of file rt_mapalgebra.c.

536  {
537  int i = 0;
538  int hasband = 0;
539 
540  _param->count = itrcount;
541  _param->distance.x = distancex;
542  _param->distance.y = distancey;
543  _param->dimension.columns = distancex * 2 + 1;
544  _param->dimension.rows = distancey * 2 + 1;
545 
546  /* allocate memory for children */
547  _param->raster = rtalloc(sizeof(rt_raster) * itrcount);
548  _param->isempty = rtalloc(sizeof(int) * itrcount);
549  _param->width = rtalloc(sizeof(int) * itrcount);
550  _param->height = rtalloc(sizeof(int) * itrcount);
551 
552  _param->offset = rtalloc(sizeof(double *) * itrcount);
553 
554  _param->band.rtband = rtalloc(sizeof(rt_band) * itrcount);
555  _param->band.hasnodata = rtalloc(sizeof(int) * itrcount);
556  _param->band.isnodata = rtalloc(sizeof(int) * itrcount);
557  _param->band.nodataval = rtalloc(sizeof(double) * itrcount);
558  _param->band.minval = rtalloc(sizeof(double) * itrcount);
559 
560  if (
561  _param->raster == NULL ||
562  _param->isempty == NULL ||
563  _param->width == NULL ||
564  _param->height == NULL ||
565  _param->offset == NULL ||
566  _param->band.rtband == NULL ||
567  _param->band.hasnodata == NULL ||
568  _param->band.isnodata == NULL ||
569  _param->band.nodataval == NULL ||
570  _param->band.minval == NULL
571  ) {
572  rterror("_rti_iterator_arg_populate: Could not allocate memory for children of _rti_iterator_arg");
573  return 0;
574  }
575 
576  *allnull = 0;
577  *allempty = 0;
578 
579  /*
580  check input rasters
581  not empty, band # is valid
582  copy raster pointers and set flags
583  */
584  for (i = 0; i < itrcount; i++) {
585  /* initialize elements */
586  _param->raster[i] = NULL;
587  _param->isempty[i] = 0;
588  _param->width[i] = 0;
589  _param->height[i] = 0;
590 
591  _param->offset[i] = NULL;
592 
593  _param->band.rtband[i] = NULL;
594  _param->band.hasnodata[i] = 0;
595  _param->band.isnodata[i] = 0;
596  _param->band.nodataval[i] = 0;
597  _param->band.minval[i] = 0;
598 
599  /* set isempty */
600  if (itrset[i].raster == NULL) {
601  _param->isempty[i] = 1;
602 
603  (*allnull)++;
604  (*allempty)++;
605 
606  continue;
607  }
608  else if (rt_raster_is_empty(itrset[i].raster)) {
609  _param->isempty[i] = 1;
610 
611  (*allempty)++;
612 
613  continue;
614  }
615 
616  /* check band number */
617  hasband = rt_raster_has_band(itrset[i].raster, itrset[i].nband);
618  if (!hasband) {
619  if (!itrset[i].nbnodata) {
620  rterror("_rti_iterator_arg_populate: Band %d not found for raster %d", itrset[i].nband, i);
621  return 0;
622  }
623  else {
624  RASTER_DEBUGF(4, "Band %d not found for raster %d. Using NODATA", itrset[i].nband, i);
625  }
626  }
627 
628  _param->raster[i] = itrset[i].raster;
629  if (hasband) {
630  _param->band.rtband[i] = rt_raster_get_band(itrset[i].raster, itrset[i].nband);
631  if (_param->band.rtband[i] == NULL) {
632  rterror("_rti_iterator_arg_populate: Could not get band %d for raster %d", itrset[i].nband, i);
633  return 0;
634  }
635 
636  /* hasnodata */
637  _param->band.hasnodata[i] = rt_band_get_hasnodata_flag(_param->band.rtband[i]);
638 
639  /* hasnodata = TRUE */
640  if (_param->band.hasnodata[i]) {
641  /* nodataval */
642  rt_band_get_nodata(_param->band.rtband[i], &(_param->band.nodataval[i]));
643 
644  /* isnodata */
645  _param->band.isnodata[i] = rt_band_get_isnodata_flag(_param->band.rtband[i]);
646  }
647  /* hasnodata = FALSE */
648  else {
649  /* minval */
650  _param->band.minval[i] = rt_band_get_min_value(_param->band.rtband[i]);
651  }
652  }
653 
654  /* width, height */
655  _param->width[i] = rt_raster_get_width(_param->raster[i]);
656  _param->height[i] = rt_raster_get_height(_param->raster[i]);
657 
658  /* init offset */
659  _param->offset[i] = rtalloc(sizeof(double) * 2);
660  if (_param->offset[i] == NULL) {
661  rterror("_rti_iterator_arg_populate: Could not allocate memory for offsets");
662  return 0;
663  }
664  }
665 
666  return 1;
667 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:674
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition: rt_band.c:714
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Definition: rt_raster.c:1347
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
Definition: rt_band.c:1745
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1730
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_raster.c:1334
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
nband
Definition: pixval.py:52
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
struct _rti_iterator_arg_t::@10 band
struct _rti_iterator_arg_t::@11 distance
struct _rti_iterator_arg_t::@12 dimension
rt_raster raster
Definition: librtcore.h:2443

References _rti_iterator_arg_t::band, _rti_iterator_arg_t::columns, _rti_iterator_arg_t::count, _rti_iterator_arg_t::dimension, _rti_iterator_arg_t::distance, _rti_iterator_arg_t::hasnodata, _rti_iterator_arg_t::height, _rti_iterator_arg_t::isempty, _rti_iterator_arg_t::isnodata, _rti_iterator_arg_t::minval, pixval::nband, _rti_iterator_arg_t::nodataval, _rti_iterator_arg_t::offset, rt_iterator_t::raster, _rti_iterator_arg_t::raster, rtrowdump::raster, RASTER_DEBUGF, _rti_iterator_arg_t::rows, rt_band_get_hasnodata_flag(), rt_band_get_isnodata_flag(), rt_band_get_min_value(), rt_band_get_nodata(), rt_raster_get_band(), rt_raster_get_height(), rt_raster_get_width(), rt_raster_has_band(), rt_raster_is_empty(), rtalloc(), _rti_iterator_arg_t::rtband, rterror(), _rti_iterator_arg_t::width, _rti_iterator_arg_t::x, and _rti_iterator_arg_t::y.

Referenced by rt_raster_iterator().

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