PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 1716 of file rt_raster.c.

1717{
1718 assert(drv_count != NULL);
1719 uint32_t output_driver = 0;
1721 uint32_t count = (uint32_t)GDALGetDriverCount();
1722
1723 rt_gdaldriver rtn = (rt_gdaldriver)rtalloc(count * sizeof(struct rt_gdaldriver_t));
1724 if (!rtn)
1725 {
1726 rterror("rt_raster_gdal_drivers: Could not allocate memory for gdaldriver structure");
1727 *drv_count = output_driver;
1728 return NULL;
1729 }
1730
1731 for (uint32_t i = 0; i < count; i++)
1732 {
1733 GDALDriverH *drv = GDALGetDriver(i);
1734
1735#ifdef GDAL_DCAP_RASTER
1736 /* Starting with GDAL 2.0, vector drivers can also be returned */
1737 /* Only keep raster drivers */
1738 const char *is_raster;
1739 is_raster = GDALGetMetadataItem(drv, GDAL_DCAP_RASTER, NULL);
1740 if (!is_raster || !EQUAL(is_raster, "YES"))
1741 continue;
1742#endif
1743
1744 /* CreateCopy support */
1745 const char *cc = GDALGetMetadataItem(drv, GDAL_DCAP_CREATECOPY, NULL);
1746 if (can_write && !cc)
1747 continue;
1748
1749 /* VirtualIO support */
1750 const char *vio = GDALGetMetadataItem(drv, GDAL_DCAP_VIRTUALIO, NULL);
1751 if (can_write && !vio)
1752 continue;
1753
1754 /* we can always read what GDAL can load */
1755 rtn[output_driver].can_read = 1;
1756 /* we require CreateCopy and VirtualIO support to write to GDAL */
1757 rtn[output_driver].can_write = (cc != NULL && vio != NULL);
1758
1759 /* index of driver */
1760 rtn[output_driver].idx = i;
1761
1762 /* short name */
1763 const char *txt = GDALGetDriverShortName(drv);
1764 size_t txt_len = strlen(txt);
1765 txt_len = (txt_len + 1) * sizeof(char);
1766 rtn[output_driver].short_name = (char *)rtalloc(txt_len);
1767 memcpy(rtn[output_driver].short_name, txt, txt_len);
1768
1769 /* long name */
1770 txt = GDALGetDriverLongName(drv);
1771 txt_len = strlen(txt);
1772 txt_len = (txt_len + 1) * sizeof(char);
1773 rtn[output_driver].long_name = (char *)rtalloc(txt_len);
1774 memcpy(rtn[output_driver].long_name, txt, txt_len);
1775
1776 /* creation options */
1777 txt = GDALGetDriverCreationOptionList(drv);
1778 txt_len = strlen(txt);
1779 txt_len = (txt_len + 1) * sizeof(char);
1780 rtn[output_driver].create_options = (char *)rtalloc(txt_len);
1781 memcpy(rtn[output_driver].create_options, txt, txt_len);
1782
1783 output_driver++;
1784 }
1785
1786 /* free unused memory */
1787 rtn = rtrealloc(rtn, output_driver * sizeof(struct rt_gdaldriver_t));
1788 *drv_count = output_driver;
1789
1790 return rtn;
1791}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
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:444
void * rtrealloc(void *mem, size_t size)
Definition rt_context.c:199
struct rt_gdaldriver_t * rt_gdaldriver
Definition librtcore.h:155
int count
Definition genraster.py:57
uint8_t can_write
Definition librtcore.h:2693
char * create_options
Definition librtcore.h:2691

References rt_gdaldriver_t::can_read, rt_gdaldriver_t::can_write, 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 main(), RASTER_getGDALDrivers(), rtpg_assignHookGDALEnabledDrivers(), and test_gdal_drivers().

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