PostGIS  2.1.10dev-r@@SVN_REVISION@@
static int rtpg_nmapalgebra_callback ( rt_iterator_arg  arg,
void *  userarg,
double *  value,
int *  nodata 
)
static

Definition at line 16539 of file rt_pg.c.

References rt_iterator_arg_t::columns, rt_iterator_arg_t::dst_pixel, if(), rt_iterator_arg_t::nodata, POSTGIS_RT_DEBUGF, rt_iterator_arg_t::rasters, rt_iterator_arg_t::rows, rt_iterator_arg_t::src_pixel, rtpg_nmapalgebra_callback_arg::ufc_info, rtpg_nmapalgebra_callback_arg::ufc_rettype, rt_iterator_arg_t::values, pixval::x, and pixval::y.

Referenced by RASTER_nMapAlgebra().

16542  {
16544 
16545  int16 typlen;
16546  bool typbyval;
16547  char typalign;
16548 
16549  ArrayType *mdValues = NULL;
16550  Datum *_values = NULL;
16551  bool *_nodata = NULL;
16552 
16553  ArrayType *mdPos = NULL;
16554  Datum *_pos = NULL;
16555  bool *_null = NULL;
16556 
16557  int i = 0;
16558  int x = 0;
16559  int y = 0;
16560  int z = 0;
16561  int dim[3] = {0};
16562  int lbound[3] = {1, 1, 1};
16563  Datum datum = (Datum) NULL;
16564 
16565  if (arg == NULL)
16566  return 0;
16567 
16568  *value = 0;
16569  *nodata = 0;
16570 
16571  dim[0] = arg->rasters;
16572  dim[1] = arg->rows;
16573  dim[2] = arg->columns;
16574 
16575  _values = palloc(sizeof(Datum) * arg->rasters * arg->rows * arg->columns);
16576  _nodata = palloc(sizeof(bool) * arg->rasters * arg->rows * arg->columns);
16577  if (_values == NULL || _nodata == NULL) {
16578  elog(ERROR, "rtpg_nmapalgebra_callback: Could not allocate memory for values array");
16579  return 0;
16580  }
16581 
16582  /* build mdValues */
16583  i = 0;
16584  /* raster */
16585  for (z = 0; z < arg->rasters; z++) {
16586  /* Y axis */
16587  for (y = 0; y < arg->rows; y++) {
16588  /* X axis */
16589  for (x = 0; x < arg->columns; x++) {
16590  POSTGIS_RT_DEBUGF(4, "(z, y ,x) = (%d, %d, %d)", z, y, x);
16591  POSTGIS_RT_DEBUGF(4, "(value, nodata) = (%f, %d)", arg->values[z][y][x], arg->nodata[z][y][x]);
16592 
16593  _nodata[i] = (bool) arg->nodata[z][y][x];
16594  if (!_nodata[i])
16595  _values[i] = Float8GetDatum(arg->values[z][y][x]);
16596  else
16597  _values[i] = (Datum) NULL;
16598 
16599  i++;
16600  }
16601  }
16602  }
16603 
16604  /* info about the type of item in the multi-dimensional array (float8). */
16605  get_typlenbyvalalign(FLOAT8OID, &typlen, &typbyval, &typalign);
16606 
16607  /* construct mdValues */
16608  mdValues = construct_md_array(
16609  _values, _nodata,
16610  3, dim, lbound,
16611  FLOAT8OID,
16612  typlen, typbyval, typalign
16613  );
16614  pfree(_nodata);
16615  pfree(_values);
16616 
16617  _pos = palloc(sizeof(Datum) * (arg->rasters + 1) * 2);
16618  _null = palloc(sizeof(bool) * (arg->rasters + 1) * 2);
16619  if (_pos == NULL || _null == NULL) {
16620  pfree(mdValues);
16621  elog(ERROR, "rtpg_nmapalgebra_callback: Could not allocate memory for position array");
16622  return 0;
16623  }
16624  memset(_null, 0, sizeof(bool) * (arg->rasters + 1) * 2);
16625 
16626  /* build mdPos */
16627  i = 0;
16628  _pos[i] = arg->dst_pixel[0] + 1;
16629  i++;
16630  _pos[i] = arg->dst_pixel[1] + 1;
16631  i++;
16632 
16633  for (z = 0; z < arg->rasters; z++) {
16634  _pos[i] = arg->src_pixel[z][0] + 1;
16635  i++;
16636 
16637  _pos[i] = arg->src_pixel[z][1] + 1;
16638  i++;
16639  }
16640 
16641  /* info about the type of item in the multi-dimensional array (int4). */
16642  get_typlenbyvalalign(INT4OID, &typlen, &typbyval, &typalign);
16643 
16644  /* reuse dim and lbound, just tweak to what we need */
16645  dim[0] = arg->rasters + 1;
16646  dim[1] = 2;
16647  lbound[0] = 0;
16648 
16649  /* construct mdPos */
16650  mdPos = construct_md_array(
16651  _pos, _null,
16652  2, dim, lbound,
16653  INT4OID,
16654  typlen, typbyval, typalign
16655  );
16656  pfree(_pos);
16657  pfree(_null);
16658 
16659  callback->ufc_info.arg[0] = PointerGetDatum(mdValues);
16660  callback->ufc_info.arg[1] = PointerGetDatum(mdPos);
16661 
16662  /* call user callback function */
16663  datum = FunctionCallInvoke(&(callback->ufc_info));
16664  pfree(mdValues);
16665  pfree(mdPos);
16666 
16667  /* result is not null*/
16668  if (!callback->ufc_info.isnull) {
16669  switch (callback->ufc_rettype) {
16670  case FLOAT8OID:
16671  *value = DatumGetFloat8(datum);
16672  break;
16673  case FLOAT4OID:
16674  *value = (double) DatumGetFloat4(datum);
16675  break;
16676  case INT4OID:
16677  *value = (double) DatumGetInt32(datum);
16678  break;
16679  case INT2OID:
16680  *value = (double) DatumGetInt16(datum);
16681  break;
16682  }
16683  }
16684  else
16685  *nodata = 1;
16686 
16687  return 1;
16688 }
int ** src_pixel
Definition: rt_api.h:2381
uint32_t rows
Definition: rt_api.h:2370
uint32_t columns
Definition: rt_api.h:2372
uint16_t rasters
Definition: rt_api.h:2368
tuple x
Definition: pixval.py:53
double *** values
Definition: rt_api.h:2376
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rt_pg.h:62
int *** nodata
Definition: rt_api.h:2378
int dst_pixel[2]
Definition: rt_api.h:2384
tuple y
Definition: pixval.py:54
if(!(yy_init))
Definition: lwin_wkt_lex.c:860
FunctionCallInfoData ufc_info
Definition: rt_pg.c:16276

Here is the call graph for this function:

Here is the caller graph for this function: