So far, we have used the QGIS Console as a glorified Python interpreter, running standard Python programs and manipulating the QGIS user interface. But QGIS is a Geographical Information System (GIS), and one of the main uses of a GIS is to manipulate and query geospatial data. So, let's write some Python code to work with geospatial data directly within the QGIS Console.
In the previous chapter, we loaded three shapefiles into a QGIS project using Python. Here is a typical instruction we used to load a shapefile into a QGIS map layer:
layer = iface.addVectorLayer("/path/to/shapefile.shp", "layer_name", "ogr")
While this is useful if you want to create a QGIS project programmatically, you may just want ...