PostGIS  2.5.2dev-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 1716 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().

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