195 FuncCallContext *funcctx;
203 if (SRF_IS_FIRSTCALL()) {
204 MemoryContext oldcontext;
209 bool exclude_nodata_value =
TRUE;
215 funcctx = SRF_FIRSTCALL_INIT();
218 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
221 if (PG_ARGISNULL(0)) {
222 MemoryContextSwitchTo(oldcontext);
223 SRF_RETURN_DONE(funcctx);
225 pgraster = (
rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
228 PG_FREE_IF_COPY(pgraster, 0);
230 errcode(ERRCODE_OUT_OF_MEMORY),
231 errmsg(
"Could not deserialize raster")
233 MemoryContextSwitchTo(oldcontext);
234 SRF_RETURN_DONE(funcctx);
237 if (!PG_ARGISNULL(1))
238 nband = PG_GETARG_UINT32(1);
245 if (nband < 1 || nband > numbands) {
246 elog(NOTICE,
"Invalid band index (must use 1-based). Returning NULL");
248 PG_FREE_IF_COPY(pgraster, 0);
249 MemoryContextSwitchTo(oldcontext);
250 SRF_RETURN_DONE(funcctx);
253 if (!PG_ARGISNULL(2))
254 exclude_nodata_value = PG_GETARG_BOOL(2);
260 PG_FREE_IF_COPY(pgraster, 0);
261 MemoryContextSwitchTo(oldcontext);
262 SRF_RETURN_DONE(funcctx);
272 PG_FREE_IF_COPY(pgraster, 0);
273 if (NULL == geomval) {
275 errcode(ERRCODE_NO_DATA_FOUND),
276 errmsg(
"Could not polygonize raster")
278 MemoryContextSwitchTo(oldcontext);
279 SRF_RETURN_DONE(funcctx);
285 funcctx->user_fctx = geomval;
288 funcctx->max_calls = nElements;
291 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
293 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
294 errmsg(
"function returning record called in context that cannot accept type record")
298 BlessTupleDesc(tupdesc);
299 funcctx->tuple_desc = tupdesc;
301 MemoryContextSwitchTo(oldcontext);
305 funcctx = SRF_PERCALL_SETUP();
307 call_cntr = funcctx->call_cntr;
308 max_calls = funcctx->max_calls;
309 tupdesc = funcctx->tuple_desc;
310 geomval2 = funcctx->user_fctx;
313 if (call_cntr < max_calls) {
320 size_t gser_size = 0;
330 values[0] = PointerGetDatum(gser);
331 values[1] = Float8GetDatum(geomval2[call_cntr].val);
334 tuple = heap_form_tuple(tupdesc, values, nulls);
337 result = HeapTupleGetDatum(tuple);
339 SRF_RETURN_NEXT(funcctx, result);
344 SRF_RETURN_DONE(funcctx);
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,...)