PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ rt_raster_gdal_drivers()

rt_gdaldriver rt_raster_gdal_drivers ( uint32_t drv_count,
uint8_t  can_write 
)

Returns a set of available GDAL drivers.

Parameters
drv_count: number of GDAL drivers available
can_write: 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 1720 of file rt_raster.c.

References rt_gdaldriver_t::can_read, rt_gdaldriver_t::can_write, 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().

1720  {
1721  const char *cc;
1722  const char *vio;
1723  const char *txt;
1724  int txt_len;
1725  GDALDriverH *drv = NULL;
1726  rt_gdaldriver rtn = NULL;
1727  int count;
1728  int i;
1729  uint32_t j;
1730 
1731  assert(drv_count != NULL);
1732 
1734  count = GDALGetDriverCount();
1735  RASTER_DEBUGF(3, "%d drivers found", count);
1736 
1737  rtn = (rt_gdaldriver) rtalloc(count * sizeof(struct rt_gdaldriver_t));
1738  if (NULL == rtn) {
1739  rterror("rt_raster_gdal_drivers: Could not allocate memory for gdaldriver structure");
1740  return 0;
1741  }
1742 
1743  for (i = 0, j = 0; i < count; i++) {
1744  drv = GDALGetDriver(i);
1745 
1746 #ifdef GDAL_DCAP_RASTER
1747  /* Starting with GDAL 2.0, vector drivers can also be returned */
1748  /* Only keep raster drivers */
1749  const char *is_raster;
1750  is_raster = GDALGetMetadataItem(drv, GDAL_DCAP_RASTER, NULL);
1751  if (is_raster == NULL || !EQUAL(is_raster, "YES"))
1752  continue;
1753 #endif
1754 
1755  /* CreateCopy support */
1756  cc = GDALGetMetadataItem(drv, GDAL_DCAP_CREATECOPY, NULL);
1757 
1758  /* VirtualIO support */
1759  vio = GDALGetMetadataItem(drv, GDAL_DCAP_VIRTUALIO, NULL);
1760 
1761  if (can_write && (cc == NULL || vio == NULL))
1762  continue;
1763 
1764  /* we can always read what GDAL can load */
1765  rtn[j].can_read = 1;
1766  /* we require CreateCopy and VirtualIO support to write to GDAL */
1767  rtn[j].can_write = (cc != NULL && vio != NULL);
1768 
1769  if (rtn[j].can_write) {
1770  RASTER_DEBUGF(3, "driver %s (%d) supports CreateCopy() and VirtualIO()", txt, i);
1771  }
1772 
1773  /* index of driver */
1774  rtn[j].idx = i;
1775 
1776  /* short name */
1777  txt = GDALGetDriverShortName(drv);
1778  txt_len = strlen(txt);
1779 
1780  txt_len = (txt_len + 1) * sizeof(char);
1781  rtn[j].short_name = (char *) rtalloc(txt_len);
1782  memcpy(rtn[j].short_name, txt, txt_len);
1783 
1784  /* long name */
1785  txt = GDALGetDriverLongName(drv);
1786  txt_len = strlen(txt);
1787 
1788  txt_len = (txt_len + 1) * sizeof(char);
1789  rtn[j].long_name = (char *) rtalloc(txt_len);
1790  memcpy(rtn[j].long_name, txt, txt_len);
1791 
1792  /* creation options */
1793  txt = GDALGetDriverCreationOptionList(drv);
1794  txt_len = strlen(txt);
1795 
1796  txt_len = (txt_len + 1) * sizeof(char);
1797  rtn[j].create_options = (char *) rtalloc(txt_len);
1798  memcpy(rtn[j].create_options, txt, txt_len);
1799 
1800  j++;
1801  }
1802 
1803  /* free unused memory */
1804  rtn = rtrealloc(rtn, j * sizeof(struct rt_gdaldriver_t));
1805  *drv_count = j;
1806 
1807  return rtn;
1808 }
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_util.c:336
struct rt_gdaldriver_t * rt_gdaldriver
Definition: librtcore.h:154
char * short_name
Definition: librtcore.h:2473
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
unsigned int uint32_t
Definition: uthash.h:78
int count
Definition: genraster.py:56
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
uint8_t can_write
Definition: librtcore.h:2477
char * create_options
Definition: librtcore.h:2475
char * long_name
Definition: librtcore.h:2474
uint8_t can_read
Definition: librtcore.h:2476
Here is the call graph for this function:
Here is the caller graph for this function: