A CSV file contains columns latitude
, longitude
and color
.
uri = "file:///C:/data/balls.csv?type=csv&xField=longitude&yField=latitude&spatialIndex=no&subsetIndex=no&watchFile=no"
vlayer = QgsVectorLayer(uri, 'Balls', "delimitedtext")
Using the Python console in QGIS, how can we draw each row in the CSV as a point whose color depends on the value in the color
column of the imported CSV?
It's my understanding that QgsDataSourceURI.setDataSource()
can do such a WHERE query during the import, but only works on PostGIS.
Best Answer
To do that you should access to data defined properties for the symbol layer and set the color by passing the field name as expression. You can do it like: