[GIS] QGIS split rectangular polygon in grid

editinggeometry-conversionqgis

I have this selected rectangular polygon in yellow on a layer with hundreds of polygons:

enter image description here

I need to split the selected polygon in 4 vertical columns (Y axis) and 8 horizontal rows (X axis), so that I get 32 final same-sized polygons. Something like this should be the output:

enter image description here

I have tested these plugins with no success so far:

  • Polygon Divider
  • Polygon Splitter
  • Split Polygon
  • Split Features on steroids

EDITED 19.12.2018:

Well in fact I have a layer with hundreds of polygons. It is my town's graveyard and it is divided in zones:
enter image description here

I need to split some of them in smaller tiles (real graves, pantheons, etc) so that I can locate each buried person in his parcel (tile).

In the above image I showed three zones.
Polygon 1: has to be split in 1(columns)x 40(rows) so there would be finally 40 polygons (graves).

Polygon 2: has to be split in 2(columns)x 50(rows) so there would be finally 100 polygons (graves).

Polygon 3: has to be split in 2(columns)x 3(rows) so there would be finally 6 polygons (graves).

All the polygons that need to be split have square-rectangle shape; only 4 sides.

EDIT 20.12.2018:

Array of offset (parallel) lines tool is not working well in my case. Seems that rectangles are not perfect (horizontal sides do not have exact same length, same with vertical). See image below:

enter image description here

Best Answer

I went through a relatively convoluted way of doing it without having to script anything in Python or without having to resort to plugins. It's still semi-manual and includes some nested expressions but it works. Bear in mind this was done in QGIS 3.4. Some features used might not be available in earlier versions. To further automate the process, it could be made into a processing model.

First off, this method takes a few things for granted:

  • Layer is in a projected CRS
  • Zone polygons need to be "perfect" rectangles
  • Each zone polygon needs two fields where the number of divisions for each axis is present

The original data I used looks like this:

enter image description here

From there, a sequence of tools can be used to go from the original zones to subdivided plots (every tool takes as input layer the output of the previous tool):

  • Using the Polygons to lines tool, transform your zones into polylines.
  • Using the Explode lines tool, break each side into separate segments.
  • Using the Extract by expression tool, get only the two first segments of a rectangle with this expression (it tests for an array of only first and second segments of exploded sides):

    array_intersect(array($id), array_cat(generate_series(1, maximum($id) - 2, 4), generate_series(2, maximum($id) - 2, 4)))
    
  • Using the Field calculator tool, create a new field (in my case called len_seg) of type float where $length is calculated

  • Using the Array of offset (parallel) lines tool, create the plot subdivision lines with these expressions in the relevant parameters (it's convenient that the segments' right side is always inside the original polygon. I had to round the segment lengths before evaluating them as it seems there might be slight differences between opposite sides even for 'perfect' rectangles):

    Number of features to create:

    if(round("len_seg",3) = minimum(round("len_seg",3),group_by:="fid"),"plot_max"-1,"plot_min"-1)
    

    Offset step distance:

    if(round("len_seg",3) = minimum(round("len_seg",3),group_by:="fid"),(maximum("len_seg",group_by:="fid")/"plot_max")*-1, (minimum("len_seg",group_by:="fid")/"plot_min")*-1)
    
  • After this, you'll end up with a large number of offset lines layers. Using the Merge vector layers tool, combine the initial exploded segments and offset lines into one layer.
  • Using the Extend lines tool, add a small value (I added 0.02 in my example) to the plot lines. This ensures angled rectangles have complete polygon rings for the last step.
  • Using the Polygonize tool, convert that merged layer into polygons.

The result looks like this:

enter image description here

Related Question