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

Definition at line 18066 of file rt_pg.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().

18066  {
18067  int numbands;
18068  int i;
18069 
18070  if (rt_raster_is_empty(raster))
18071  return 1;
18072 
18073  numbands = rt_raster_get_num_bands(raster);
18074  if (numbands <= arg->numband)
18075  return 1;
18076 
18077  /* more bands to process */
18078  POSTGIS_RT_DEBUG(4, "input raster has more bands, adding more bandargs");
18079  if (arg->numband)
18080  arg->bandarg = repalloc(arg->bandarg, sizeof(struct rtpg_union_band_arg_t) * numbands);
18081  else
18082  arg->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * numbands);
18083  if (arg->bandarg == NULL) {
18084  elog(ERROR, "rtpg_union_noarg: Could not reallocate memory for band information");
18085  return 0;
18086  }
18087 
18088  i = arg->numband;
18089  arg->numband = numbands;
18090  for (; i < arg->numband; i++) {
18091  POSTGIS_RT_DEBUGF(4, "Adding bandarg for band at index %d", i);
18092  arg->bandarg[i].uniontype = UT_LAST;
18093  arg->bandarg[i].nband = i;
18094  arg->bandarg[i].numraster = 1;
18095 
18096  arg->bandarg[i].raster = (rt_raster *) palloc(sizeof(rt_raster) * arg->bandarg[i].numraster);
18097  if (arg->bandarg[i].raster == NULL) {
18098  elog(ERROR, "rtpg_union_noarg: Could not allocate memory for working rasters");
18099  return 0;
18100  }
18101  memset(arg->bandarg[i].raster, 0, sizeof(rt_raster) * arg->bandarg[i].numraster);
18102 
18103  /* add new working rt_raster but only if working raster already exists */
18104  if (!rt_raster_is_empty(arg->bandarg[0].raster[0])) {
18105  arg->bandarg[i].raster[0] = rt_raster_clone(arg->bandarg[0].raster[0], 0); /* shallow clone */
18106  if (arg->bandarg[i].raster[0] == NULL) {
18107  elog(ERROR, "rtpg_union_noarg: Could not create working raster");
18108  return 0;
18109  }
18110  }
18111  }
18112 
18113  return 1;
18114 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_api.c:5677
rtpg_union_band_arg bandarg
Definition: rt_pg.c:17764
rt_raster * raster
Definition: rt_pg.c:17758
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rt_pg.h:58
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rt_pg.h:62
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_api.c:8550
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
Definition: rt_api.c:8740
rtpg_union_type uniontype
Definition: rt_pg.c:17755

Here is the call graph for this function:

Here is the caller graph for this function: