Loading a vector layer from a file sample
This recipe describes the most common type of data used in QGIS, a file. In most cases, you'll start a QGIS project by loading a shapefile.
Getting ready
For ease of following the examples in this book, it is recommended that you create a directory called qgis_data
in your root or user directory, which provides a short pathname. This setup will help prevent the occurrence of any frustrating errors resulting from path-related issues on a given system. In this recipe and others, we'll use a point shapefile of New York City museums, which you can download from https://geospatialpython.googlecode.com/svn/NYC_MUSEUMS_GEO.zip.
Unzip this file and place the shapfile's contents in a directory named nyc
within your qgis_data
directory.
How to do it...
Now, we'll walk through the steps of loading a shapefile and adding it to the map, as follows:
Start QGIS.
From the Plugins menu, select Python Console.
In the Python console, create the layer:
layer = QgsVectorLayer...