Some quick pointers for using the Python console in QGIS.
1) create reference to a shapefile and open it using OGR
layer = QgsVectorLayer("path\\to\\file.shp", "layer_name_you_like", "ogr") if not layer.isValid(): print "FAIL"
2) Render the layer
QgsMapLayerRegistry.instance().addMapLayer(layer)
3) Interrogate the layer
layer = qgis.utils.iface.activeLayer() layer.getLayerID() layer.featureCount()
Leave a Reply