I am looking for the easiest way to programmatically clip a raster to a rectangular extent for testing purposes. I have GDAL and Python installed on a virtual machine and would like to run the code from Jupyter (python/command line) or command line directly. I do not have a polygon with the extent yet. I am not looking for answers that involve QGIS/ ArcGIS or some other GUI.

I found this resource but I was hoping for something more succinct like:

some-command inputraster.tif outputraster.tif -extent [lower left corner, upper right corner]


  1. Create polygon
  2. Clip using polygon

I am pretty sure there must be some gdal command out there.


I think you can do what you want using gdalwarp and the -te option.

-te xmin ymin xmax ymax:

set georeferenced extents of output file to be created (in target SRS by default, or in the SRS specified with -te_srs)

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.