PostGIS  3.1.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
cancc: if non-zero, filter drivers to only those with support for CreateCopy and VirtualIO
Returns
set of "gdaldriver" values 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.

1712 {
1713  assert(drv_count != NULL);
1714  uint32_t output_driver = 0;
1716  uint32_t count = (uint32_t)GDALGetDriverCount();
1717 
1718  rt_gdaldriver rtn = (rt_gdaldriver)rtalloc(count * sizeof(struct rt_gdaldriver_t));
1719  if (!rtn)
1720  {
1721  rterror("rt_raster_gdal_drivers: Could not allocate memory for gdaldriver structure");
1722  *drv_count = output_driver;
1723  return NULL;
1724  }
1725 
1726  for (uint32_t i = 0; i < count; i++)
1727  {
1728  GDALDriverH *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  const char *is_raster;
1734  is_raster = GDALGetMetadataItem(drv, GDAL_DCAP_RASTER, NULL);
1735  if (!is_raster || !EQUAL(is_raster, "YES"))
1736  continue;
1737 #endif
1738 
1739  /* CreateCopy support */
1740  const char *cc = GDALGetMetadataItem(drv, GDAL_DCAP_CREATECOPY, NULL);
1741  if (can_write && !cc)
1742  continue;
1743 
1744  /* VirtualIO support */
1745  const char *vio = GDALGetMetadataItem(drv, GDAL_DCAP_VIRTUALIO, NULL);
1746  if (can_write && !vio)
1747  continue;
1748 
1749  /* we can always read what GDAL can load */
1750  rtn[output_driver].can_read = 1;
1751  /* we require CreateCopy and VirtualIO support to write to GDAL */
1752  rtn[output_driver].can_write = (cc != NULL && vio != NULL);
1753 
1754  /* index of driver */
1755  rtn[output_driver].idx = i;
1756 
1757  /* short name */
1758  const char *txt = GDALGetDriverShortName(drv);
1759  size_t txt_len = strlen(txt);
1760  txt_len = (txt_len + 1) * sizeof(char);
1761  rtn[output_driver].short_name = (char *)rtalloc(txt_len);
1762  memcpy(rtn[output_driver].short_name, txt, txt_len);
1763 
1764  /* long name */
1765  txt = GDALGetDriverLongName(drv);
1766  txt_len = strlen(txt);
1767  txt_len = (txt_len + 1) * sizeof(char);
1768  rtn[output_driver].long_name = (char *)rtalloc(txt_len);
1769  memcpy(rtn[output_driver].long_name, txt, txt_len);
1770 
1771  /* creation options */
1772  txt = GDALGetDriverCreationOptionList(drv);
1773  txt_len = strlen(txt);
1774  txt_len = (txt_len + 1) * sizeof(char);
1775  rtn[output_driver].create_options = (char *)rtalloc(txt_len);
1776  memcpy(rtn[output_driver].create_options, txt, txt_len);
1777 
1778  output_driver++;
1779  }
1780 
1781  /* free unused memory */
1782  rtn = rtrealloc(rtn, output_driver * sizeof(struct rt_gdaldriver_t));
1783  *drv_count = output_driver;
1784 
1785  return rtn;
1786 }
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
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, 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: