PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ rtpg_union_unionarg_process()

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

Definition at line 1913 of file rtpg_mapalgebra.c.

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

References rtpg_union_arg_t::bandarg, rtpg_union_band_arg_t::nband, pixval::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().

Here is the call graph for this function:
Here is the caller graph for this function: