I have a large number of GeoTiffs that I need to clip by a polygon stored in a shapefile and then save them as a new raster.

I use a gdalwarp command which I call from a Python script. These GTiffs (sources) have different spatial reference systems but the clipped GTiffs (targets) are all stored with the same SRS. This is the command I am using:

cmd = 'gdalwarp -tr 10.0 10.0 -r bilinear -s_srs {} -t_srs {} '\
              '-of vrt -cutline {} -overwrite {} '\
              '/vsistdout/ | gdal_translate -of GTiff -co compress=lzw /vsistdin/ {}'.format(s_srs, t_srs, cutline, f_in, f_out)

The problem I have is that since source GTiffs' SRS differs, I have to transform the shapefile with the clipping polygon every time into the SRS of the source.

But, since during the gdalwarp execution the GTiffs are transformed into the target_SRS anyway, I was wondering if I could somehow first execute the "source_SRS to target_SRS" transformation and then execute the clipping. If that was possible, I could just set the SRS of the shapefile with the clipping feature to the target_SRS and would avoid having to transform it with every GTiff.

Maybe there is something obvious that I am missing.

Feel free to edit the title of the question if you can think of something better.

  • would it be possible to retroject everything to a common prediction to begin with? Maybe WGS84? – Nathan Thomas Sep 6 '19 at 20:26

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.