1

I'm using QGIS 3.14.16-Pi and I'm trying to clip a raster layer by a multipolygon layer representing a network of protected areas. My raster has 4 categories of values: -3, -1, 0 and 2.

I've tried using Raster >> Extraction >> Clip raster by mask layer, but the resulting raster has different values from those of my input raster and isn't even displayed on QGIS.

I tried clipping the same raster but with a different polygon file and it worked just fine, so I think the problem might be with the protected areas shapefile. I created that shapefile by dissolving a shapefile of the World's protected areas into a single polygon and then clipping it to my study area.

Does anyone know what might be the problem?

Here is a picture of that shapefile (yellow areas) over my study area (black outline):

enter image description here

Here is a WeTransfer link to download it if necessary: https://we.tl/t-nnAIlhmHkR

1
  • @Babel the other polygons with which I tested (and had positive results) were also multipart.
    – Spectron
    Sep 15 at 17:59
1

I found a way to solve the problem by using some of @Babel's tips.

I went back to the original shapefile and clipped it to my study area. THen I dissolved all polygons by using Dissolve

Then reprojected it into a projected CRS. I made this so that I could create a buffer around the original shapefile (small buffer area, just 100 meters).

Then I used this new shapefile to clip the raster and it worked.

0

Quick solution

You need to repair your polygon layer as it conatins many errors. See below how to do that. I did a "quick and dirty" repair, download the result here: https://drive.switch.ch/index.php/s/4MinvisRoHfmSxc - be aware: many of the tiny polygons were deleted, so make sure this is really what you need. In any case, with this polygon, you can clip a raster:

See the screenshot: I used a raster DEM to clip it with the result from above - the result are the grey areas, representing the clipped raster. The red areas are those polygons that were deleted in my repaired polygon above. If you have time, you could try to fix this red areas as well (see below how): enter image description here

Detailed solution

Running Clip raster by mask layer, I get the following error:

IllegalArgumentException: Invalid number of points in LinearRing found 3 - must be 0 or >= 4 ERROR 1: Cutline polygon is invalid.

So your layer contains invalid polygons (duplicate node, self contact), that's why it does not work. You have a very complex polygon layer, containing holes, slivers and a few just simple, but very tiny polygons etc. So there is a lot of work to clean it up.

To repair the polygons yourself, depending on what you want to achieve, consider using just a few larger polygons and get rid of the other ones.

Getting a valid polygon layer, you can do the following things:

  • Convert the multipart to single parts polygon layer, then create a new attribute calculating the area and delete all those polygons smaller than a certain threshold.

  • Buffer your polygons by a (not too large) amount - due to your data, I guess 1000 meters would be a good start point. After that buffer again with -1000 meters to get back to the original shape, but with some problematic areas eliminated. Be aware: your layer is in CRS EPSG:4326, with distances in degrees. First reproject to a projected CRS before buffering.

  • Run Check Geometries plugin to repair the remaining polygons.

1
  • thank you for the suggestions. I used some of your tips to find a way to solve it without deleting the small polygons, as I need to keep them. I'll post a comment with my solution
    – Spectron
    Sep 15 at 21:17

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.