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