In this post, I describe how we can use built-in QGIS processing tools to create a workflow to split polygons into equal parts. Using a clever algorithm and Feature Iterator tool in the Processing Framework, we can easily split all features in a given polygon layer into equal parts.
The algorithm for splitting any polygon shape into equal parts is described in this post PostGIS Polygon Splitting by Paul Ramsey. We will see how this can be implemented in QGIS.
Get the Dataset
Want to follow along? Download the
Splitting a Single Polygon
Let’s say we want to split a single polygon into approximately 4 parts of equal area. Here we have the state of California in the US.
1. Create Random Points within the Polygon
Use the Random Points Inside Polygons tool from the Processing Toolbox to create random points. The more points the better, but for a polygon like this, we can use 1000 points.
2. Create Clusters
If you want to split the polygons into N parts, create N clusters. Here we want to create 4 equal parts, so we use the K-Means clustering tool from the Processing Toolbox to create 4 clusters.
3. Group Cluster Points
Now, use the Aggregate tool to group points from the same cluster and create multipoint geometries from all points belonging to the same cluster.
4. Calculate Cluster Centroids
We can use the Centroids algorithm to calculate the centroid of each multipoint feature.
5. Create Thiessen Polygons
We have centroids for each of the parts. Using the Thiessen Polygons (SAGA) algorithm, we can now create polygons that will divide the region so that each point within the region is assigned to the closest centroid. This will closely match the clusters we computed. The Frame Size parameter controls the buffer region. We can use the size of the bounding box of the polygon to determine the ideal buffer size. It should be at least half of the largest edge of the bounding box.
framesize = max(maxy - miny , maxx - minx )/2
We can also use the QGIS’s native Voronoi Polygons algorithm here, but if all the centroids are in a single line, it can fail to create thiessen polygons that cover the original geometry – even with a large buffer specified.
6. Clip Thiessen Polygons to Original Polygon Boundary
Using the Intersection tool, we can now overlay the thiessen polygons on the original polygon layer to split it into 4 equal parts.
The result is what we want. The original polygon split into 4 equal parts.
Splitting Multiple Polygons
What if you want to split multiple polygons into equal parts? We can build a model to build a workflow of all the steps in the previous section and run it on each polygon. Below is the screenshot of a model built using the QGIS Processing Modeler. You can download and install this model from the Spatial Thoughts QGIS Resource Sharing repository.
Once installed, you can launch it from the Processing Toolbox. We will run it on a polygon layer containing of all states of the US.
When running the model, we want to split each polygon. Select the
tl_2019_us_state layer as the Polygons layer and make sure to click the Iterate Feature button. Once configured, click Run.
Once the processing finishes, you will end up with 1 layer per state. Each layer contains the split polygons for that state.
The final step is to merge all these layers into a single layer containing all split polygons. We can use the Merge vector layers algorithm to accomplish this.
The result is the original US States layer split with 4 equal parts of each state.
There are a few existing QGIS plugins and methods that can also help with the polygon division task:
- Cadastral Divisions Plugin: If you are looking to split land parcels, this plugin can interactively help you find the correct divisions.
- Polygon Divider Plugin: If you are looking to divide a large polygon into many small regularly sized polygons, this is the plugin for you.
- Split Polygins using PyQGIS: A blog post by Luísa Lucchese showing how to use PyQGIS to split many polygons using a technique similar to this post.
Found this post useful? Do let me know in the comments!
If you want to learn and master techniques for automating your GIS workflows with QGIS and earn official QGIS.org certification, check out my course Advanced QGIS.
Leave a Comment
There is a plugin doing that.
Thanks for sharing! I checked it out and it works well. The use case seems to be more geared towards parcel splitting as it requires a reference line for direction in which to split the polygon. But it is definitely better to use this plugin for cadastre data. I have updated the blog post to include a link to it.
Thank you, Giulio will be happy!
Instead of using Aggregate and then Centroids, you can just use Mean Coordinates with CLUSTER_ID as the unique ID field. And if SAGA isn’t working on your installation, the native “Voronoi polygons” algorithm does the same thing.
The “Mean Coordinates” algorithm is a good suggestion and will save one step. Thanks!
I have mentioned the reason for using SAGA’s Thiessen Polygon algorithm in the post. “…QGIS’s native Voronoi Polygons algorithm here, but if all the centroids are in a single line, it can fail to create thiessen polygons that cover the original geometry – even with a large buffer specified…”
Hello, Mr. Ujaval Gandhi! This post is very helpful and was one of my inspirations for automatizing the polygon division procedure using PyQGIS. My pipeline differs from yours but the idea behind it is the same. I also linked your post in my blog post. Here is the link if you wish to check it out: https://www.luisalucchese.com/post/split-polygons-pyqgis/
Thanks for sharing. I have added a link to your blog post as some readers may find it helpful to know how to implement this in PyQGIS.
I’m glad you liked it! Thank you!
I have state shp/geojson file for a state but I need to make small modification in it like one particular district from it divided into two districts and I just need to draw approximate line to split that district. I tried http://geojson.io/ and https://mapshaper.org/ but could not do it.
You can use the ‘advanced digitizing toolbar’ in QGIS. Select the district and use ‘Split Features’ tool. See this video for more info https://www.youtube.com/watch?v=3H9X-ZkoHYY