Saturday, 14 July 2018

python - gdalwarp causing shift in pixels


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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...