2121 MemoryContext aggcontext;
2122 MemoryContext oldcontext;
2132 int isempty[2] = {0};
2133 int hasband[2] = {0};
2135 double _offset[4] = {0.};
2143 char *utypename = NULL;
2147 double nodataval = 0;
2153 uint16_t _dim[2] = {0};
2160 if (!AggCheckCallContext(fcinfo, &aggcontext)) {
2161 elog(ERROR,
"RASTER_union_transfn: Cannot be called in a non-aggregate context");
2166 oldcontext = MemoryContextSwitchTo(aggcontext);
2168 if (PG_ARGISNULL(0)) {
2173 MemoryContextSwitchTo(oldcontext);
2174 elog(ERROR,
"RASTER_union_transfn: Could not allocate memory for state variable");
2190 if (!PG_ARGISNULL(1)) {
2192 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
2199 PG_FREE_IF_COPY(pgraster, 1);
2201 MemoryContextSwitchTo(oldcontext);
2202 elog(ERROR,
"RASTER_union_transfn: Could not deserialize raster");
2215 if (!PG_ARGISNULL(2)) {
2216 Oid calltype = get_fn_expr_argtype(fcinfo->flinfo, 2);
2251 if (numband > idx) {
2269 PG_FREE_IF_COPY(pgraster, 1);
2272 MemoryContextSwitchTo(oldcontext);
2273 elog(ERROR,
"RASTER_union_transfn: Could not allocate memory for band information");
2278 for (i = idx; i < iwr->
numband; i++) {
2302 nband = PG_GETARG_INT32(2);
2308 PG_FREE_IF_COPY(pgraster, 1);
2311 MemoryContextSwitchTo(oldcontext);
2312 elog(ERROR,
"RASTER_union_transfn: Band number must be greater than zero (1-based)");
2323 PG_FREE_IF_COPY(pgraster, 1);
2326 MemoryContextSwitchTo(oldcontext);
2327 elog(ERROR,
"RASTER_union_transfn: Could not allocate memory for band information");
2348 PG_FREE_IF_COPY(pgraster, 1);
2351 MemoryContextSwitchTo(oldcontext);
2352 elog(ERROR,
"RASTER_union_transfn: Could not process unionarg");
2361 if (nargs > 3 && !PG_ARGISNULL(3)) {
2376 for (i = 0; i < iwr->
numband; i++) {
2391 PG_FREE_IF_COPY(pgraster, 1);
2394 MemoryContextSwitchTo(oldcontext);
2395 elog(ERROR,
"RASTER_union_transfn: Could not allocate memory for working raster(s)");
2410 PG_FREE_IF_COPY(pgraster, 1);
2413 MemoryContextSwitchTo(oldcontext);
2414 elog(ERROR,
"RASTER_union_transfn: Could not create working raster");
2431 PG_FREE_IF_COPY(pgraster, 1);
2434 MemoryContextSwitchTo(oldcontext);
2435 elog(ERROR,
"RASTER_union_transfn: Could not check and balance number of bands");
2442 if (itrset == NULL) {
2447 PG_FREE_IF_COPY(pgraster, 1);
2450 MemoryContextSwitchTo(oldcontext);
2451 elog(ERROR,
"RASTER_union_transfn: Could not allocate memory for iterator arguments");
2456 for (i = 0; i < iwr->
numband; i++) {
2476 if (!isempty[0] && hasband[0])
2478 else if (!isempty[1] && hasband[1])
2485 if (_band != NULL) {
2523 itrset[0].
nband = 0;
2539 if (!isempty[0] && !isempty[1] && hasband[0] && hasband[1]) {
2553 PG_FREE_IF_COPY(pgraster, 1);
2556 MemoryContextSwitchTo(oldcontext);
2557 elog(ERROR,
"RASTER_union_transfn: Could not create internal raster");
2561 _offset[0], _offset[1], _offset[2], _offset[3]);
2568 double igt[6] = {0};
2584 hasnodata, nodataval,
2593 PG_FREE_IF_COPY(pgraster, 1);
2596 MemoryContextSwitchTo(oldcontext);
2597 elog(ERROR,
"RASTER_union_transfn: Could not add new band to internal raster");
2605 for (
y = 0;
y < _dim[1];
y++) {
2606 POSTGIS_RT_DEBUGF(4,
"Getting pixel line of working raster at (x, y, length) = (0, %d, %d)",
y, _dim[0]);
2620 PG_FREE_IF_COPY(pgraster, 1);
2623 MemoryContextSwitchTo(oldcontext);
2624 elog(ERROR,
"RASTER_union_transfn: Could not get pixel line from band of working raster");
2628 POSTGIS_RT_DEBUGF(4,
"Setting pixel line at (x, y, length) = (%d, %d, %d)", (
int) _offset[0], (
int) _offset[1] +
y, nvals);
2631 (
int) _offset[0], (
int) _offset[1] +
y,
2641 PG_FREE_IF_COPY(pgraster, 1);
2644 MemoryContextSwitchTo(oldcontext);
2645 elog(ERROR,
"RASTER_union_transfn: Could not set pixel line to band of internal raster");
2661 hasnodata, nodataval,
2678 PG_FREE_IF_COPY(pgraster, 1);
2681 MemoryContextSwitchTo(oldcontext);
2682 elog(ERROR,
"RASTER_union_transfn: Could not run raster iterator function");
2690 for (
y = 0;
y < _dim[1];
y++) {
2691 POSTGIS_RT_DEBUGF(4,
"Getting pixel line of iterator raster at (x, y, length) = (0, %d, %d)",
y, _dim[0]);
2707 PG_FREE_IF_COPY(pgraster, 1);
2710 MemoryContextSwitchTo(oldcontext);
2711 elog(ERROR,
"RASTER_union_transfn: Could not get pixel line from band of working raster");
2715 POSTGIS_RT_DEBUGF(4,
"Setting pixel line at (x, y, length) = (%d, %d, %d)", (
int) _offset[2], (
int) _offset[3] +
y, nvals);
2718 (
int) _offset[2], (
int) _offset[3] +
y,
2730 PG_FREE_IF_COPY(pgraster, 1);
2733 MemoryContextSwitchTo(oldcontext);
2734 elog(ERROR,
"RASTER_union_transfn: Could not set pixel line to band of internal raster");
2754 hasnodata, nodataval,
2768 PG_FREE_IF_COPY(pgraster, 1);
2771 MemoryContextSwitchTo(oldcontext);
2772 elog(ERROR,
"RASTER_union_transfn: Could not run raster iterator function");
2791 PG_FREE_IF_COPY(pgraster, 1);
2795 MemoryContextSwitchTo(oldcontext);
2799 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