3

I have a layer containing MultiPolygons. These MultiPolygons do overlap each other and do have a not unique attribute time containing integers. The number of polygons per layer vary as well as the range of time attribute values. So splitting the layer by time attribute and running difference iterative is not a good solution.

You can download an example file here: https://drive.google.com/file/d/1bqoypolx0NXrfiEy3xb_4YvaignSdEgr/view?usp=sharing

What I need are polygons, where each (imaginary) possible point is covered by one feature/polygon only. Preferably with the minium time attribute assigned, but this can be done in an additional step later as well by using join attributes by location, so not really part of the question.

Right now I am looking for a way to do this with native QGIS processing tools. Later I will implement this workflow in a PlugIn using PyQGIS.

SAGA's polygon self intersection would be a good start, if then beeing able to delete the duplicate geometries. Unfortunately SAGA tools are not officially supported and especially this tool tends to return invalid geometries, which makes it impossible to properly delete duplicate geometries afterwards.

Here is a sketch of what I am trying:

enter image description here

6
  • 1
    @BERA that would be almost what I am looking for. Unfortunately that query does not work for GeoPackages (respectively memory layers) neither via DB Manger nor Execute SQL. But instead of keeping the highest priority, the overlap should become an extra part having the highest priority attribute.
    – MrXsquared
    Dec 29, 2021 at 17:10
  • 3
    I would have proposed to try Union Geoprocessing tool. However, the tool fails: Could not add feature with geometry type MultiLineString to layer of type MultiPolygon. You have some problematic overlaps like here that probably result in geometry errors: i.stack.imgur.com/s62tF.png - maybe try to clean the geometries first?
    – Babel
    Dec 29, 2021 at 17:36
  • @Babel hm, true that. Kind of a weird error I can not fix or even find using "Fix geometries", "Check Validity", "Zero Buffer" or "0.001 Buffer". Neither I can find any "LineStrings" by using area calculation (I know its degrees but a line should always return 0?). Unfortunately fixing this by hand is not an option.
    – MrXsquared
    Dec 29, 2021 at 17:52
  • So indeed the geometries seem to make trouble. Would be interesting if the solution I proposed would work as a model, as proposed by @BERA
    – Babel
    Dec 29, 2021 at 18:00
  • 1
    If you can a v.clean and then the delete duplicate geometries tool you might get the flat result requested, but it would have more polys than your graphical example.
    – johns
    Dec 29, 2021 at 18:07

1 Answer 1

3

What worked for me with a sample dataset similar to your sketch - but not with the data you provided. They contain some problematic geometries that you should fix (for any solution, I guess).

My dataset (compare result below): enter image description here

  1. Run Menu Vector / Geoprocessing / Union

  2. Identify which of the overlapping parts you want to keep. In my example: the one with the highest value for the field value. Create a boolean field named keep with this expression:

     if (
         overlay_equals(@layer),
         if (
             value >= overlay_equals( 
                 @layer, 
                 value
             )[0],
             true,
             false
         ),
         true
     )
    
  3. Delete all features with keep = false

  4. Aggregate features based on value, run Multipart to singleparts.

This is what I got (including a sliver - delete all polygons with area < n to get rid of that):

enter image description here

4
  • What does the [0] do? Which aggregate function are you using?
    – BERA
    Dec 30, 2021 at 18:33
  • 1
    Overlay functions generate an array and [0] gets the first element/index 0 of the array
    – Babel
    Dec 30, 2021 at 19:57
  • 1
    The function here gets the value of the value attribute field of the first of the polygons that overlap exactly (equals) with the current feature.
    – Babel
    Dec 30, 2021 at 20:04
  • 1
    @BERA you can use Aggregate from processing toolbox, choose minimum on the attribute and $geometry as group by instead of the expression. Increases backward compatibilty to older versions and works for the basic question (the sketch), but not for the example polygon. The point where I realized I had a wrong workflow and therefore a slightly wrong question.
    – MrXsquared
    Dec 30, 2021 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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