Skip to main content
added 1906 characters in body
Source Link
Babel
  • 80.4k
  • 15
  • 97
  • 245

If you have not one set of 4 points, but several ones, you can slightly modify the expression to subdivide all rectangles at once. For this, you have to define an array for each rectangle, listing the points as you can see in the screenshot (find the expression below):

enter image description here

collect_geometries( case when @id=1 -- must be a valid $id value of one of the points then with_variable('no',13, -- no. of sub-polygons you want the polygon to divide into array_foreach( array ( array (0,1,19,18), array (19,18,20,15), array(22,11,23,10), array(20,15,21,14), array(21,14,22,11), array(2,3,17,4), array(17,4,16,5), array(16,5,13,6), array(13,6,12,7), array(12,7,9,8) ), with_variable( 'line1', make_line ( geometry (get_feature_by_id ('points', @element[0])), -- $id of point at bottom left geometry (get_feature_by_id ('points', @element[1])) -- $id of point at bottom right ), with_variable( 'line2', make_line ( geometry (get_feature_by_id ('points', @element[2])), -- $id of point at top left geometry (get_feature_by_id ('points', @element[3])) -- $id of point at top right ), collect_geometries ( array_foreach ( generate_series (1,@no), make_polygon( make_line( end_point( line_substring ( @line1, 0, length(@line1)/@no*(@element-1) ) ), end_point( line_substring ( @line1, 0, length(@line1)/@no*@element ) ), end_point( line_substring ( @line2, 0, length(@line2)/@no*@element ) ), end_point( line_substring ( @line2, 0, length(@line2)/@no*(@element-1) ) ) )))))))) end ) 

If you have not one set of 4 points, but several ones, you can slightly modify the expression to subdivide all rectangles at once. For this, you have to define an array for each rectangle, listing the points as you can see in the screenshot (find the expression below):

enter image description here

collect_geometries( case when @id=1 -- must be a valid $id value of one of the points then with_variable('no',13, -- no. of sub-polygons you want the polygon to divide into array_foreach( array ( array (0,1,19,18), array (19,18,20,15), array(22,11,23,10), array(20,15,21,14), array(21,14,22,11), array(2,3,17,4), array(17,4,16,5), array(16,5,13,6), array(13,6,12,7), array(12,7,9,8) ), with_variable( 'line1', make_line ( geometry (get_feature_by_id ('points', @element[0])), -- $id of point at bottom left geometry (get_feature_by_id ('points', @element[1])) -- $id of point at bottom right ), with_variable( 'line2', make_line ( geometry (get_feature_by_id ('points', @element[2])), -- $id of point at top left geometry (get_feature_by_id ('points', @element[3])) -- $id of point at top right ), collect_geometries ( array_foreach ( generate_series (1,@no), make_polygon( make_line( end_point( line_substring ( @line1, 0, length(@line1)/@no*(@element-1) ) ), end_point( line_substring ( @line1, 0, length(@line1)/@no*@element ) ), end_point( line_substring ( @line2, 0, length(@line2)/@no*@element ) ), end_point( line_substring ( @line2, 0, length(@line2)/@no*(@element-1) ) ) )))))))) end ) 
added 147 characters in body
Source Link
Babel
  • 80.4k
  • 15
  • 97
  • 245

Use the following expression (see below) with Geometry by expression, making the following adaptations:

Run Multipart to singleparts on the resulting layer to get separate features.

Works even for irregularily shaped polygons: enter image description here

Use the following expression with Geometry by expression, making the following adaptations:

Run Multipart to singleparts on the resulting layer to get separate features.

Use the following expression (see below) with Geometry by expression, making the following adaptations:

Run Multipart to singleparts on the resulting layer to get separate features.

Works even for irregularily shaped polygons: enter image description here

added 290 characters in body
Source Link
Babel
  • 80.4k
  • 15
  • 97
  • 245

Use thisthe following expression with Geometry by expression, making the following adaptations:

  • replace the $id@id of the points at the bottom/top - right/left (use a label with $id@id to see which point has which id); See QGIS documentation: @id is the newer syntax to use for the older $id, so in older QGIS versions, you might have to replace @id with $id
  • in line 2 ($id=1), change 1 to any number of the $id of one of the points
  • in line 3, change the number to define the numbor of polygons you want to create and replace
  • replace points with the name of your points layer

Run Multipart to singleparts on the resulting layer to get separate features.

