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