1

I am using QGIS 3.10.

I am trying to split multiple rectangle polygons diagonally into 2 parts using "Geometry by expression" under Processing. This is for symbology only (exporting for use elsewhere), so attribute retention is not necessary. For symbolizing diagonally split rectangles in QGIS, I successfully produced a two-layered geometry-generated symbology for each rectangle using:

Top layer: make_triangle(point_n($geometry,1), point_n ($geometry,2),point_n( $geometry,3))

Bottom layer: make_triangle(point_n($geometry,3), point_n ($geometry,4),point_n( $geometry,1))

This is fine for symbology, but now I need to reproduce those triangles as saved geometry.

Using Geometry by expression, I used the following, which only produces one triangle:

collect_geometries(make_triangle(point_n($geometry,1), point_n($geometry,2),point_n( $geometry,3)),(make_triangle(point_n($geometry,3), point_n ($geometry,4),point_n( $geometry,1))))

The expression builder accepts the whole expression above with no errors - just produces one element (see figure, blue polys).

Plugin Polygon divider doesn't accommodate corner to corner splits.

Also tried "Combine" expression in place of "collect geometries"

This should be simple, but I can't find any native command or plugin for the job.

enter image description here

2
  • 1
    Is the split unambiguous, i.e. allways make triangles of points 1,2,3 and 3,4,1 or does 2,3,4 and 4,1,2 occur too? or doesn't it even matter? Commented Oct 12, 2020 at 6:07
  • It doesn't matter as long as it's consistent.
    – SDNX
    Commented Oct 13, 2020 at 1:40

2 Answers 2

2

SDNX could simply make a geoprocess union with the original layer and the resulting one, that would generate the blue polygon and the missing portion.

Just run, Vector menu, geoprocessing tools, Union after Geometry by expressions.

Or even better, create a model, in the model generator with both processes

Solution, Update to 12-10-2020 I work with the same expressions that we defined before, but now I create a multi-polygon wkt.

Wkt is a vectorial format in ascii format, which most software work, it is a standard.

After converting to wkt I have a string left that I can alter with the expressions

A multi-polygon has a structure like this:

MULTIPOLYGON ((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))

Just copy the code and paste it, if required I will explain the expression

geom_from_wkt( 
left(geom_to_wkt(make_polygon(exterior_ring( make_triangle(point_n($geometry,1),point_n($geometry,2),point_n($geometry,3))))),length(geom_to_wkt(make_polygon(exterior_ring( make_triangle(point_n($geometry,1),point_n($geometry,2),point_n($geometry,3))))))-1) 
 +','+ 
right(geom_to_wkt(difference($geometry, make_triangle(point_n($geometry,1),point_n($geometry,2),point_n($geometry,3)))),
  length(geom_to_wkt(difference($geometry, make_triangle(point_n($geometry,1),point_n($geometry,2),point_n($geometry,3)))))-9) ) 
10
  • OK, these are good alternatives. I was aware of the Union option in geoprocessing tools, but wanted to see if I could make this a one-step process. In terms of expressions, it doesn't seem possible to create multiple geometries. This is something I wasn't sure of. If true, then a model would be a better way. For e.g. this doesn't work, unless my syntax is wrong: union(make_triangle(point_n($geometry,1), point_n($geometry,2),point_n( $geometry,3)),(make_triangle(point_n($geometry,3), point_n ($geometry,4),point_n( $geometry,1))))
    – SDNX
    Commented Oct 11, 2020 at 23:52
  • Your updated expression at the bottom of your response makes sense to me, but still produces one half / triangle. I suspect that it may only be possible to create one type of geometry per expression. I might be wrong.
    – SDNX
    Commented Oct 12, 2020 at 0:22
  • Yes, it seems that the expressions pass only one geometry at a time. I think the solution is to convert both parts to multi-polygon, but there is no such expression in QGIS3.4 either. So, the solution would be to create that expression, which takes a collection_geometries and converts it to multi-polygon
    – Luis Perez
    Commented Oct 12, 2020 at 11:48
  • 1
    I found a solution!! I hope you give me a bonus point for that :). the expression can only receive one geometry, it can be multi-polygon. So I convert to wkt and build a multi-polygon with the two geometries.Update the answer with details
    – Luis Perez
    Commented Oct 12, 2020 at 18:26
  • 1
    The multipart to single part geoprocess does not work, it must be a detail in the writing of the wkt, to improve it you should print it. But this process does work, Processing tool box > SAGA > Vector Polygons Tools > Polygons Parts to Separate Polygons. But it takes a little while to process
    – Luis Perez
    Commented Oct 13, 2020 at 11:58
0

Solution Steps (thanks to @Luis Perez):

  1. In Processing -> Geometry by Expression, enter the following expression in geometry generator on quadrangle feature layer:

geom_from_wkt( left(geom_to_wkt(make_polygon(exterior_ring( make_triangle(point_n($geometry,1),point_n($geometry,2),point_n($geometry,3))))),length(geom_to_wkt(make_polygon(exterior_ring( make_triangle(point_n($geometry,1),point_n($geometry,2),point_n($geometry,3))))))-1) +','+ right(geom_to_wkt(difference($geometry, make_triangle(point_n($geometry,1),point_n($geometry,2),point_n($geometry,3)))), length(geom_to_wkt(difference($geometry, make_triangle(point_n($geometry,1),point_n($geometry,2),point_n($geometry,3)))))-9) )

  1. On resulting multipart quadrangles, run Processing -> SAGA -> Vector Polygon Tools -> Polygon parts to separate polygons. Retains original FID's for both halves of each quadrangle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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