PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ rtpg_union_unionarg_process()

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

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

1950  {
1951  Oid etype;
1952  Datum *e;
1953  bool *nulls;
1954  int16 typlen;
1955  bool typbyval;
1956  char typalign;
1957  int n = 0;
1958 
1959  HeapTupleHeader tup;
1960  bool isnull;
1961  Datum tupv;
1962 
1963  int i;
1964  int nband = 1;
1965  char *utypename = NULL;
1966  rtpg_union_type utype = UT_LAST;
1967 
1968  etype = ARR_ELEMTYPE(array);
1969  get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
1970 
1971  deconstruct_array(
1972  array,
1973  etype,
1974  typlen, typbyval, typalign,
1975  &e, &nulls, &n
1976  );
1977 
1978  if (!n) {
1979  elog(ERROR, "rtpg_union_unionarg_process: Invalid argument for unionarg");
1980  return 0;
1981  }
1982 
1983  /* prep arg */
1984  arg->numband = n;
1985  arg->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * arg->numband);
1986  if (arg->bandarg == NULL) {
1987  elog(ERROR, "rtpg_union_unionarg_process: Could not allocate memory for band information");
1988  return 0;
1989  }
1990 
1991  /* process each element */
1992  for (i = 0; i < n; i++) {
1993  if (nulls[i]) {
1994  arg->numband--;
1995  continue;
1996  }
1997 
1998  POSTGIS_RT_DEBUGF(4, "Processing unionarg at index %d", i);
1999 
2000  /* each element is a tuple */
2001  tup = (HeapTupleHeader) DatumGetPointer(e[i]);
2002  if (NULL == tup) {
2003  elog(ERROR, "rtpg_union_unionarg_process: Invalid argument for unionarg");
2004  return 0;
2005  }
2006 
2007  /* first element, bandnum */
2008  tupv = GetAttributeByName(tup, "nband", &isnull);
2009  if (isnull) {
2010  nband = i + 1;
2011  elog(NOTICE, "First argument (nband) of unionarg is NULL. Assuming nband = %d", nband);
2012  }
2013  else
2014  nband = DatumGetInt32(tupv);
2015 
2016  if (nband < 1) {
2017  elog(ERROR, "rtpg_union_unionarg_process: Band number must be greater than zero (1-based)");
2018  return 0;
2019  }
2020 
2021  /* second element, uniontype */
2022  tupv = GetAttributeByName(tup, "uniontype", &isnull);
2023  if (isnull) {
2024  elog(NOTICE, "Second argument (uniontype) of unionarg is NULL. Assuming uniontype = LAST");
2025  utype = UT_LAST;
2026  }
2027  else {
2028  utypename = text_to_cstring((text *) DatumGetPointer(tupv));
2029  utype = rtpg_uniontype_index_from_name(rtpg_strtoupper(utypename));
2030  }
2031 
2032  arg->bandarg[i].uniontype = utype;
2033  arg->bandarg[i].nband = nband - 1;
2034  arg->bandarg[i].raster = NULL;
2035 
2036  if (
2037  utype != UT_MEAN &&
2038  utype != UT_RANGE
2039  ) {
2040  arg->bandarg[i].numraster = 1;
2041  }
2042  else
2043  arg->bandarg[i].numraster = 2;
2044  }
2045 
2046  if (arg->numband < n) {
2047  arg->bandarg = repalloc(arg->bandarg, sizeof(struct rtpg_union_band_arg_t) * arg->numband);
2048  if (arg->bandarg == NULL) {
2049  elog(ERROR, "rtpg_union_unionarg_process: Could not reallocate memory for band information");
2050  return 0;
2051  }
2052  }
2053 
2054  return 1;
2055 }
rtpg_union_band_arg bandarg
rtpg_union_type
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:65
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: