Iterating over layers
For many GIS operations, you need to loop through the map layers to look for specific information or to apply a change to all the layers. In this recipe, we'll loop through the layers and get information about them.
Getting ready
We'll need two layers in the same map projection to perform this recipe. You can download the first layer as a ZIP file from https://github.com/GeospatialPython/Learn/raw/master/MSCities_Geo_Pts.zip.
You can download the second zipped layer from https://github.com/GeospatialPython/Learn/raw/master/Mississippi.zip.
Unzip both of these layers into a directory named ms
within your qgis_data
 directory.
How to do it...
We will add the layers to the map through the map registry. Then, we will iterate through the map layers and print each layer's title. To do this, perform the following steps:
First, let's open the polygon and the point layer using Python Console:
lyr_1 = QgsVectorLayer("/qgis_data/ms/mississippi.shp", ...