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

Definition at line 1734 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().

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

Here is the caller graph for this function: