PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ rtpg_union_noarg()

static int rtpg_union_noarg ( rtpg_union_arg  arg,
rt_raster  raster 
)
static

Definition at line 2005 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, PG_FUNCTION_INFO_V1(), POSTGIS_RT_DEBUG, POSTGIS_RT_DEBUGF, rtpg_union_band_arg_t::raster, RASTER_union_transfn(), 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().

2005  {
2006  int numbands;
2007  int i;
2008 
2009  if (rt_raster_is_empty(raster))
2010  return 1;
2011 
2012  numbands = rt_raster_get_num_bands(raster);
2013  if (numbands <= arg->numband)
2014  return 1;
2015 
2016  /* more bands to process */
2017  POSTGIS_RT_DEBUG(4, "input raster has more bands, adding more bandargs");
2018  if (arg->numband)
2019  arg->bandarg = repalloc(arg->bandarg, sizeof(struct rtpg_union_band_arg_t) * numbands);
2020  else
2021  arg->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * numbands);
2022  if (arg->bandarg == NULL) {
2023  elog(ERROR, "rtpg_union_noarg: Could not reallocate memory for band information");
2024  return 0;
2025  }
2026 
2027  i = arg->numband;
2028  arg->numband = numbands;
2029  for (; i < arg->numband; i++) {
2030  POSTGIS_RT_DEBUGF(4, "Adding bandarg for band at index %d", i);
2031  arg->bandarg[i].uniontype = UT_LAST;
2032  arg->bandarg[i].nband = i;
2033  arg->bandarg[i].numraster = 1;
2034 
2035  arg->bandarg[i].raster = (rt_raster *) palloc(sizeof(rt_raster) * arg->bandarg[i].numraster);
2036  if (arg->bandarg[i].raster == NULL) {
2037  elog(ERROR, "rtpg_union_noarg: Could not allocate memory for working rasters");
2038  return 0;
2039  }
2040  memset(arg->bandarg[i].raster, 0, sizeof(rt_raster) * arg->bandarg[i].numraster);
2041 
2042  /* add new working rt_raster but only if working raster already exists */
2043  if (!rt_raster_is_empty(arg->bandarg[0].raster[0])) {
2044  arg->bandarg[i].raster[0] = rt_raster_clone(arg->bandarg[0].raster[0], 0); /* shallow clone */
2045  if (arg->bandarg[i].raster[0] == NULL) {
2046  elog(ERROR, "rtpg_union_noarg: Could not create working raster");
2047  return 0;
2048  }
2049  }
2050  }
2051 
2052  return 1;
2053 }
uint16_t 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:65
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:61
Here is the call graph for this function:
Here is the caller graph for this function: