Replacing Data and Writing/Updating to the same TIFF file #3006
-
Hello, I have been downloading some DEM data from here: https://www.hydrosheds.org/hydrosheds-core-downloads I have another package I am working with that does not allow nodata values. The nodata from the above files does have a value associated with them, but I am trying to make that value negative. This is what I have currently:
Obviously this is wrong but I don't really know what to do. Essentially I want to read an existing dataset, find all the nodata/32767 values, change them, and then save the updated dataset. I want to keep everything else, same grid and all. I am not sure either if I can take the read in ndarray and save it to the new file anyways. Based on the docs, any kind of saving data needs to be done in write mode to save the new file, but when I write the line for the newdata and put 'w' in the parentheses, I get the below error. Does anyone know a better way or know how to fix this so I can save the new data? Or if this wouldn't work in rasterio, let me know as well. Any help is appreciated, sorry I am very new to rasters and TIFF files in general so thank you in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@anna24valcarcel you're on the right track. If you open a dataset with |
Beta Was this translation helpful? Give feedback.
@anna24valcarcel you're on the right track. If you open a dataset with
mode="r+"
you can update entire bands, smaller windows of bands, and non-structural metadata. Documentation of this use case has been overlooked (by me), but there are a bunch of examples in the test suite. For example https://github.com/rasterio/rasterio/blob/main/tests/test_update.py#L25.