PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ RASTER_getGDALDrivers()

Datum RASTER_getGDALDrivers ( PG_FUNCTION_ARGS  )

Definition at line 344 of file rtpg_gdal.c.

References FALSE, PG_FUNCTION_INFO_V1(), POSTGIS_RT_DEBUGF, RASTER_GDALWarp(), and rt_raster_gdal_drivers().

Referenced by RASTER_asGDALRaster().

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