PostGIS  3.0.6dev-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 1711 of file rt_raster.c.

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

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 RASTER_getGDALDrivers(), rtpg_assignHookGDALEnabledDrivers(), and test_gdal_drivers().

Here is the call graph for this function:
Here is the caller graph for this function: