3

I have a polygon shapefile, with overlapping elements. Currently, QGIS displays the biggest one on top of the others, which hides the smaller ones behind.

Is there a way to change this behaviour and make the bigger polygons go to the back, while raising the smaller ones to the top?

4

It is possible to change the shapefile with ogr2ogr. It is not part of Qgis itself but it is installed alongside when using the osgeo4w installer. If you did so you can go in the start menue to (asuming windows) all programs-osgeo4w-osgeo4w or in your install folder start the OSGeo4W.bat

You then use the function ogr2ogr with the following entry:

ogr2ogr -sql "SELECT * FROM originalfile ORDER BY area DESC" newfile.shp originalfile.shp

You need to put the correct path to files and probably need to create and calculate a field in your shapefile with the area first. The sorting process will put the largest polygons first in the new shapefile and they should therefore be in the background later.

2
  • That's exactly what I needed! Is there a way to avoid writing the full path in the command line for both newfile.shp and originalfile.shp, like working with relative path maybe? – Kantan Jun 22 '16 at 12:45
  • You can navigate in the osgeo4w shell to the folder where the shapefiles are. Then you only need the filenames without path. – Matte Jun 22 '16 at 12:48
1

On the properties of your layer, in the "Style" tab, see "Layer rendering options" at the bottom.

Check "Control feature rendering order" and use the expression :

$area DESC NULLS LAST

enter image description here

1
  • This is a good solution if you want to easily display all the polygons, and it is optimal if you just want to display the polygons on top of each other. However, if you want to select one of the smaller polygons, you will end up selecting the bigger one, even if it is behind graphically. That might be an issue depending on your workflow. – Kantan Jun 23 '16 at 7:46
0

When creating a shapefile, the newest shapes will always be on top (oldest/first created shapes on the bottom). So mitigate against any overlapping issues its best to give some thought to which shapes you want to create first.

Now if you not creating the layer then your stuck with the order (as far as I'm aware). What you can do as a slight work around is create a column in the attribute table identifying the order you wish. Then use the categorised style with this new column. Then under 'Advanced > Symbol Levels...' you can now order how to view the polygons.

You can now see the smaller polygons on the top, but you won't be able to select them normally, as they are technically still underneath the polygon. group selecting (click and drag) will select the polygon plus those polygons around it. You'll just have to deselect those as you go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.