[Qgis-developer] ogrLayerName in processing/tools/vector.py
Mark Johnson
mj10777 at googlemail.com
Tue Oct 18 02:00:54 PDT 2016
>
> What do you mean by "opening the source" and "retrieving the layer" ?
> They sound like the same operation to me ?
In the Python code you are using the OGR Interface
ds = ogr.Open(ogruri)
in c++ (as used in QgsOgrProvider) this corresponds to:
OGRDataSourceH hDS = OGROpen( pszPath, bUpdate, &hDriver );
it will only open the Datasource for use.
OGR will read the datasource and create the infastructure needed during
reading
- such as a list of layers
-- in gdal 1.* each geometry is 1 layer (with only 1 geometry-field)
-- in gdal 2.* each table is 1 layer that may contain more than 1
geometry-field
At this point you can decide what to do
- list the layers and the fields
- select a specific layer with a geometry-field
Either with the layer-id:
python:
ly = ds.GetLayer(layerid)
in c++ (as used in QgsOgrProvider) this corresponds to:
ogrLayer = OGR_DS_GetLayer( ogrDataSource, iLayerIndex );
or with the layer-name
ogrLayer = OGR_DS_GetLayerByName( ogrDataSource, TO8( sLayerName ) );
when all tasks are completed, the Datasource is closed.
Inside QgsOgrProvider all of this is done as needed, but when using the
OGR-API directly each step must be done manually.
Mark Johnson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20161018/cd34a44f/attachment.html>
More information about the Qgis-developer
mailing list