Using NULL values in PyQGIS
QGIS can use NULL values as field values. Python has no concept of NULL values. The closest type it has is the None
type. You must be aware of this fact when working with Python in QGIS. In this recipe, we'll explore the implications of QGIS's NULL values in Python. The computing of a NULL value involves a pointer that is an uninitialized, undefined, empty, or meaningless value.
Getting ready
In your qgis_data/shapes
directory, download the shapefile from https://geospatialpython.googlecode.com/svn/NullExample.zip, which contains some NULL field values, and unzip it.
How to do it...
We will load the shapefile and grab its first feature. Then, we'll access one of its NULL field values. Next, we'll run through some tests that allow you to see how the NULL values behave in Python. To do this, we need to perform the following steps:
- First, we'll load the shapefile and access its first feature:
lyrPth = "/qgis_data/shapes/NullExample.shp"...