[Qgis-developer] Python access to ogr provider datasource layer name

Dane Springmeyer blake at hailmail.net
Wed Jun 3 11:27:43 EDT 2009


Hello Godofredo,

Thanks!

Dane


On Jun 2, 2009, at 6:54 PM, godofredo contreras wrote:

>
> Hi Dane:
>
> Sublayers returns a QStringList with one string per layer, the  
> string has four components separated by a ":", the components are:
>
> LayerIndex : LayerName : FeatureCount : GeometryType
>
> Regards
>
> Godofredo Contreras
>
>
> > From: blake at hailmail.net
> > To: qgis-developer at lists.osgeo.org
> > Date: Tue, 2 Jun 2009 17:54:04 -0700
> > Subject: [Qgis-developer] Python access to ogr provider datasource  
> layer name
> >
> > So OGR has this notion of data files and then their layers. I'm  
> trying
> > to figure out in QGIS how to get at this information via python for
> > data loaded into QGIS.
> >
> > For example, for this sample gml file: http://svn.osgeo.org/gdal/trunk/autotest/ogr/data/ionic_wfs.gml
> >
> > ogrinfo -so -al gives:
> >
> > Had to open data source read-only.
> > INFO: Open of `/Users/spring/src/gdal/autotest/ogr/data/ 
> ionic_wfs.gml'
> > using driver `GML' successful.
> >
> > Layer name: GEM
> > Geometry: Unknown (any)
> > Feature Count: 1
> > Extent: (437.000000, 51131.000000) - (44137.000000, 511549.000000)
> > Layer SRS WKT:
> > (unknown)
> > Name: String (0.0)
> >
> > What I am looking for is access to the name 'GEM'.
> >
> > Via python I notice that 'subLayers()' are empty:
> >
> > >>> l = iface.mapCanvas().layer(0)
> > >>> l.subLayers()
> > <PyQt4.QtCore.QStringList object at 0x13101618>
> > >>> l.subLayers()[0]
> > exceptions.IndexError: sequence index out of range
> >
> > While the provider subLayers have the name embedded in an odd  
> Qstring:
> > >>> l.dataProvider().subLayers()[0]
> > 0:GEM:0:Unknown
> >
> > Is parsing this string they best way to get at this information?  
> What
> > happens in QGIS when there are multiple layers?
> >
> > Running this on a shapefile and a GeoJSON file I get this:
> >
> > >>> l.dataProvider().subLayers()[0]
> > 0:statesp020:2895:Polygon
> >
> > http://svn.osgeo.org/gdal/trunk/autotest/ogr/data/multipolygon.geojson
> > >>> l.dataProvider().subLayers()[0]
> > 0:OGRGeoJSON:1:Unknown WKB: 6
> >
> > Can anyone explain what those numbers mean - Number of features?
> >
> > Thanks,
> >
> > Dane
> > _______________________________________________
> > Qgis-developer mailing list
> > Qgis-developer at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
> Lauren found her dream laptop. Find the PC that’s right for you.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20090603/f5d30c0c/attachment.html


More information about the Qgis-developer mailing list