Examining vector layer features
Once a vector layer is loaded, you may want to investigate the data. In this recipe, we'll load a vector point layer from a shapefile and take a look at the x and y coordinates of the first point.
Getting ready
We'll use the same New York City Museums layer from the Loading a vector layer from a file recipe of this chapter. You can download the layer from https://github.com/GeospatialPython/Learn/raw/master/NYC_MUSEUMS_GEO.zip.
Unzip that file and place the shapefile's contents in a directory named nyc within your qgis_data directory, within your root or home directory.
How to do it...
In this recipe, we will load the layer, get the features, grab the first feature, obtain its geometry, and take a look at the values for the first point:
- First, load the layer:
layer = QgsVectorLayer("/qgis_data/nyc/NYC_MUSEUMS_GEO.shp", "New York City Museums", "ogr") - Next...
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime