[Qgis-developer] use ogr2ogr in a plugin

Even Rouault even.rouault at spatialys.com
Thu Oct 29 01:55:09 PDT 2015


Le jeudi 29 octobre 2015 09:38:38, Victor Olaya a écrit :
> 2015-10-29 9:18 GMT+01:00 Matthias Kuhn <matthias at opengis.ch>:
> > Hi Denis,
> > 
> > I assume the path env variable should be appropriately set in all OS'es
> > when inside QGIS so calling ogr2ogr (e.g. subprocess.call( 'ogr2ogr
> > params' ) should just work. But to be honest, I never tried.
> > 
> > Matthias
> 
> That's actually what the ogr2ogr algorithm in Processing does...
> 
> https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/gda
> l/ogr2ogr.py 

Just taking advantage of this thread to advertize RFC 59.1 : GDAL/OGR 
utilities as a library that will be part of GDAL 2.1 :

https://trac.osgeo.org/gdal/wiki/rfc59.1_utilities_as_a_library

And the current hardcoded list of formats and extensions could be dynamically 
populated from the metadata of drivers starting with GDAL 2.0 :

from osgeo import gdal
for i in range(gdal.GetDriverCount()):
    drv = gdal.GetDriver(i)
    if drv.GetMetadataItem(gdal.DCAP_VECTOR) and \
      drv.GetMetadataItem(gdal.DCAP_CREATE):
        extensions = drv.GetMetadataItem(gdal.DMD_EXTENSIONS)
        if extensions is not None:
            print('%s: %s' % (drv.GetDescription(), extensions))


Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the Qgis-developer mailing list