For the Mapping North Korea project I had to split a region into smaller sectors. In other words, I had to create a raster or grid inside the polygon so that the tasks wouldn't be too big to handle. The polygons used in this example are exported from Overpass Turbo, the OpenStreetMap querying tool.
1. Add an OpenStreetMap base layer for reference
Go to Layer -> Data Source Manager and in the left menu scroll down to XYZ. Then select OpenStreetMap and press Add.
2. Add the Polygon(s)
Drag your geojson file into the section at the red arrow. This will automatically create a new layer with the right projection. If you don't have any geojson file then you can also manually create a layer and draw a polygon of course.
Make sure the layer is set to the correct projection. It is probably set automatically.
Now you have a layer with a random color as shown below. In this image I'm not using one polygon but several polygons from a feature collection. The polygons are counties and special administrative regions in North Korea.
3. Create a grid
To turn the polygon into a grid, you have to create a grid on top of the polygon, and then intersect it's lines. To create the grid, go to Vector -> Research Tools -> Create Grid.
Select Rectangle as the grid type and define the horizontal and vertical spacing size. I set them to 2 by 2 km squares.
In the Grid extent section select Calculate from layer -> the polygon layer you added. This automatically takes the bounding box of the polygon layer and creates a grid in this bounding box. Cick run and close the window when the operation is completed. See the picture in the next section of what the result should look like.
4. Intersect the grid with the polygon
Now we intersect the grid with the polygon to get the final grid inside the polygon shapes. Select Vector -> Geoprocessing Tools -> Intersection.
As the input layer select the polygon and as the overlay layer select the grid that you created in the previous step. Cick run and close the window when the operation is completed.
What you see then should look something like this.
To get a better view of your final sectors disable the original polygon and the grid and set the transparancy of the layer to 50% so you can see through it to the underlying map.
5. Export the new raster
If you're satisfied with the result, export the layer by right clicking it -> Export -> Save Feature As.
Then select a file location and the desired output parameters. The nice thing about this is that all the smaller grid polygons inherited the properties from the original polygon. Don't forget to check if the CRS is set to the right value.
Bonus: Avoid problems by checking the coordinate system
Make sure the coordinate system is set to the correct option. For the Mapping North Korea project we use EPSG:357 (WGS 84). Not setting the right coordinate system can create some issues.
This is truly educative!
Thanks š
How to give spacing in degrees for EPSG 32643
Hello,
First thanks for theĀ Turning a polygon into a grid with QGIS tutorial, but I am wondering which version of QGIS 3.xy was used that gives the option of kilometers in the horizontal and vertical spacing. Because I have checked with the current version and several versions that came before only give theĀ degrees option.Ā Thanks, again
Hey, I had the same problem. It depends on the coordinate system you are using. Try using one with meters as unit.
Thanks, this is extremely helpful!
Appreciate this tutorial, easy to follow, thank you very much