PostGIS  3.4.0dev-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 1838 of file rt_raster.c.

1839 {
1840  assert(drv_count != NULL);
1841  uint32_t output_driver = 0;
1843  uint32_t count = (uint32_t)GDALGetDriverCount();
1844 
1845  rt_gdaldriver rtn = (rt_gdaldriver)rtalloc(count * sizeof(struct rt_gdaldriver_t));
1846  if (!rtn)
1847  {
1848  rterror("rt_raster_gdal_drivers: Could not allocate memory for gdaldriver structure");
1849  *drv_count = output_driver;
1850  return NULL;
1851  }
1852 
1853  for (uint32_t i = 0; i < count; i++)
1854  {
1855  GDALDriverH *drv = GDALGetDriver(i);
1856 
1857 #ifdef GDAL_DCAP_RASTER
1858  /* Starting with GDAL 2.0, vector drivers can also be returned */
1859  /* Only keep raster drivers */
1860  const char *is_raster;
1861  is_raster = GDALGetMetadataItem(drv, GDAL_DCAP_RASTER, NULL);
1862  if (!is_raster || !EQUAL(is_raster, "YES"))
1863  continue;
1864 #endif
1865 
1866  /* CreateCopy support */
1867  const char *cc = GDALGetMetadataItem(drv, GDAL_DCAP_CREATECOPY, NULL);
1868  if (can_write && !cc)
1869  continue;
1870 
1871  /* VirtualIO support */
1872  const char *vio = GDALGetMetadataItem(drv, GDAL_DCAP_VIRTUALIO, NULL);
1873  if (can_write && !vio)
1874  continue;
1875 
1876  /* we can always read what GDAL can load */
1877  rtn[output_driver].can_read = 1;
1878  /* we require CreateCopy and VirtualIO support to write to GDAL */
1879  rtn[output_driver].can_write = (cc != NULL && vio != NULL);
1880 
1881  /* index of driver */
1882  rtn[output_driver].idx = i;
1883 
1884  /* short name */
1885  const char *txt = GDALGetDriverShortName(drv);
1886  size_t txt_len = strlen(txt);
1887  txt_len = (txt_len + 1) * sizeof(char);
1888  rtn[output_driver].short_name = (char *)rtalloc(txt_len);
1889  memcpy(rtn[output_driver].short_name, txt, txt_len);
1890 
1891  /* long name */
1892  txt = GDALGetDriverLongName(drv);
1893  txt_len = strlen(txt);
1894  txt_len = (txt_len + 1) * sizeof(char);
1895  rtn[output_driver].long_name = (char *)rtalloc(txt_len);
1896  memcpy(rtn[output_driver].long_name, txt, txt_len);
1897 
1898  /* creation options */
1899  txt = GDALGetDriverCreationOptionList(drv);
1900  txt_len = strlen(txt);
1901  txt_len = (txt_len + 1) * sizeof(char);
1902  rtn[output_driver].create_options = (char *)rtalloc(txt_len);
1903  memcpy(rtn[output_driver].create_options, txt, txt_len);
1904 
1905  output_driver++;
1906  }
1907 
1908  /* free unused memory */
1909  rtn = rtrealloc(rtn, output_driver * sizeof(struct rt_gdaldriver_t));
1910  *drv_count = output_driver;
1911 
1912  return rtn;
1913 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:219
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:191
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_util.c:342
void * rtrealloc(void *mem, size_t size)
Definition: rt_context.c:199
struct rt_gdaldriver_t * rt_gdaldriver
Definition: librtcore.h:156
int count
Definition: genraster.py:57
uint8_t can_write
Definition: librtcore.h:2630
char * long_name
Definition: librtcore.h:2627
char * create_options
Definition: librtcore.h:2628
char * short_name
Definition: librtcore.h:2626
uint8_t can_read
Definition: librtcore.h:2629

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: