PostGIS  2.4.9dev-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 1787 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().

1790  {
1791  rtpg_union_type *utype = (rtpg_union_type *) userarg;
1792 
1793  if (arg == NULL)
1794  return 0;
1795 
1796  if (
1797  arg->rasters != 2 ||
1798  arg->rows != 1 ||
1799  arg->columns != 1
1800  ) {
1801  elog(ERROR, "rtpg_union_callback: Invalid arguments passed to callback");
1802  return 0;
1803  }
1804 
1805  *value = 0;
1806  *nodata = 0;
1807 
1808  /* handle NODATA situations except for COUNT, which is a special case */
1809  if (*utype != UT_COUNT) {
1810  /* both NODATA */
1811  if (arg->nodata[0][0][0] && arg->nodata[1][0][0]) {
1812  *nodata = 1;
1813  POSTGIS_RT_DEBUGF(4, "value, nodata = %f, %d", *value, *nodata);
1814  return 1;
1815  }
1816  /* second NODATA */
1817  else if (!arg->nodata[0][0][0] && arg->nodata[1][0][0]) {
1818  *value = arg->values[0][0][0];
1819  POSTGIS_RT_DEBUGF(4, "value, nodata = %f, %d", *value, *nodata);
1820  return 1;
1821  }
1822  /* first NODATA */
1823  else if (arg->nodata[0][0][0] && !arg->nodata[1][0][0]) {
1824  *value = arg->values[1][0][0];
1825  POSTGIS_RT_DEBUGF(4, "value, nodata = %f, %d", *value, *nodata);
1826  return 1;
1827  }
1828  }
1829 
1830  switch (*utype) {
1831  case UT_FIRST:
1832  *value = arg->values[0][0][0];
1833  break;
1834  case UT_MIN:
1835  if (arg->values[0][0][0] < arg->values[1][0][0])
1836  *value = arg->values[0][0][0];
1837  else
1838  *value = arg->values[1][0][0];
1839  break;
1840  case UT_MAX:
1841  if (arg->values[0][0][0] > arg->values[1][0][0])
1842  *value = arg->values[0][0][0];
1843  else
1844  *value = arg->values[1][0][0];
1845  break;
1846  case UT_COUNT:
1847  /* both NODATA */
1848  if (arg->nodata[0][0][0] && arg->nodata[1][0][0])
1849  *value = 0;
1850  /* second NODATA */
1851  else if (!arg->nodata[0][0][0] && arg->nodata[1][0][0])
1852  *value = arg->values[0][0][0];
1853  /* first NODATA */
1854  else if (arg->nodata[0][0][0] && !arg->nodata[1][0][0])
1855  *value = 1;
1856  /* has value, increment */
1857  else
1858  *value = arg->values[0][0][0] + 1;
1859  break;
1860  case UT_SUM:
1861  *value = arg->values[0][0][0] + arg->values[1][0][0];
1862  break;
1863  case UT_MEAN:
1864  case UT_RANGE:
1865  break;
1866  case UT_LAST:
1867  default:
1868  *value = arg->values[1][0][0];
1869  break;
1870  }
1871 
1872  POSTGIS_RT_DEBUGF(4, "value, nodata = %f, %d", *value, *nodata);
1873 
1874 
1875  return 1;
1876 }
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
int value
Definition: genraster.py:61
Here is the caller graph for this function: