test_qgsvectordataprovider.py
| 1 |
from qgis.core import * |
|---|---|
| 2 |
|
| 3 |
QgsApplication.setPrefixPath('/usr/local', True) |
| 4 |
QgsApplication.initQgis() |
| 5 |
# load a layer
|
| 6 |
vlayer = QgsVectorLayer('polygons.shp', 'layer_name', 'ogr') |
| 7 |
if vlayer.isValid():
|
| 8 |
print 'layer is valid' |
| 9 |
# get the data provider
|
| 10 |
vprovider = vlayer.dataProvider() |
| 11 |
# get index of field 'name'
|
| 12 |
name_index = vprovider.fieldNameIndex('name')
|
| 13 |
# there are NULL values in the field 'name' on sample dataset
|
| 14 |
unique = vprovider.uniqueValues(name_index) |
| 15 |
print unique
|