Graphics Reference
In-Depth Information
layer.setRendererV2(QgsCategorizedSymbolRendererV2("region",
categories))
layer.triggerRepaint()
There's only one more thing to do, since this is a script that can be run multiple times, let's
have our script automatically remove the existing continents layer, if it exists, before
adding a new one. To do this, we can add the following to the start of our script:
layer_registry = QgsMapLayerRegistry.instance()
for layer in layer_registry.mapLayersByName("continents"):
layer_registry.removeMapLayer(layer.id())
Now when our script is run, it will create one (and only one) layer that shows the various
continents in different colors. These will appear as different shades of gray in the printed
topic, but the colors will be visible on the computer screen:
Now, let's use the same data set to color each country based on its relative population.
We'll start by removing the existing "population" layer, if it exists:
Search WWH ::




Custom Search