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 values of the first point.
We'll use the same New York City Museums layer from Loading a vector layer from a file recipe in this chapter. You can download the layer from https://geospatialpython.googlecode.com/svn/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.
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:
layer = QgsVectorLayer("/qgis_data/nyc/NYC_MUSEUMS_GEO.shp", "New York City Museums", "ogr")
features = layer.getFeatures()
f = features.next()
g = f.geometry()
g.asPoint()
(-74.0138,40.7038)