I have Python 3 and all GDAL bindings installed on my Windows machine, so that when I run this:
import numpy as np
from sys import argv
from osgeo import gdal, gdalconst
I get no error messages. What I want to achieve now is to create NDVI image from two Landsat 8 images. To implement this, I'm using this nice looking script – https://gist.github.com/celoyd/7443646 . I really like how simple it is, however, when I run it like so:
C:\LC81750202017091LGN00>python ndvi.py LC81750202017091LGN00_B4.TIF LC81750202017091LGN00_B5.TIF output-ndvi.TIF
ERROR 1: Deleting output-ndvi.TIF failed:
Permission denied
ERROR 1: TIFFResetField:output-ndvi.TIF: Could not find tag 273.
Traceback (most recent call last):
File "ndvi.py", line 31, in <module>
ndvi = (n - r)/(n + r)
MemoryError
I tried to debug it and see that the first error message
ERROR 1: Deleting output-ndvi.TIF failed:
comes from these lines of code (19-23):
output = geotiff.Create(
argv[3],
red.RasterXSize, red.RasterYSize,
1,
gdal.GDT_UInt16)
How can I fix it?
Best Answer
I complemented the code with a few lines, to set spatial reference and same geotransform parameters of original rasters, and it works perfectly in a Linux system (python 2.7.x and GDAL 1.11.x). In a Windows 8.x system (python 2.7.x and GDAL 1.11.x), it too worked but it printed these console errors (first one is similar to your error but I got a resulting raster):
with next command:
Apparently, resulting raster hasn't any problem.
Complete used code was:
and next image was resulting raster, obtained in Windows 8 system, loaded in QGIS.