PostGIS  2.1.10dev-r@@SVN_REVISION@@
static int rtpg_union_unionarg_process ( rtpg_union_arg  arg,
ArrayType *  array 
)
static

Definition at line 17958 of file rt_pg.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().

17958  {
17959  Oid etype;
17960  Datum *e;
17961  bool *nulls;
17962  int16 typlen;
17963  bool typbyval;
17964  char typalign;
17965  int n = 0;
17966 
17967  HeapTupleHeader tup;
17968  bool isnull;
17969  Datum tupv;
17970 
17971  int i;
17972  int nband = 1;
17973  char *utypename = NULL;
17974  rtpg_union_type utype = UT_LAST;
17975 
17976  etype = ARR_ELEMTYPE(array);
17977  get_typlenbyvalalign(etype, &typlen, &typbyval, &typalign);
17978 
17979  deconstruct_array(
17980  array,
17981  etype,
17982  typlen, typbyval, typalign,
17983  &e, &nulls, &n
17984  );
17985 
17986  if (!n) {
17987  elog(ERROR, "rtpg_union_unionarg_process: Invalid argument for unionarg");
17988  return 0;
17989  }
17990 
17991  /* prep arg */
17992  arg->numband = n;
17993  arg->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * arg->numband);
17994  if (arg->bandarg == NULL) {
17995  elog(ERROR, "rtpg_union_unionarg_process: Could not allocate memory for band information");
17996  return 0;
17997  }
17998 
17999  /* process each element */
18000  for (i = 0; i < n; i++) {
18001  if (nulls[i]) {
18002  arg->numband--;
18003  continue;
18004  }
18005 
18006  POSTGIS_RT_DEBUGF(4, "Processing unionarg at index %d", i);
18007 
18008  /* each element is a tuple */
18009  tup = (HeapTupleHeader) DatumGetPointer(e[i]);
18010  if (NULL == tup) {
18011  elog(ERROR, "rtpg_union_unionarg_process: Invalid argument for unionarg");
18012  return 0;
18013  }
18014 
18015  /* first element, bandnum */
18016  tupv = GetAttributeByName(tup, "nband", &isnull);
18017  if (isnull) {
18018  nband = i + 1;
18019  elog(NOTICE, "First argument (nband) of unionarg is NULL. Assuming nband = %d", nband);
18020  }
18021  else
18022  nband = DatumGetInt32(tupv);
18023 
18024  if (nband < 1) {
18025  elog(ERROR, "rtpg_union_unionarg_process: Band number must be greater than zero (1-based)");
18026  return 0;
18027  }
18028 
18029  /* second element, uniontype */
18030  tupv = GetAttributeByName(tup, "uniontype", &isnull);
18031  if (isnull) {
18032  elog(NOTICE, "Second argument (uniontype) of unionarg is NULL. Assuming uniontype = LAST");
18033  utype = UT_LAST;
18034  }
18035  else {
18036  utypename = text_to_cstring((text *) DatumGetPointer(tupv));
18037  utype = rtpg_uniontype_index_from_name(rtpg_strtoupper(utypename));
18038  }
18039 
18040  arg->bandarg[i].uniontype = utype;
18041  arg->bandarg[i].nband = nband - 1;
18042  arg->bandarg[i].raster = NULL;
18043 
18044  if (
18045  utype != UT_MEAN &&
18046  utype != UT_RANGE
18047  ) {
18048  arg->bandarg[i].numraster = 1;
18049  }
18050  else
18051  arg->bandarg[i].numraster = 2;
18052  }
18053 
18054  if (arg->numband < n) {
18055  arg->bandarg = repalloc(arg->bandarg, sizeof(struct rtpg_union_band_arg_t) * arg->numband);
18056  if (arg->bandarg == NULL) {
18057  elog(ERROR, "rtpg_union_unionarg_process: Could not reallocate memory for band information");
18058  return 0;
18059  }
18060  }
18061 
18062  return 1;
18063 }
static char * rtpg_strtoupper(char *str)
Definition: rt_pg.c:730
rtpg_union_band_arg bandarg
Definition: rt_pg.c:17764
rtpg_union_type
Definition: rt_pg.c:17717
rt_raster * raster
Definition: rt_pg.c:17758
tuple nband
Definition: pixval.py:52
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rt_pg.h:62
rtpg_union_type uniontype
Definition: rt_pg.c:17755
static rtpg_union_type rtpg_uniontype_index_from_name(const char *cutype)
Definition: rt_pg.c:17729

Here is the call graph for this function:

Here is the caller graph for this function: