My code that has been working flawlessly (as far as I can tell) now, after some Python and Spyder updates produces error message:
CPLE_AppDefinedError: vaesto1960.tif: MissingRequired:TIFF directory is missing required "StripOffsets" field
when trying to write a new geotiff file. The context is as follows:
import rasterio
# first read raster data from a netcdf file:
with rasterio.open('data/total_pop_05dgr.nc') as pop:
vaesto = pop.read()
profile = pop.profile
pop.close()
vaesto1960 = vaesto[4]
# want to write one of the rasters as gtiff, so prepare the profile:
profile.update(nodata = 0,
driver = 'GTiff',
tiled = False,
height = vaesto1960.shape[0],
width = vaesto1960.shape[1],
count = 1,
)
# Open a new tif file for writing, and write (also tried writing one band with write_band):
with rasterio.open("vaesto1960.tif", 'w', **profile) as out:
out.write(vaesto1960,1)
out.close
The full traceback is here:
Traceback (most recent call last):
File "C:\Users\jalavam1\git_local\YYT-C2005-2021\untitled0.py", line 25, in with rasterio.open("vaesto1960.tif", 'w', **profile) as out:
File "C:\Users\jalavam1.conda\envs\Mika\lib\site-packages\rasterio\env.py", line 435, in wrapper return f(*args, **kwds)
File "C:\Users\jalavam1.conda\envs\Mika\lib\site-packages\rasterio_init_.py", line 230, in open s = writer(path, mode, driver=driver,
File "rasterio_io.pyx", line 1122, in rasterio._io.DatasetWriterBase.init
File "rasterio_io.pyx", line 70, in rasterio._io._delete_dataset_if_exists
File "rasterio_shim.pyx", line 78, in rasterio._shim.open_dataset
File "rasterio_err.pyx", line 215, in rasterio._err.exc_wrap_pointer
CPLE_AppDefinedError: vaesto1960.tif: MissingRequired:TIFF directory is missing required "StripOffsets" field
Setting the StripOffsets (or any other tags for that matter) hasn't been advised in the rasterio documentation. The code should be pretty much a copy of the example there.
Thanks, Mika