PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ rtpg_union_unionarg_process()

static int rtpg_union_unionarg_process ( rtpg_union_arg  arg,
ArrayType *  array 
)
static

Definition at line 1900 of file rtpg_mapalgebra.c.

References rtpg_union_arg_t::bandarg, pixval::nband, rtpg_union_band_arg_t::nband, rtpg_union_arg_t::numband, rtpg_union_band_arg_t::numraster, POSTGIS_RT_DEBUGF, rtpg_union_band_arg_t::raster, rtpg_strtoupper(), rtpg_uniontype_index_from_name(), rtpg_union_band_arg_t::uniontype, UT_LAST, UT_MEAN, and UT_RANGE.

Referenced by RASTER_union_transfn().

1900  {
1901  Oid etype;
1902  Datum *e;
1903  bool *nulls;
1904  int16 typlen;
1905  bool typbyval;
1906  char typalign;
1907  int n = 0;
1908 
1909  HeapTupleHeader tup;
1910  bool isnull;
1911  Datum tupv;
1912 
1913  int i;
1914  int nband = 1;
1915  char *utypename = NULL;
1916  rtpg_union_type utype = UT_LAST;
1917 
1918  etype = ARR_ELEMTYPE(array);
1919  get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
1920 
1921  deconstruct_array(
1922  array,
1923  etype,
1924  typlen, typbyval, typalign,
1925  &e, &nulls, &n
1926  );
1927 
1928  if (!n) {
1929  elog(ERROR, "rtpg_union_unionarg_process: Invalid argument for unionarg");
1930  return 0;
1931  }
1932 
1933  /* prep arg */
1934  arg->numband = n;
1935  arg->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * arg->numband);
1936  if (arg->bandarg == NULL) {
1937  elog(ERROR, "rtpg_union_unionarg_process: Could not allocate memory for band information");
1938  return 0;
1939  }
1940 
1941  /* process each element */
1942  for (i = 0; i < n; i++) {
1943  if (nulls[i]) {
1944  arg->numband--;
1945  continue;
1946  }
1947 
1948  POSTGIS_RT_DEBUGF(4, "Processing unionarg at index %d", i);
1949 
1950  /* each element is a tuple */
1951  tup = (HeapTupleHeader) DatumGetPointer(e[i]);
1952  if (NULL == tup) {
1953  elog(ERROR, "rtpg_union_unionarg_process: Invalid argument for unionarg");
1954  return 0;
1955  }
1956 
1957  /* first element, bandnum */
1958  tupv = GetAttributeByName(tup, "nband", &isnull);
1959  if (isnull) {
1960  nband = i + 1;
1961  elog(NOTICE, "First argument (nband) of unionarg is NULL. Assuming nband = %d", nband);
1962  }
1963  else
1964  nband = DatumGetInt32(tupv);
1965 
1966  if (nband < 1) {
1967  elog(ERROR, "rtpg_union_unionarg_process: Band number must be greater than zero (1-based)");
1968  return 0;
1969  }
1970 
1971  /* second element, uniontype */
1972  tupv = GetAttributeByName(tup, "uniontype", &isnull);
1973  if (isnull) {
1974  elog(NOTICE, "Second argument (uniontype) of unionarg is NULL. Assuming uniontype = LAST");
1975  utype = UT_LAST;
1976  }
1977  else {
1978  utypename = text_to_cstring((text *) DatumGetPointer(tupv));
1979  utype = rtpg_uniontype_index_from_name(rtpg_strtoupper(utypename));
1980  }
1981 
1982  arg->bandarg[i].uniontype = utype;
1983  arg->bandarg[i].nband = nband - 1;
1984  arg->bandarg[i].raster = NULL;
1985 
1986  if (
1987  utype != UT_MEAN &&
1988  utype != UT_RANGE
1989  ) {
1990  arg->bandarg[i].numraster = 1;
1991  }
1992  else
1993  arg->bandarg[i].numraster = 2;
1994  }
1995 
1996  if (arg->numband < n) {
1997  arg->bandarg = repalloc(arg->bandarg, sizeof(struct rtpg_union_band_arg_t) * arg->numband);
1998  if (arg->bandarg == NULL) {
1999  elog(ERROR, "rtpg_union_unionarg_process: Could not reallocate memory for band information");
2000  return 0;
2001  }
2002  }
2003 
2004  return 1;
2005 }
rtpg_union_band_arg bandarg
rtpg_union_type
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:57
nband
Definition: pixval.py:52
static rtpg_union_type rtpg_uniontype_index_from_name(const char *cutype)
rtpg_union_type uniontype
char * rtpg_strtoupper(char *str)
Here is the call graph for this function:
Here is the caller graph for this function: