1

I'm trying to clip an image in gdal and when I run this code:

gdalwarp -cutline path/to/polygon.shp \
-crop_to_cutline -dstnodata "-9999.0" \
in_raster.tif \
out_raster.tif

it runs ok and output is working ok too. However, when running this code:

import ogr
import subprocess

inraster = 'in_raster.tif'
inshape = 'polygon.shp'
outraster = 'out_raster.tif'

subprocess.call(['gdalwarp', '-cutline', inshape, '-crop_to_cutline', '-dstnodata -9999.0', inraster, outraster])

it doesn't create any output. I reckon there is something wrong in -dstnodata <nodata_value>.

1 Answer 1

2

You should split -dstnodata and -9999.0 into two parameters, so that you have

subprocess.call(['gdalwarp', '-cutline', inshape, '-crop_to_cutline', '-dstnodata', '-9999.0', inraster, outraster])

See also this post.

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.