I know that this question might be confusing, so I'll try my best to explain it.

I have a shapefile that I will be using to clip my raster:

This is my shapefile (whole island of Palawan, Philippines): enter image description here

And this is my input raster to be clipped/extracted: enter image description here

Now using gdalwarp, my result looks like this: enter image description here

My question is, can I produce an output where its extent is based on the input raster only (excluding the upper part covered by shapefile) and does not include the whole shapefile?

This is the ouput raster extent that I want to have (as covered by green bounding box). enter image description here

  • 2
    I would have a try by 1) making a copy of the original image as "output.tif", and then by using that as target for gdalwarp. From gdal.org/gdalwarp.html Mosaicing into an existing output file is supported if the output file already exists. The spatial extent of the existing file will not be modified to accommodate new data, so you may have to remove it in that case, or use the -overwrite option.
    – user30184
    Apr 25, 2019 at 6:30

1 Answer 1


Use the -te flag of gdal_warp to set the bounds of the output to match those of the original raster.

From the documentation at https://www.gdal.org/gdalwarp.html

-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)

You can find the extent of the original raster using gdalinfo It gives you all four vertices of the bounding box but xmin is just the x (or longitude) value of the Upper Left and Upper Right values, ymin the is the y (latitude) from the Lower Left values and Upper Right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.