


We must remember repaint the layerto force the update:Ĭhanging the color of a layer sounds trivial, but remember in QGIS anything you see must be altered through the canvas API.Therefore we add the layer to the map and access the layer’s symbology through its renderer.Once we have the symbol, we can set its color:.Next we reference the first symbol which in this case is the only symbol:.Now we access the layer’s symbol list through the layer’s renderer object:.QgsMapLayerRegistry.instance().addMapLayer(lyr) Then we add it to the map layer registry:.Lyr = QgsVectorLayer(“/Users/joellawhead/qgis_data/ms/mississippi.shp”, “Mississippi”, “ogr”) First, using the QGIS Python Console, we must import the QtGui library in order to access the QColor object used to describe colors in the PYQGIS API:.We will load a layer, add it to the map layer registry, change the layer’s color, and then refresh the map. In this recipe, we’ll load a vector layer, change its symbology, and refresh the map.ĭownload the following zipped shapefile and extract it to your qgis_data directory into a folder named ms. The symbols describe properties including color, shape, size, and line width. The renderer provides rules dictating the appearance of symbols. A layer’s symbology includes the renderer and one or more symbols. The appearance of layers on a QGIS map are controlled by its symbology.
Python convert raster to vector how to#
With 140 short, reusable recipes to automate geospatial processes in QGIS, the QGIS Python Programming CookBook teaches readers how to use Python and QGIS to create and transform data, produce appealing GIS visualizations, and build complex map layouts. Learn how to symbolize vector and raster layers in QGIS using programming from this section as part of this preview chapter, Creating Dynamic Maps from QGIS Python Programming CookBook.
