2

I want to clip a large raster file (1.8 GB) by a shapefile with more than 100 smaller polygons. The polygons have the size of under 1% of the TIFF image.

I'll tried to use the clip function of QGIS, but when I start it, my whole system freezes in one second.

I tried it with only one smaller polygon and it worked. My workstation should manage the workload. I have 98 GB of RAM, a Xeon six core CPU and even a Titan GPU (if QGIS can utilize it).

In the best case I want to loop over every polygon and save every polygon as one file by it id name.

  • 1
    What do you mean here by "clip"? For each polygon are you expecting a raster that covers just that polygon? – Spacedman Jul 20 '18 at 11:36
  • Sometimes it's not about what your workstation can fit.. but what the drivers and software can handle as well.. shapefiles are also very fragile and have a space limit around 2gb. You maybe could try batch 5x 20 polygons instead of all in one run? – DirkB. Jul 20 '18 at 13:24
  • @ Spacedman Yes I mean exactly what you meant. @Dirk Brunken how can I use batches? – Lau Jul 20 '18 at 14:26
2

To batch a process like clipping a raster with a polygon you can use right-click on that clip-tool from your toolbox and then add your data.

batch processing easy way

1

QGISs clip by extent tool uses the GDAL library warp tool. You could try running this from the command line instead which is much more stable for large/complex datasets, something like this should do it:

gdalwarp -of GTiff -cutline DataSourceOfMask.shp -cl FileNameOfMask  -crop_to_cutline NameOfInputRaster.asc  NameOfOutputClippedRaster.tiff

(Adapted from Clipping raster with vector layer using GDAL)

  • When I use gdalwarp, can I also clip by each polygon of the shape file or can I split the shape file by ID before clipping? – Lau Jul 20 '18 at 14:27
  • 1
    Lau - I've just read your clarification in the comments above. To what you want you need to split your polygon shapefile up and then run the above command for each one. There are many ways to automate that (see for example: gis.stackexchange.com/questions/48423/…). You may need to start a new question or edit your existing one. – Ed Rollason Jul 20 '18 at 16:38
  • Yeah sorry I don't stated my question clear. May I say how I solve my Problem. I used under Vector -> Data Managemetn tool -> Split vector layer. Then I have every polygon of the shape file seperate in one folder. After that I wrote a python script that loops over this folder and executes gdalwarp for every .shp file. I also tried the python binding of gdal, but it is not well documented and does not throw any error. – Lau Jul 22 '18 at 8:02

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.