PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ RASTER_getGDALDrivers()

Datum RASTER_getGDALDrivers ( PG_FUNCTION_ARGS  )

Definition at line 339 of file rtpg_gdal.c.

340{
341 FuncCallContext *funcctx;
342 TupleDesc tupdesc;
343
344 uint32_t drv_count;
345 rt_gdaldriver drv_set;
346 rt_gdaldriver drv_set2;
347 int call_cntr;
348 int max_calls;
349
350 /* first call of function */
351 if (SRF_IS_FIRSTCALL()) {
352 MemoryContext oldcontext;
353
354 /* create a function context for cross-call persistence */
355 funcctx = SRF_FIRSTCALL_INIT();
356
357 /* switch to memory context appropriate for multiple function calls */
358 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
359
360 drv_set = rt_raster_gdal_drivers(&drv_count, 0);
361 if (NULL == drv_set || !drv_count) {
362 elog(NOTICE, "No GDAL drivers found");
363 MemoryContextSwitchTo(oldcontext);
364 SRF_RETURN_DONE(funcctx);
365 }
366
367 POSTGIS_RT_DEBUGF(3, "%d drivers returned", (int) drv_count);
368
369 /* Store needed information */
370 funcctx->user_fctx = drv_set;
371
372 /* total number of tuples to be returned */
373 funcctx->max_calls = drv_count;
374
375 /* Build a tuple descriptor for our result type */
376 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
377 ereport(ERROR, (
378 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
379 errmsg(
380 "function returning record called in context "
381 "that cannot accept type record"
382 )
383 ));
384 }
385
386 BlessTupleDesc(tupdesc);
387 funcctx->tuple_desc = tupdesc;
388 MemoryContextSwitchTo(oldcontext);
389 }
390
391 /* stuff done on every call of the function */
392 funcctx = SRF_PERCALL_SETUP();
393
394 call_cntr = funcctx->call_cntr;
395 max_calls = funcctx->max_calls;
396 tupdesc = funcctx->tuple_desc;
397 drv_set2 = funcctx->user_fctx;
398
399 /* do when there is more left to send */
400 if (call_cntr < max_calls) {
401 Datum values[VALUES_LENGTH];
402 bool nulls[VALUES_LENGTH];
403 HeapTuple tuple;
404 Datum result;
405
406 POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
407
408 memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
409
410 values[0] = Int32GetDatum(drv_set2[call_cntr].idx);
411 values[1] = CStringGetTextDatum(drv_set2[call_cntr].short_name);
412 values[2] = CStringGetTextDatum(drv_set2[call_cntr].long_name);
413 values[3] = BoolGetDatum(drv_set2[call_cntr].can_read);
414 values[4] = BoolGetDatum(drv_set2[call_cntr].can_write);
415 values[5] = CStringGetTextDatum(drv_set2[call_cntr].create_options);
416
417 POSTGIS_RT_DEBUGF(4, "Result %d, Index %d", call_cntr, drv_set2[call_cntr].idx);
418 POSTGIS_RT_DEBUGF(4, "Result %d, Short Name %s", call_cntr, drv_set2[call_cntr].short_name);
419 POSTGIS_RT_DEBUGF(4, "Result %d, Full Name %s", call_cntr, drv_set2[call_cntr].long_name);
420 POSTGIS_RT_DEBUGF(4, "Result %d, Can Read %u", call_cntr, drv_set2[call_cntr].can_read);
421 POSTGIS_RT_DEBUGF(4, "Result %d, Can Write %u", call_cntr, drv_set2[call_cntr].can_write);
422 POSTGIS_RT_DEBUGF(5, "Result %d, Create Options %s", call_cntr, drv_set2[call_cntr].create_options);
423
424 /* build a tuple */
425 tuple = heap_form_tuple(tupdesc, values, nulls);
426
427 /* make the tuple into a datum */
428 result = HeapTupleGetDatum(tuple);
429
430 /* clean up */
431 pfree(drv_set2[call_cntr].short_name);
432 pfree(drv_set2[call_cntr].long_name);
433 pfree(drv_set2[call_cntr].create_options);
434
435 SRF_RETURN_NEXT(funcctx, result);
436 }
437 /* do when there is no more left */
438 else {
439 pfree(drv_set2);
440 SRF_RETURN_DONE(funcctx);
441 }
442}
#define FALSE
Definition dbfopen.c:168
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition rt_raster.c:1711
#define VALUES_LENGTH
Definition rtpg_gdal.c:333
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition rtpostgis.h:65

References FALSE, POSTGIS_RT_DEBUGF, rt_raster_gdal_drivers(), and VALUES_LENGTH.

Here is the call graph for this function: