PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_getGDALDrivers()

Datum RASTER_getGDALDrivers ( PG_FUNCTION_ARGS  )

Definition at line 346 of file rtpg_gdal.c.

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

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