QGIS - How to Control the Drawing Order of Map Features

Marketing
Marketing
  • Updated

By David Crowther

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_1.JPG

Question:

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

Answer:

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.

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_2.JPG

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.

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_3.JPG

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_4.JPG

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

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_5.JPG

Then choose the Order button….

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_6.JPG

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.

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_7.JPG

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.

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_8.JPG

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.

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_9.JPG

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.

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_10.JPG

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.

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_11.JPG

… 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.

QGIS_-_How_to_Control_the_Drawing_Order_of_Map_Features_-_12.JPG

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.