PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ rtpg_union_unionarg_process()

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

Definition at line 1954 of file rtpg_mapalgebra.c.

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