This is the expression to use:

case when $id=1@id=1 -- must be a valid $id@id value of one of the points then with_variable('no',13, -- no. of sub-polygons you want the polygon to divide into with_variable( 'line1', make_line ( geometry (get_feature_by_id ('points', 0)), -- $id@id of point at bottom left geometry (get_feature_by_id ('points', 1)) -- $id@id of point at bottom right ), with_variable( 'line2', make_line ( geometry (get_feature_by_id ('points', 3)), -- $id@id of point at top left geometry (get_feature_by_id ('points', 2)) -- $id@id of point at top right ), collect_geometries ( array_foreach ( generate_series (1,@no), make_polygon( make_line( end_point( line_substring ( @line1, 0, length(@line1)/@no*(@element-1) ) ), end_point( line_substring ( @line1, 0, length(@line1)/@no*@element ) ), end_point( line_substring ( @line2, 0, length(@line2)/@no*@element ) ), end_point( line_substring ( @line2, 0, length(@line2)/@no*(@element-1) ) ) ))))))) end 

The expression in use, here with Geometry Generator (just for visual purpose, not creating actual geometries): enter image description here

Use this expression with Geometry by expression, making the following adaptations:

  • replace the $id of the points at the bottom/top - right/left (use a label with $id to see which point has which id)
  • in line 2 ($id=1), change 1 to any number of the $id of one of the points
  • in line 3, change the number to define the numbor of polygons you want to create and replace
  • replace points with the name of your points layer
case when $id=1 -- must be a valid $id value of one of the points then with_variable('no',13, -- no. of sub-polygons you want the polygon to divide into with_variable( 'line1', make_line ( geometry (get_feature_by_id ('points', 0)), -- $id of point at bottom left geometry (get_feature_by_id ('points', 1)) -- $id of point at bottom right ), with_variable( 'line2', make_line ( geometry (get_feature_by_id ('points', 3)), -- $id of point at top left geometry (get_feature_by_id ('points', 2)) -- $id of point at top right ), collect_geometries ( array_foreach ( generate_series (1,@no), make_polygon( make_line( end_point( line_substring ( @line1, 0, length(@line1)/@no*(@element-1) ) ), end_point( line_substring ( @line1, 0, length(@line1)/@no*@element ) ), end_point( line_substring ( @line2, 0, length(@line2)/@no*@element ) ), end_point( line_substring ( @line2, 0, length(@line2)/@no*(@element-1) ) ) ))))))) end 

The expression in use, here with Geometry Generator: enter image description here

Use the following expression with Geometry by expression, making the following adaptations:

  • replace the @id of the points at the bottom/top - right/left (use a label with @id to see which point has which id); See QGIS documentation: @id is the newer syntax to use for the older $id, so in older QGIS versions, you might have to replace @id with $id
  • in line 2 ($id=1), change 1 to any number of the $id of one of the points
  • in line 3, change the number to define the numbor of polygons you want to create and replace
  • replace points with the name of your points layer

Run Multipart to singleparts on the resulting layer to get separate features.

This is the expression to use:

case when @id=1 -- must be a valid @id value of one of the points then with_variable('no',13, -- no. of sub-polygons you want the polygon to divide into with_variable( 'line1', make_line ( geometry (get_feature_by_id ('points', 0)), -- @id of point at bottom left geometry (get_feature_by_id ('points', 1)) -- @id of point at bottom right ), with_variable( 'line2', make_line ( geometry (get_feature_by_id ('points', 3)), -- @id of point at top left geometry (get_feature_by_id ('points', 2)) -- @id of point at top right ), collect_geometries ( array_foreach ( generate_series (1,@no), make_polygon( make_line( end_point( line_substring ( @line1, 0, length(@line1)/@no*(@element-1) ) ), end_point( line_substring ( @line1, 0, length(@line1)/@no*@element ) ), end_point( line_substring ( @line2, 0, length(@line2)/@no*@element ) ), end_point( line_substring ( @line2, 0, length(@line2)/@no*(@element-1) ) ) ))))))) end 

The expression in use, here with Geometry Generator (just for visual purpose, not creating actual geometries): enter image description here

added 1047 characters in body
Source Link
Babel
  • 80.4k
  • 15
  • 97
  • 245
Loading
Source Link
Babel
  • 80.4k
  • 15
  • 97
  • 245
Loading