PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ rtpg_union_noarg()

static int rtpg_union_noarg ( rtpg_union_arg  arg,
rt_raster  raster 
)
static

Definition at line 2058 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().

2058  {
2059  int numbands;
2060  int i;
2061 
2062  if (rt_raster_is_empty(raster))
2063  return 1;
2064 
2065  numbands = rt_raster_get_num_bands(raster);
2066  if (numbands <= arg->numband)
2067  return 1;
2068 
2069  /* more bands to process */
2070  POSTGIS_RT_DEBUG(4, "input raster has more bands, adding more bandargs");
2071  if (arg->numband)
2072  arg->bandarg = repalloc(arg->bandarg, sizeof(struct rtpg_union_band_arg_t) * numbands);
2073  else
2074  arg->bandarg = palloc(sizeof(struct rtpg_union_band_arg_t) * numbands);
2075  if (arg->bandarg == NULL) {
2076  elog(ERROR, "rtpg_union_noarg: Could not reallocate memory for band information");
2077  return 0;
2078  }
2079 
2080  i = arg->numband;
2081  arg->numband = numbands;
2082  for (; i < arg->numband; i++) {
2083  POSTGIS_RT_DEBUGF(4, "Adding bandarg for band at index %d", i);
2084  arg->bandarg[i].uniontype = UT_LAST;
2085  arg->bandarg[i].nband = i;
2086  arg->bandarg[i].numraster = 1;
2087 
2088  arg->bandarg[i].raster = (rt_raster *) palloc(sizeof(rt_raster) * arg->bandarg[i].numraster);
2089  if (arg->bandarg[i].raster == NULL) {
2090  elog(ERROR, "rtpg_union_noarg: Could not allocate memory for working rasters");
2091  return 0;
2092  }
2093  memset(arg->bandarg[i].raster, 0, sizeof(rt_raster) * arg->bandarg[i].numraster);
2094 
2095  /* add new working rt_raster but only if working raster already exists */
2096  if (!rt_raster_is_empty(arg->bandarg[0].raster[0])) {
2097  arg->bandarg[i].raster[0] = rt_raster_clone(arg->bandarg[0].raster[0], 0); /* shallow clone */
2098  if (arg->bandarg[i].raster[0] == NULL) {
2099  elog(ERROR, "rtpg_union_noarg: Could not create working raster");
2100  return 0;
2101  }
2102  }
2103  }
2104 
2105  return 1;
2106 }
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: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: