I have two files, GeoTIFFs (.tif) in this case which need to be cropped to each other's minimum overlap, and have matching spatial resolutions. I also want to round their Pixel Size to a whole number (50m in my case). I strongly prefer using gdal or a similiar alternative like rasterio.


Upper left (240650.486, 4234958.562) Pixel Size (50.000101..., -50.000101...)


Lower Left (242715.000, 4234848.000) Pixel Size (50.00023..., -50.00023...)

Say I found the min overlapping extent in python for instance:

left_bounds = max(min(xcoords1), min(xcoords2))   
right_bounds = min(max(xcoords1), max(xcoords2))   
#same for lower_bounds and upper_bounds

I still couldn't simply gdalwarp -te left_bounds lower_bounds right_bounds top_bounds because my resolution still needs rounding.

Essentially I would like to do all this through gdal commands, but am curious the most parsimonious string of gdal commands that could clip to bounds, ensure alignment of two tifs, and round resolution to 50m

AND! If possible, find the lower_bounds, upper_bounds, etc. without resorting to an external scripts or parsing gdalinfo outputs in the command line.

  • 1
    This isn't a GIS question it's a bash text parsing question and probably better asked on StackOverflow, SuperUser or Unix/Linux. That said, you'll need to provide an attempt at it and the gdalinfo output as code formatted text not screenshots so potential answerers can reproduce.
    – user2856
    Aug 5 '19 at 21:35
  • Use gdalbuildvrt mosaic.vrt *.tif and then gdalinfo mosaic.vrt.
    – user30184
    Aug 6 '19 at 9:09
  • I think it's half GIS half bash text parsing. I am detailing my choppy workflow on StackExchange because this is where most of my troubleshooting has led me. I will reframe the question and focus JUST on the gdal steps that would get me there. Thanks for the input @user2856, I'll attempt to edit this up and repost in the hopes that it now qualifies as 'on topic'. Thanks! Aug 6 '19 at 15:11

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.