PostGIS  2.3.8dev-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 1737 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().

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