PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ RASTER_getGDALDrivers()

Datum RASTER_getGDALDrivers ( PG_FUNCTION_ARGS  )

Definition at line 337 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().

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