> 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
- 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

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:
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
Qgis-developer mailing list
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to