PostGIS  2.3.7dev-r@@SVN_REVISION@@
static int rtpg_union_noarg ( rtpg_union_arg  arg,
rt_raster  raster 
)
static

Definition at line 2008 of file rtpg_mapalgebra.c.

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().

2008  {
2009  int numbands;
2010  int i;
2011 
2012  if (rt_raster_is_empty(raster))
2013  return 1;
2014 
2015  numbands = rt_raster_get_num_bands(raster);
2016  if (numbands <= arg->numband)
2017  return 1;
2018 
2019  /* more bands to process */
2020  POSTGIS_RT_DEBUG(4, "input raster has more bands, adding more bandargs");
2021  if (arg->numband)
2022  arg->bandarg = repalloc(arg->bandarg, sizeof(struct rtpg_union_band_arg_t) * numbands);
2023  else
2024  arg->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * numbands);
2025  if (arg->bandarg == NULL) {
2026  elog(ERROR, "rtpg_union_noarg: Could not reallocate memory for band information");
2027  return 0;
2028  }
2029 
2030  i = arg->numband;
2031  arg->numband = numbands;
2032  for (; i < arg->numband; i++) {
2033  POSTGIS_RT_DEBUGF(4, "Adding bandarg for band at index %d", i);
2034  arg->bandarg[i].uniontype = UT_LAST;
2035  arg->bandarg[i].nband = i;
2036  arg->bandarg[i].numraster = 1;
2037 
2038  arg->bandarg[i].raster = (rt_raster *) palloc(sizeof(rt_raster) * arg->bandarg[i].numraster);
2039  if (arg->bandarg[i].raster == NULL) {
2040  elog(ERROR, "rtpg_union_noarg: Could not allocate memory for working rasters");
2041  return 0;
2042  }
2043  memset(arg->bandarg[i].raster, 0, sizeof(rt_raster) * arg->bandarg[i].numraster);
2044 
2045  /* add new working rt_raster but only if working raster already exists */
2046  if (!rt_raster_is_empty(arg->bandarg[0].raster[0])) {
2047  arg->bandarg[i].raster[0] = rt_raster_clone(arg->bandarg[0].raster[0], 0); /* shallow clone */
2048  if (arg->bandarg[i].raster[0] == NULL) {
2049  elog(ERROR, "rtpg_union_noarg: Could not create working raster");
2050  return 0;
2051  }
2052  }
2053  }
2054 
2055  return 1;
2056 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
rtpg_union_band_arg bandarg
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_raster.c:1338
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:57
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
Definition: rt_raster.c:1544
rtpg_union_type uniontype
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rtpostgis.h:53

Here is the call graph for this function:

Here is the caller graph for this function: