PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_gdaldriver rt_raster_gdal_drivers ( uint32_t *  drv_count,
uint8_t  cancc 
)

Returns a set of available GDAL drivers.

Parameters
drv_count: number of GDAL drivers available
cancc: if non-zero, filter drivers to only those with support for CreateCopy and VirtualIO
Returns
set of "gdaldriver" values of available GDAL drivers

Definition at line 8891 of file rt_api.c.

References genraster::count, rt_gdaldriver_t::create_options, rt_gdaldriver_t::idx, rt_gdaldriver_t::long_name, RASTER_DEBUGF, rt_util_gdal_register_all(), rtalloc(), rterror(), rtrealloc(), and rt_gdaldriver_t::short_name.

Referenced by main(), RASTER_getGDALDrivers(), rtpg_assignHookGDALEnabledDrivers(), and test_gdal_drivers().

8891  {
8892  const char *state;
8893  const char *txt;
8894  int txt_len;
8895  GDALDriverH *drv = NULL;
8896  rt_gdaldriver rtn = NULL;
8897  int count;
8898  int i;
8899  uint32_t j;
8900 
8901  assert(drv_count != NULL);
8902 
8904  count = GDALGetDriverCount();
8905  rtn = (rt_gdaldriver) rtalloc(count * sizeof(struct rt_gdaldriver_t));
8906  if (NULL == rtn) {
8907  rterror("rt_raster_gdal_drivers: Could not allocate memory for gdaldriver structure");
8908  return 0;
8909  }
8910 
8911  for (i = 0, j = 0; i < count; i++) {
8912  drv = GDALGetDriver(i);
8913 
8914 #ifdef GDAL_DCAP_RASTER
8915  /* Starting with GDAL 2.0, vector drivers can also be returned */
8916  /* Only keep raster drivers */
8917  state = GDALGetMetadataItem(drv, GDAL_DCAP_RASTER, NULL);
8918  if (state == NULL || !EQUAL(state, "YES"))
8919  continue;
8920 #endif
8921 
8922  if (cancc) {
8923  /* CreateCopy support */
8924  state = GDALGetMetadataItem(drv, GDAL_DCAP_CREATECOPY, NULL);
8925  if (state == NULL) continue;
8926 
8927  /* VirtualIO support */
8928  state = GDALGetMetadataItem(drv, GDAL_DCAP_VIRTUALIO, NULL);
8929  if (state == NULL) continue;
8930  }
8931 
8932  /* index of driver */
8933  rtn[j].idx = i;
8934 
8935  /* short name */
8936  txt = GDALGetDriverShortName(drv);
8937  txt_len = strlen(txt);
8938 
8939  if (cancc) {
8940  RASTER_DEBUGF(3, "rt_raster_gdal_driver: driver %s (%d) supports CreateCopy() and VirtualIO()", txt, i);
8941  }
8942 
8943  txt_len = (txt_len + 1) * sizeof(char);
8944  rtn[j].short_name = (char *) rtalloc(txt_len);
8945  memcpy(rtn[j].short_name, txt, txt_len);
8946 
8947  /* long name */
8948  txt = GDALGetDriverLongName(drv);
8949  txt_len = strlen(txt);
8950 
8951  txt_len = (txt_len + 1) * sizeof(char);
8952  rtn[j].long_name = (char *) rtalloc(txt_len);
8953  memcpy(rtn[j].long_name, txt, txt_len);
8954 
8955  /* creation options */
8956  txt = GDALGetDriverCreationOptionList(drv);
8957  txt_len = strlen(txt);
8958 
8959  txt_len = (txt_len + 1) * sizeof(char);
8960  rtn[j].create_options = (char *) rtalloc(txt_len);
8961  memcpy(rtn[j].create_options, txt, txt_len);
8962 
8963  j++;
8964  }
8965 
8966  /* free unused memory */
8967  rtn = rtrealloc(rtn, j * sizeof(struct rt_gdaldriver_t));
8968  *drv_count = j;
8969 
8970  return rtn;
8971 }
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_api.c:445
char * short_name
Definition: rt_api.h:2390
struct rt_gdaldriver_t * rt_gdaldriver
Definition: rt_api.h:141
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
int count
Definition: genraster.py:57
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
char * create_options
Definition: rt_api.h:2392
char * long_name
Definition: rt_api.h:2391
void * rtrealloc(void *mem, size_t size)
Definition: rt_api.c:875

Here is the call graph for this function:

Here is the caller graph for this function: