The most direct way to interact with the QGIS API (short for Application Programming Interface) is through the Python Console, which can be opened by going to Plugins | Python Console. As you can see in the following screenshot, the Python Console is displayed within a new panel below the map:
Our access point for interaction with the application, project, and data is the iface
object. To get a list of all the functions available for iface
, type help(iface)
. Alternatively, this information is available online in the API documentation at http://qgis.org/api/classQgisInterface.html.
One of the first things we will want to do is to load some data. For example, to load a vector layer, we use the addVectorLayer()
function of iface
:
v_layer = iface.addVectorLayer('C:/Users/anita/Documents/Geodata/qgis_sample_data/shapefiles/airports.shp','airports','ogr')
When we execute this command, airports.shp
will be loaded using the ogr
driver...