[gdal-dev] Gdal 2.0 vs Gdal 1.x : Testing driver capabilities
Even Rouault
even.rouault at spatialys.com
Wed Oct 14 01:41:44 PDT 2015
Hi Julien,
>
> I am currently trying to make our software (Orfeo ToolBox) both
> compatible with Gdal 1.x (> 1.10) and gdal 2.x. I am almost done but I
> am having a hard time figuring out how to test capabilities on a (former
> OGR) driver.
>
> Indeed, I can see in ogrsf_frmts.h that OGRSFDriver::TestCapability() is
> deprecated :
>
> virtual int TestCapability( const char *pszCap )
> OGR_DEPRECATED("Use GDALDriver class instead") = 0;
>
> However, I can not find such a service in GDALDriver class ... The only
> TestCapability I found is the one of GDALDataset.
>
> I am specifically trying to test the ODrCDeleteDataSource capability on
> the driver, and I can not use the GDALDataset::TestCapability() for that
> (or at least it is not listed in supported capabilities in doxygen of
> this method [1]).
>
> What am I missing here ?
Nothing. There's no equivalent for ODrCDeleteDataSource indeed. In GDAL
drivers (and thus vector drivers that have been converted to GDAL drivers),
the Delete() capability is implemented in a generic way by querying the list
of files that make the dataset and delete them. Drivers may provide a dedicated
implementation instead of that generic one.
Without a dataset, there's no way to know in advance if calling Delete() is
going to do something or not. That's perhaps missing indeed.
A potential workaround is to query drivers for GDAL_DMD_CONNECTION_PREFIX
metadata item that is set for (hopefully most) drivers that are not file based,
and for which Delete() is generally going to raise an error at runtime.
>>> from osgeo import gdal
>>> gdal.GetDriverByName('MYSQL').Delete('MYSQL:autotest')
ERROR 6: Unable to determine files associated with MYSQL:autotest,
delete fails.
3
>>> gdal.GetDriverByName('MYSQL').GetMetadataItem(gdal.DMD_CONNECTION_PREFIX)
'MYSQL:'
>>>
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list