QGIS - How to Control the Drawing Order of Map Features

  • Updated

By David Crowther



Is it possible to control the order that Map Features are drawn within QGIS and GeoServer?


Yes, this is possible, and it will enable you to better manage features that may be currently obscured by larger objects on top of them.

Generally, the features in your GIS files e.g. a SQL Table, will be drawn into the map in the order that they were created in the source file/table. This should mean that if you create a new Map feature (e.g. the polygon in yellow below) it will be added to the map in QGIS and GeoServer on top of all other records.


However, it can be possible that for another data source when you create a new feature it is being rendered below existing map features. For example, in this Grounds Maintenance layer, although the WILD FLOWER feature was created after the larger GRASS area, it is being obscured and hidden below the larger Grassed area.



To resolve this in QGIS, choose the Layer Properties and in the Symbology tab tick the option – Control feature rendering order.


Then choose the Order button….


Here you can define the order of how your map features are drawn in the map.

Simply choose a Field of data and decide if you wish to draw the records in descending or ascending order. In this example we are forcing the layer to draw features based on their order in the source SQL table, as we are using the Primary Key qgs_fid field for the draw order.


Once applied, back in the map window, the features in the source GIS file/SQL table will now be rendered in the map using the draw order that you chose. In this example we can see the area of WILD FLOWER is now being drawn above the larger GRASS area because it was digitised more recently and its qgs_fid value is greater than the other map features.


But what about GeoServer?... if we have a WMS that is based on the same GIS file, how can we ensure we have the same drawing order?... see below where by default the WILD FLOWER polygon is again being hidden below the GRASSED area.


Like QGIS you can also force GeoServer to draw the features in the source GIS data/table using an order based on any field in the source data. To do this, simply update your STYLE file (SLD) that you use for publishing the WMS and add this line –

<se:VendorOption name="sortBy">qgs_fid</se:VendorOption>

The field to use for the drawing order is inserted after the SORTBY tag.
Here is the line inserted into my Style File…. where you can see it has been inserted below all RULES and before the end of the FeatureStyle tag.


Once you have updated the Stye file (SLD),… refresh the WMS and you see the drawing order now forces the features to be drawn based on the defined field (qgs_fid), which draws the map features based on when they were last digitised.


… now shown in your desktop GIS or the Cadline webGIS – MapThat – we can see the WMS shows the new features on top of previously digitised features.


Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request



Please sign in to leave a comment.