6

I have stumbled on an error and I would like to have an external point of view to maybe help me figure it out.

When I

  1. clip layerA as input with layerB as the overlay, and then
  2. make the difference of layerC as input with the Clipped layer as the overlay layer,

I get this error:

Could not add feature with geometry type MultiLineString to layer of type MultiPolygon

Strangely, all of the layers are multipolygons.

I then tried to do mutlipart to singlepart + remove duplicate vertices + fix geometries, but the issue still arise. I even tried to do a tiny negative buffer to make very small objects disapear.

Any other idea to circumvent this situation?

Here is a link to the gpkg containing the layers : https://drive.google.com/drive/folders/1TpPflqDJGYriDaYcjr49F04qpk9uXsPw?usp=share_link

I use Windows11 and QGIS 3.28.6

9
  • I'd load the clipped data into a geopandas dataframe, filter out the Multistring geom types and then save to another shapefile. That will let you zoom to the feature that is causing the error.
    – Binx
    Commented May 9, 2023 at 14:35
  • 2
    I've run into problems sometimes where you linestrings are generated due to corner shared geometries.
    – Binx
    Commented May 9, 2023 at 14:37
  • So I understand that the clip creates some undesired artifacts. The thing is, this step is part of a big model, is there a way to filter lines with the basic processes ? (I'm using the model and not a python script because it will be shared with a client)
    – Elyum
    Commented May 9, 2023 at 14:44
  • 1
    Please provide more details: which is input layer, which is overlay layer? In step 2, you use the clipped layer for difference tool? Again: which layer is input and overlay? Simply following your steps, I get no error.
    – Babel
    Commented May 9, 2023 at 14:44
  • 1
    I've edited my question now
    – Elyum
    Commented May 9, 2023 at 14:48

3 Answers 3

4

Buffer layer C with a very small value, then it works. I used 0.01 m as buffer distance. Buffer again with the negative of it (-0.01) to get back the initial shape, but without the gaps contained in layer C.

6
  • On my side, the issue is not on layerC, but on the result of the clip between layerA and layerB. I tried the buffer on the result of the clip without success. I also realise I should have shared the said clipped layer to avoid confusion... live and learn...
    – Elyum
    Commented May 9, 2023 at 15:03
  • My bad, I did exactly what you said, and it works
    – Elyum
    Commented May 9, 2023 at 15:05
  • So buffering solved your problem or not? I'm a bit confused. If you run geometry checker on layer C, see see that it has many sliver polygons.
    – Babel
    Commented May 9, 2023 at 15:07
  • Yes and no. See next answer plz.
    – Elyum
    Commented May 9, 2023 at 15:18
  • 1
    @Babel it seems that the OP had some invalid geometries (check my answer), that needed to be fixed. Then your solution worked.
    – Binx
    Commented May 9, 2023 at 18:27
4

Apologies for cluttering the answer section, but this is geared towards why the OP might be running into some problems and may lend a hand towards others troubleshoot similar problems.

The OP has some odd geometry types within their dataset. For example LayerC id==27 is Class NoneType. You can find these underlying issues by using geopandas within a python script.

# python 3.10.9
import os
os.environ['USE_PYGEOS'] = '0'
import geopandas

# Load the file
file = geopandas.read_file("C:/Users/zleslie/Downloads/layerC.shp")

# Iterate through geometries and track the id with enumerate
for i, geom in enumerate(file.geometry):
    try:
        geom.geom_type
    except:
        print(type(geom))
        print(i)
2

I suggest you run select by expression on your faulty layer (in this case layer C), using $area<1, thus selection all sliver geometries. Then delete those.

This can be implemented in a model, probably in a script, too, but the latter is beyond my expertise.

3
  • Good idea, I've used that before, but in this case, it doesn't help... Also, it is not the layrC that is faulty, it is the result of the clip
    – Elyum
    Commented May 9, 2023 at 14:56
  • For me it worked with your data @Elyum
    – Erik
    Commented May 9, 2023 at 14:57
  • sorry, I edited while you were answering
    – Elyum
    Commented May 9, 2023 at 14:58

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.