192         FuncCallContext *funcctx;
 
  200         if (SRF_IS_FIRSTCALL()) {
 
  201                 MemoryContext oldcontext;
 
  206                 bool exclude_nodata_value = 
TRUE;
 
  212                 funcctx = SRF_FIRSTCALL_INIT();
 
  215                 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
 
  218                 if (PG_ARGISNULL(0)) {
 
  219                         MemoryContextSwitchTo(oldcontext);
 
  220                         SRF_RETURN_DONE(funcctx);
 
  222                 pgraster = (
rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 
  225                         PG_FREE_IF_COPY(pgraster, 0);
 
  227                                 errcode(ERRCODE_OUT_OF_MEMORY),
 
  228                                 errmsg(
"Could not deserialize raster")
 
  230                         MemoryContextSwitchTo(oldcontext);
 
  231                         SRF_RETURN_DONE(funcctx);
 
  234                 if (!PG_ARGISNULL(1))
 
  235                         nband = PG_GETARG_UINT32(1);
 
  242                 if (nband < 1 || nband > numbands) {
 
  243                         elog(NOTICE, 
"Invalid band index (must use 1-based). Returning NULL");
 
  245                         PG_FREE_IF_COPY(pgraster, 0);
 
  246                         MemoryContextSwitchTo(oldcontext);
 
  247                         SRF_RETURN_DONE(funcctx);
 
  250                 if (!PG_ARGISNULL(2))
 
  251                         exclude_nodata_value = PG_GETARG_BOOL(2);
 
  257                         PG_FREE_IF_COPY(pgraster, 0);
 
  258                         MemoryContextSwitchTo(oldcontext);
 
  259                         SRF_RETURN_DONE(funcctx);
 
  269                 PG_FREE_IF_COPY(pgraster, 0);
 
  270                 if (NULL == geomval) {
 
  272                                 errcode(ERRCODE_NO_DATA_FOUND),
 
  273                                 errmsg(
"Could not polygonize raster")
 
  275                         MemoryContextSwitchTo(oldcontext);
 
  276                         SRF_RETURN_DONE(funcctx);
 
  282                 funcctx->user_fctx = geomval;
 
  285                 funcctx->max_calls = nElements;
 
  288                 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
 
  290                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 
  291                                 errmsg(
"function returning record called in context that cannot accept type record")
 
  295                 BlessTupleDesc(tupdesc);
 
  296                 funcctx->tuple_desc = tupdesc;
 
  298                 MemoryContextSwitchTo(oldcontext);
 
  302         funcctx = SRF_PERCALL_SETUP();
 
  304         call_cntr = funcctx->call_cntr;
 
  305         max_calls = funcctx->max_calls;
 
  306         tupdesc = funcctx->tuple_desc;
 
  307         geomval2 = funcctx->user_fctx;
 
  310         if (call_cntr < max_calls) {
 
  317                 size_t gser_size = 0;
 
  327                 values[0] = PointerGetDatum(gser);
 
  328                 values[1] = Float8GetDatum(geomval2[call_cntr].val);
 
  331                 tuple = heap_form_tuple(tupdesc, values, nulls);
 
  334                 result = HeapTupleGetDatum(tuple);
 
  336                 SRF_RETURN_NEXT(funcctx, 
result);
 
  341                 SRF_RETURN_DONE(funcctx);
 
char result[OUT_DOUBLE_BUFFER_SIZE]
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
rt_geomval rt_raster_gdal_polygonize(rt_raster raster, int nband, int exclude_nodata_value, int *pnElements)
Returns a set of "geomval" value, one for each group of pixel sharing the same value for the provided...
uint16_t rt_raster_get_num_bands(rt_raster raster)
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
#define POSTGIS_RT_DEBUG(level, msg)
#define POSTGIS_RT_DEBUGF(level, msg,...)