[Qgis-developer] Corrections of QgsOgrProvider implementaion of GDAL 2.0

Even Rouault even.rouault at spatialys.com
Mon Mar 20 15:12:45 PDT 2017


On lundi 20 mars 2017 22:39:20 CET Mark Johnson wrote:
> > In the provider we could decide to allocate layer ids diffently than OGR .
> > 
> >> Example if you have a dataset with
> > 
> > - layer1 (geom1, geom2)
> > 
> > - layer2 (geom)
> > 
> >> Then you would map that to :
> > - qgis_ogr_provider_layer_id = 1: layer1, geom1
> > 
> > - qgis_ogr_provider_layer_id = 2: layer1, geom2
> > 
> > - qgis_ogr_provider_layer_id = 3: layer2, geom
> 
> Which gdal function would then called for this construction
> - the function that needs an id cannot use qgis_ogr_provider_layer_id
> 
> Some value must also be stored in the project, that must be valid days or
> weeks later.

Good point.

There are different issues you've raised and that we might want handle or not:
1) make sure that a URI points to the same layer if the datasource evolves (new layer)
2) be able to deal with the corner cases of layers with same name

1) involves that we cannot always rely on the index of the layer in the layer list returned by 
OGR
2) involves that we cannot always rely on the layer name to identify uniquely a layer (can 
happen in some drivers like KML)

Fun situation...

So if we want to address both we need the layer_id and layer_name. I'd say when you build a 
OGR URI (mostly in QgisApp::askUserForOGRSublayers()), then look at the uniqueness of the 
layer names. If there's layer name unicity, then use only the layer name. Otherwise fallback to 
uniquely the layer_id (and well in that case if the datasource changes at some point, we 
might have an issue indeed)

On opening in the povider, if you have both the layer_name and layer_id, then prefer the 
layer_name as currently : 
https://github.com/qgis/QGIS/blob/master/src/providers/ogr/qgsogrprovider.cpp#L186

On top of that, we need to add an extra argument to store the geometry column name in the 
URI and in the output of subLayers().
With OGR_FD_GetGeomFieldIndex(feat_defn, geom_field_name) you get the index that 
OGR_F_GetGeomFieldRef(feature, geom_field_index) wil use.

All this would impact mainly AnalyzeURI in qgsogrprovider.cpp, QgsOgrProvider::subLayers() 
and QgisApp::askUserForOGRSublayers()

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170320/70520deb/attachment.html>


More information about the Qgis-developer mailing list