2116 MemoryContext aggcontext;
2117 MemoryContext oldcontext;
2127 int isempty[2] = {0};
2128 int hasband[2] = {0};
2130 double _offset[4] = {0.};
2138 char *utypename = NULL;
2142 double nodataval = 0;
2148 uint16_t _dim[2] = {0};
2155 if (!AggCheckCallContext(fcinfo, &aggcontext)) {
2156 elog(ERROR,
"RASTER_union_transfn: Cannot be called in a non-aggregate context");
2161 oldcontext = MemoryContextSwitchTo(aggcontext);
2163 if (PG_ARGISNULL(0)) {
2168 MemoryContextSwitchTo(oldcontext);
2169 elog(ERROR,
"RASTER_union_transfn: Could not allocate memory for state variable");
2185 if (!PG_ARGISNULL(1)) {
2187 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
2194 PG_FREE_IF_COPY(pgraster, 1);
2196 MemoryContextSwitchTo(oldcontext);
2197 elog(ERROR,
"RASTER_union_transfn: Could not deserialize raster");
2210 if (!PG_ARGISNULL(2)) {
2211 Oid calltype = get_fn_expr_argtype(fcinfo->flinfo, 2);
2246 if (numband > idx) {
2264 PG_FREE_IF_COPY(pgraster, 1);
2267 MemoryContextSwitchTo(oldcontext);
2268 elog(ERROR,
"RASTER_union_transfn: Could not allocate memory for band information");
2273 for (i = idx; i < iwr->
numband; i++) {
2297 nband = PG_GETARG_INT32(2);
2303 PG_FREE_IF_COPY(pgraster, 1);
2306 MemoryContextSwitchTo(oldcontext);
2307 elog(ERROR,
"RASTER_union_transfn: Band number must be greater than zero (1-based)");
2318 PG_FREE_IF_COPY(pgraster, 1);
2321 MemoryContextSwitchTo(oldcontext);
2322 elog(ERROR,
"RASTER_union_transfn: Could not allocate memory for band information");
2343 PG_FREE_IF_COPY(pgraster, 1);
2346 MemoryContextSwitchTo(oldcontext);
2347 elog(ERROR,
"RASTER_union_transfn: Could not process unionarg");
2356 if (nargs > 3 && !PG_ARGISNULL(3)) {
2371 for (i = 0; i < iwr->
numband; i++) {
2386 PG_FREE_IF_COPY(pgraster, 1);
2389 MemoryContextSwitchTo(oldcontext);
2390 elog(ERROR,
"RASTER_union_transfn: Could not allocate memory for working raster(s)");
2405 PG_FREE_IF_COPY(pgraster, 1);
2408 MemoryContextSwitchTo(oldcontext);
2409 elog(ERROR,
"RASTER_union_transfn: Could not create working raster");
2426 PG_FREE_IF_COPY(pgraster, 1);
2429 MemoryContextSwitchTo(oldcontext);
2430 elog(ERROR,
"RASTER_union_transfn: Could not check and balance number of bands");
2437 if (itrset == NULL) {
2442 PG_FREE_IF_COPY(pgraster, 1);
2445 MemoryContextSwitchTo(oldcontext);
2446 elog(ERROR,
"RASTER_union_transfn: Could not allocate memory for iterator arguments");
2451 for (i = 0; i < iwr->
numband; i++) {
2471 if (!isempty[0] && hasband[0])
2473 else if (!isempty[1] && hasband[1])
2480 if (_band != NULL) {
2518 itrset[0].
nband = 0;
2534 if (!isempty[0] && !isempty[1] && hasband[0] && hasband[1]) {
2548 PG_FREE_IF_COPY(pgraster, 1);
2551 MemoryContextSwitchTo(oldcontext);
2552 elog(ERROR,
"RASTER_union_transfn: Could not create internal raster");
2556 _offset[0], _offset[1], _offset[2], _offset[3]);
2563 double igt[6] = {0};
2579 hasnodata, nodataval,
2588 PG_FREE_IF_COPY(pgraster, 1);
2591 MemoryContextSwitchTo(oldcontext);
2592 elog(ERROR,
"RASTER_union_transfn: Could not add new band to internal raster");
2600 for (
y = 0;
y < _dim[1];
y++) {
2601 POSTGIS_RT_DEBUGF(4,
"Getting pixel line of working raster at (x, y, length) = (0, %d, %d)",
y, _dim[0]);
2615 PG_FREE_IF_COPY(pgraster, 1);
2618 MemoryContextSwitchTo(oldcontext);
2619 elog(ERROR,
"RASTER_union_transfn: Could not get pixel line from band of working raster");
2623 POSTGIS_RT_DEBUGF(4,
"Setting pixel line at (x, y, length) = (%d, %d, %d)", (
int) _offset[0], (
int) _offset[1] +
y, nvals);
2626 (
int) _offset[0], (
int) _offset[1] +
y,
2636 PG_FREE_IF_COPY(pgraster, 1);
2639 MemoryContextSwitchTo(oldcontext);
2640 elog(ERROR,
"RASTER_union_transfn: Could not set pixel line to band of internal raster");
2656 hasnodata, nodataval,
2673 PG_FREE_IF_COPY(pgraster, 1);
2676 MemoryContextSwitchTo(oldcontext);
2677 elog(ERROR,
"RASTER_union_transfn: Could not run raster iterator function");
2685 for (
y = 0;
y < _dim[1];
y++) {
2686 POSTGIS_RT_DEBUGF(4,
"Getting pixel line of iterator raster at (x, y, length) = (0, %d, %d)",
y, _dim[0]);
2702 PG_FREE_IF_COPY(pgraster, 1);
2705 MemoryContextSwitchTo(oldcontext);
2706 elog(ERROR,
"RASTER_union_transfn: Could not get pixel line from band of working raster");
2710 POSTGIS_RT_DEBUGF(4,
"Setting pixel line at (x, y, length) = (%d, %d, %d)", (
int) _offset[2], (
int) _offset[3] +
y, nvals);
2713 (
int) _offset[2], (
int) _offset[3] +
y,
2725 PG_FREE_IF_COPY(pgraster, 1);
2728 MemoryContextSwitchTo(oldcontext);
2729 elog(ERROR,
"RASTER_union_transfn: Could not set pixel line to band of internal raster");
2749 hasnodata, nodataval,
2763 PG_FREE_IF_COPY(pgraster, 1);
2766 MemoryContextSwitchTo(oldcontext);
2767 elog(ERROR,
"RASTER_union_transfn: Could not run raster iterator function");
2786 PG_FREE_IF_COPY(pgraster, 1);
2790 MemoryContextSwitchTo(oldcontext);
2794 PG_RETURN_POINTER(iwr);
int rt_raster_generate_new_band(rt_raster raster, rt_pixtype pixtype, double initialvalue, uint32_t hasnodata, double nodatavalue, int index)
Generate a new inline band and add it to a raster.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
rt_errorstate rt_band_set_pixel_line(rt_band band, int x, int y, void *vals, uint32_t len)
Set values of multiple pixels.
void rt_band_destroy(rt_band band)
Destroy a raster band.
uint16_t rt_raster_get_num_bands(rt_raster raster)
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
uint16_t rt_raster_get_height(rt_raster raster)
rt_errorstate rt_raster_iterator(rt_iterator itrset, uint16_t itrcount, rt_extenttype extenttype, rt_raster customextent, rt_pixtype pixtype, uint8_t hasnodata, double nodataval, uint16_t distancex, uint16_t distancey, rt_mask mask, void *userarg, int(*callback)(rt_iterator_arg arg, void *userarg, double *value, int *nodata), rt_raster *rtnraster)
n-raster iterator.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
const char * rt_pixtype_name(rt_pixtype pixtype)
uint16_t rt_raster_get_width(rt_raster raster)
rt_errorstate rt_raster_from_two_rasters(rt_raster rast1, rt_raster rast2, rt_extenttype extenttype, rt_raster *rtnraster, double *offset)
int rt_util_same_geotransform_matrix(double *gt1, double *gt2)
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
rt_errorstate rt_band_get_pixel_line(rt_band band, int x, int y, uint16_t len, void **vals, uint16_t *nvals)
Get values of multiple pixels.
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
char * text_to_cstring(const text *textptr)
char * rtpg_strtoupper(char *str)
static rtpg_union_type rtpg_uniontype_index_from_name(const char *cutype)
static void rtpg_union_arg_destroy(rtpg_union_arg arg)
struct rtpg_union_arg_t * rtpg_union_arg
static int rtpg_union_unionarg_process(rtpg_union_arg arg, ArrayType *array)
static int rtpg_union_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
static int rtpg_union_noarg(rtpg_union_arg arg, rt_raster raster)
#define POSTGIS_RT_DEBUG(level, msg)
#define POSTGIS_RT_DEBUGF(level, msg,...)
rtpg_union_band_arg bandarg
rtpg_union_type uniontype