PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ rtpg_union_callback()

static int rtpg_union_callback ( rt_iterator_arg  arg,
void *  userarg,
double *  value,
int *  nodata 
)
static

Definition at line 1732 of file rtpg_mapalgebra.c.

References rt_iterator_arg_t::columns, rt_iterator_arg_t::nodata, POSTGIS_RT_DEBUGF, rt_iterator_arg_t::rasters, rt_iterator_arg_t::rows, UT_COUNT, UT_FIRST, UT_LAST, UT_MAX, UT_MEAN, UT_MIN, UT_RANGE, UT_SUM, and rt_iterator_arg_t::values.

Referenced by RASTER_union_transfn().

1735  {
1736  rtpg_union_type *utype = (rtpg_union_type *) userarg;
1737 
1738  if (arg == NULL)
1739  return 0;
1740 
1741  if (
1742  arg->rasters != 2 ||
1743  arg->rows != 1 ||
1744  arg->columns != 1
1745  ) {
1746  elog(ERROR, "rtpg_union_callback: Invalid arguments passed to callback");
1747  return 0;
1748  }
1749 
1750  *value = 0;
1751  *nodata = 0;
1752 
1753  /* handle NODATA situations except for COUNT, which is a special case */
1754  if (*utype != UT_COUNT) {
1755  /* both NODATA */
1756  if (arg->nodata[0][0][0] && arg->nodata[1][0][0]) {
1757  *nodata = 1;
1758  POSTGIS_RT_DEBUGF(4, "value, nodata = %f, %d", *value, *nodata);
1759  return 1;
1760  }
1761  /* second NODATA */
1762  else if (!arg->nodata[0][0][0] && arg->nodata[1][0][0]) {
1763  *value = arg->values[0][0][0];
1764  POSTGIS_RT_DEBUGF(4, "value, nodata = %f, %d", *value, *nodata);
1765  return 1;
1766  }
1767  /* first NODATA */
1768  else if (arg->nodata[0][0][0] && !arg->nodata[1][0][0]) {
1769  *value = arg->values[1][0][0];
1770  POSTGIS_RT_DEBUGF(4, "value, nodata = %f, %d", *value, *nodata);
1771  return 1;
1772  }
1773  }
1774 
1775  switch (*utype) {
1776  case UT_FIRST:
1777  *value = arg->values[0][0][0];
1778  break;
1779  case UT_MIN:
1780  if (arg->values[0][0][0] < arg->values[1][0][0])
1781  *value = arg->values[0][0][0];
1782  else
1783  *value = arg->values[1][0][0];
1784  break;
1785  case UT_MAX:
1786  if (arg->values[0][0][0] > arg->values[1][0][0])
1787  *value = arg->values[0][0][0];
1788  else
1789  *value = arg->values[1][0][0];
1790  break;
1791  case UT_COUNT:
1792  /* both NODATA */
1793  if (arg->nodata[0][0][0] && arg->nodata[1][0][0])
1794  *value = 0;
1795  /* second NODATA */
1796  else if (!arg->nodata[0][0][0] && arg->nodata[1][0][0])
1797  *value = arg->values[0][0][0];
1798  /* first NODATA */
1799  else if (arg->nodata[0][0][0] && !arg->nodata[1][0][0])
1800  *value = 1;
1801  /* has value, increment */
1802  else
1803  *value = arg->values[0][0][0] + 1;
1804  break;
1805  case UT_SUM:
1806  *value = arg->values[0][0][0] + arg->values[1][0][0];
1807  break;
1808  case UT_MEAN:
1809  case UT_RANGE:
1810  break;
1811  case UT_LAST:
1812  default:
1813  *value = arg->values[1][0][0];
1814  break;
1815  }
1816 
1817  POSTGIS_RT_DEBUGF(4, "value, nodata = %f, %d", *value, *nodata);
1818 
1819 
1820  return 1;
1821 }
rtpg_union_type
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:65
uint32_t columns
Definition: librtcore.h:2455
uint16_t rasters
Definition: librtcore.h:2451
double *** values
Definition: librtcore.h:2459
int value
Definition: genraster.py:61
Here is the caller graph for this function: