PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ rtpg_union_unionarg_process()

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

Definition at line 1897 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(), text_to_cstring(), rtpg_union_band_arg_t::uniontype, UT_LAST, UT_MEAN, and UT_RANGE.

Referenced by RASTER_union_transfn().

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