0

Has anyone been able to successfully call gdal_pansharpen.py from your own Python script?

I have successfully used rasterio to combine my R, G, and B bands, but would like to perform a pansharpen on the final image using the gdal_pansharpen command.

How did you manage to make the call?

4

Ensure gdal_pansharpen.py is in your python path. You may need to add it by setting the PYTHONPATH env var before running your script, or within your script, i.e. sys.path.append('gdal_pansharpen/directory').

from gdal_pansharpen import gdal_pansharpen 
gdal_pansharpen(['-b', '1', '-b', '2', '-b', '3', 'input_pan.tif', 'input_multi.tif', 'output_pansharpened.tif'])
  • Thanks, I think that gets me pretty close. How would I specify the arguments with the parens to equate to this: gdal_pansharpen.py LC80420362016085LGN00_B8.TIF LC80420362016085LGN00_B4.TIF LC80420362016085LGN00_B3.TIF LC80420362016085LGN00_B2.TIF carrizo-20160325-oli-pan.tif -r bilinear -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB assuming I have the images stored as local variables b8, b4, b3, b2, and tif? Would it be equal to this? gdal_pansharpen([b8, b4, b3, b2, tif, '-r', 'bilinear', '-co', 'COMPRESS=DEFLATE', '-co', 'PHOTOMETRIC=RGB']) – Nathan Raley Mar 11 '20 at 15:45
  • Yea, turns out I also needed to specify the -nodata flag as well, otherwise the image was messed up due to the nodata messing with the overall statistics of the image. Unfortunately, the multi band format pansharpen call has a bug where you can't specify nodata, but the vrt route then calling it works just fine. Thanks! – Nathan Raley Mar 19 '20 at 15:47

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.