PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rtpg_union_unionarg_process()

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

Definition at line 1959 of file rtpg_mapalgebra.c.

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