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

◆ rtpg_union_noarg()

static int rtpg_union_noarg ( rtpg_union_arg  arg,
rt_raster  raster 
)
static

Definition at line 2062 of file rtpg_mapalgebra.c.

2062 {
2063 int numbands;
2064 int i;
2065
2066 if (rt_raster_is_empty(raster))
2067 return 1;
2068
2069 numbands = rt_raster_get_num_bands(raster);
2070 if (numbands <= arg->numband)
2071 return 1;
2072
2073 /* more bands to process */
2074 POSTGIS_RT_DEBUG(4, "input raster has more bands, adding more bandargs");
2075 if (arg->numband)
2076 arg->bandarg = repalloc(arg->bandarg, sizeof(struct rtpg_union_band_arg_t) * numbands);
2077 else
2078 arg->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * numbands);
2079 if (arg->bandarg == NULL) {
2080 elog(ERROR, "rtpg_union_noarg: Could not reallocate memory for band information");
2081 return 0;
2082 }
2083
2084 i = arg->numband;
2085 arg->numband = numbands;
2086 for (; i < arg->numband; i++) {
2087 POSTGIS_RT_DEBUGF(4, "Adding bandarg for band at index %d", i);
2088 arg->bandarg[i].uniontype = UT_LAST;
2089 arg->bandarg[i].nband = i;
2090 arg->bandarg[i].numraster = 1;
2091
2092 arg->bandarg[i].raster = (rt_raster *) palloc(sizeof(rt_raster) * arg->bandarg[i].numraster);
2093 if (arg->bandarg[i].raster == NULL) {
2094 elog(ERROR, "rtpg_union_noarg: Could not allocate memory for working rasters");
2095 return 0;
2096 }
2097 memset(arg->bandarg[i].raster, 0, sizeof(rt_raster) * arg->bandarg[i].numraster);
2098
2099 /* add new working rt_raster but only if working raster already exists */
2100 if (!rt_raster_is_empty(arg->bandarg[0].raster[0])) {
2101 arg->bandarg[i].raster[0] = rt_raster_clone(arg->bandarg[0].raster[0], 0); /* shallow clone */
2102 if (arg->bandarg[i].raster[0] == NULL) {
2103 elog(ERROR, "rtpg_union_noarg: Could not create working raster");
2104 return 0;
2105 }
2106 }
2107 }
2108
2109 return 1;
2110}
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition rt_raster.c:372
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
Definition rt_raster.c:1535
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition rt_raster.c:1329
@ UT_LAST
#define POSTGIS_RT_DEBUG(level, msg)
Definition rtpostgis.h:61
#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_DEBUG, POSTGIS_RT_DEBUGF, rtpg_union_band_arg_t::raster, rt_raster_clone(), rt_raster_get_num_bands(), rt_raster_is_empty(), rtpg_union_band_arg_t::uniontype, and UT_LAST.

Referenced by RASTER_union_transfn().

Here is the call graph for this function:
Here is the caller graph for this function: