Adding a set of attributes to a vector layer
Each QGIS feature has two parts: the geometry and the attributes. In this recipe, we'll add an attribute for a layer from an existing dataset.
Getting ready...
We will use a point shapefile with museum data for New York City, which you can download as a ZIP file from the following URL:
https://github.com/GeospatialPython/Learn/raw/master/NYC_MUSEUMS_GEO.zip
Extract this shapefile to the following directory: /qgis_data/nyc
How to do it...
While you can add a geometry to a feature without attributes, you must have at least a geometry in order to add attributes. So, we will create a new feature, add some attributes, and then add everything to the layer:
- Start QGIS.
- From the Plugins menu, select Python Console ...
Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.