Can somebody help me with gdalwarp issue? I am having an input raster and would like to clip it with polygons. After running the below code, while overlaying output raster on input raster, I see there is a slight shift in pixels of output raster.
Can somebody help me how to match the output and input raster so that the pixel borders matches exactly?
import ogr
import subprocess
inraster = 'C:/Users/claudio/workspace/test/inraster.tif'
print(inraster)
inshape = 'C:/Users/claudio/workspace/test/country.shp'
ds = ogr.Open(inshape)
lyr = ds.GetLayer(0)
lyr.ResetReading()
ft = lyr.GetNextFeature()
while ft:
country_name = ft.GetFieldAsString('admin')
outraster = inraster.replace('.tif', '_%s.tif' % country_name.replace(' ', '_'))
subprocess.call(['gdalwarp', inraster, outraster, '-cutline', inshape, '-crop_to_cutline', '-cwhere', "'admin'='%s'" % country_name])
ft = lyr.GetNextFeature()
ds = None
No comments:
Post a Comment