3

I am attempting to clip a raster to a shapefile boundary (country boundary, 1 polygon) using the 'clip raster by mask' tool in QGIS v3.8.2. Both layers are in WGS84, so projection mismatch shouldn't be the issue.

I'm getting the following error message that I haven't been able to sort out:

2019-09-09T16:23:13 INFO GDAL execution console output
Creating output file that is 435P x 193L.
Processing R:\exampledata\wc20_25m_tmin_01.tif [1/1] : 0ERROR 1: IllegalArgumentException: point array must contain 0 or >1 elements

ERROR 1: Cutline polygon is invalid.

Using internal nodata values (e.g. -3.4e+38) for image R:\exampledata\wc20_25m_tmin_01.tif.

Copying nodata values from source R:\exampledata\wc20_25m_tmin_01.tif to destination C:/Temp/processing_7b281fab84954f6ca3dd66d12d696f5c/0b2ef639021f42f0b744260b98b85235/OUTPUT.tif.

To correct this I've tried:

1) checking the geometry of the polygon file, no errors were found. Geometry is valid

2) correcting the geometry anyway. No change.

3) creating a zero distance buffer, didn't fix it.

4) tried a different vector shapefile, same issue.

5) tried a different raster with both shapefiles, same issue.

6) tried simplifying the geometry, no change to the issue.

7) discovered the single feature is in fact a 'multi polygon'. tried deleteing all the small features and saving the main area as a single polygon. This did not correct the issue.

8) Using the SAGA 'clip raster with polygon' tool. This produces a usable output with a warning:

Loading resulting layers The following layers were not correctly generated.

  • C:/Users/wkessler/AppData/Local/Temp/processing_1b387f0cf3564641840068eedfe5ec05/cf6aaedbd8e44f09b1eeb194d5d23a36/OUTPUT.sdat
You can check the 'Log Messages Panel' in QGIS main window to find more information about the execution of the algorithm.

Now, I have tried the same operation in both QGIS 2.18 (Clipper tool) and ArcGIS 10.6 (Clip) and have no issues. I have also managed to get the SAGA 'clip raster with polygon' function to work on this data in QGIS 3.8.2, although it does give a warning that the result was generated incorrectly. Can anyone tell me what's going on?

EDIT: Since posting this question I have also sent the data to a friend who tried the operations using QGIS 3.8.2, 3.4, and 2.18. They found the same thing; that it works in 2.18 but not in 3.4 or 3.8.2.

EDIT 2: tried additional solutions suggested by comments. None have solved the issue.

  • Have you checked if both shapefile and raster file have the same projection? – ahmadhanb Sep 10 at 6:05
  • @ahmadhanb , yes, both files have the same projection. – W. Kessler Sep 10 at 15:02
  • I've been fighting the same problem with a fairly complex shoreline of Alaska. I also found a similar question here: gis.stackexchange.com/questions/333194/…. I did not try the simplification @d_araujo used, but I did delete all islands and was able to clip to the single mainland polygon. Perhaps a simplification process would help solve your error since you already have a single polygon? – snow-raven Sep 13 at 20:23
  • @snow-raven Thanks for the suggestion. I realized that while my shapefile only contains one feature, it is in fact a 'multipolygon' i.e. there are many small islands. I tried converting the shapefile to single parts and save off the mainland area, effectively removing all the small islands. This did not fix the issue either. – W. Kessler Sep 27 at 20:58
  • @snow-raven I also tried the simplification suggested in the question you linked to. That did not correct the issue. – W. Kessler Sep 27 at 20:59

Your Answer

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

Browse other questions tagged or ask your own question.