PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ rt_raster_gdal_drivers()

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 1705 of file rt_raster.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().

1705  {
1706  const char *state;
1707  const char *txt;
1708  int txt_len;
1709  GDALDriverH *drv = NULL;
1710  rt_gdaldriver rtn = NULL;
1711  int count;
1712  int i;
1713  uint32_t j;
1714 
1715  assert(drv_count != NULL);
1716 
1718  count = GDALGetDriverCount();
1719  RASTER_DEBUGF(3, "%d drivers found", count);
1720 
1721  rtn = (rt_gdaldriver) rtalloc(count * sizeof(struct rt_gdaldriver_t));
1722  if (NULL == rtn) {
1723  rterror("rt_raster_gdal_drivers: Could not allocate memory for gdaldriver structure");
1724  return 0;
1725  }
1726 
1727  for (i = 0, j = 0; i < count; i++) {
1728  drv = GDALGetDriver(i);
1729 
1730 #ifdef GDAL_DCAP_RASTER
1731  /* Starting with GDAL 2.0, vector drivers can also be returned */
1732  /* Only keep raster drivers */
1733  state = GDALGetMetadataItem(drv, GDAL_DCAP_RASTER, NULL);
1734  if (state == NULL || !EQUAL(state, "YES"))
1735  continue;
1736 #endif
1737 
1738  if (cancc) {
1739  /* CreateCopy support */
1740  state = GDALGetMetadataItem(drv, GDAL_DCAP_CREATECOPY, NULL);
1741  if (state == NULL) continue;
1742 
1743  /* VirtualIO support */
1744  state = GDALGetMetadataItem(drv, GDAL_DCAP_VIRTUALIO, NULL);
1745  if (state == NULL) continue;
1746  }
1747 
1748  /* index of driver */
1749  rtn[j].idx = i;
1750 
1751  /* short name */
1752  txt = GDALGetDriverShortName(drv);
1753  txt_len = strlen(txt);
1754 
1755  if (cancc) {
1756  RASTER_DEBUGF(3, "driver %s (%d) supports CreateCopy() and VirtualIO()", txt, i);
1757  }
1758 
1759  txt_len = (txt_len + 1) * sizeof(char);
1760  rtn[j].short_name = (char *) rtalloc(txt_len);
1761  memcpy(rtn[j].short_name, txt, txt_len);
1762 
1763  /* long name */
1764  txt = GDALGetDriverLongName(drv);
1765  txt_len = strlen(txt);
1766 
1767  txt_len = (txt_len + 1) * sizeof(char);
1768  rtn[j].long_name = (char *) rtalloc(txt_len);
1769  memcpy(rtn[j].long_name, txt, txt_len);
1770 
1771  /* creation options */
1772  txt = GDALGetDriverCreationOptionList(drv);
1773  txt_len = strlen(txt);
1774 
1775  txt_len = (txt_len + 1) * sizeof(char);
1776  rtn[j].create_options = (char *) rtalloc(txt_len);
1777  memcpy(rtn[j].create_options, txt, txt_len);
1778 
1779  j++;
1780  }
1781 
1782  /* free unused memory */
1783  rtn = rtrealloc(rtn, j * sizeof(struct rt_gdaldriver_t));
1784  *drv_count = j;
1785 
1786  return rtn;
1787 }
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_util.c:334
struct rt_gdaldriver_t * rt_gdaldriver
Definition: librtcore.h:166
char * short_name
Definition: librtcore.h:2436
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
void * rtrealloc(void *mem, size_t size)
Definition: rt_context.c:179
int count
Definition: genraster.py:56
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:311
char * create_options
Definition: librtcore.h:2438
char * long_name
Definition: librtcore.h:2437
Here is the call graph for this function:
Here is the caller graph for this function: