Jul-26-2021, 09:04 AM
Hi
I have a tiff with lakes, which I converted into a 2D array. I would like to keep the outline of the lakes in a 2D array.
I have tried:
If you know of a completely different way how to keep the outline of the lakes (maybe with rasterio), I would also be thankful. I hope I made clear what I mean with inner values of the lakes. Important: A lake can appear anywhere in the array not just in a corner
Tim
I have a tiff with lakes, which I converted into a 2D array. I would like to keep the outline of the lakes in a 2D array.
import rasterio
import numpy as np
with rasterio.open('myfile.tif') as dtm:
array = dtm.read(1)
array[array>0] = 1
array = array.astype(float)
array[array==0] = np.nanMy array looks like this now, a lake can be seen in the upper right corner: [[ nan nan nan ... 2888.001 [b]2877.458 2867.5798[/b]]
[ nan nan nan ... 2890.188 [b] 2879.2876 2869.0415][/b]
[ nan nan nan ... 2892.2622 2880.9907 2870.4985]
...
[ nan nan nan ... nan nan nan]
[ nan nan nan ... nan nan nan]
[ nan nan nan ... nan nan nan]]I wish to keep the outline of the lakes, thus I have to set all values to nan, which are NOT located next to a nan (marked in bold).I have tried:
array[1:-1, 1:-1] = np.nanHowever, this converts ALL inner values of the entire array to nan, not just the inner values of the lakes.
If you know of a completely different way how to keep the outline of the lakes (maybe with rasterio), I would also be thankful. I hope I made clear what I mean with inner values of the lakes. Important: A lake can appear anywhere in the array not just in a corner
Tim
