PostGIS 3.7.0dev-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 1919 of file rtpg_mapalgebra.c.

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