Commit 479e602a authored by Roelofsen, Hans's avatar Roelofsen, Hans
Browse files

script for combinatie geslotenheidskaarten

parent 70ddf022
"""
Short script to combine opgaande elementen kaarten from 2018 and 2019 into a single map showing all possible
combinations.
First reclass Open (1), close (2) cells to powers of 2:
2018 Open 0
2018 Close 1
2019 Open 2
2019 Close 4
Then make all combinations:
2019O 2019C
2018O 2 4
2018C 3 5
Opgaande elementenkaarten by Henk Meeuwsen.
Zie W:\PROJECTS\Landschapsmonitor\Documentatie\LM werkwijze openheid 2020.docx.
Code by Hans Roelofsen, WEnR, 5 August 2020
"""
import os
import numpy as np
import rasterio as rio
from sample.utils import lm as lm
# Read source rasters
og18_src = r'c:\apps\temp_geodata\gesloten_2018_20200629time114900.flt'
og19_src = r'c:\apps\temp_geodata\gesloten_2019_20200702time193947.flt'
og18 = rio.open(og18_src)
og19 = rio.open(og19_src)
# Apply reclass dictionaries
og18_rc_dict = {-9999: 0, 1: 0, 2: 1}
og19_rc_dict = {-9999: 0, 1: 2, 2: 4}
og18_reclass = lm.vec_translate(og18.read(1), og18_rc_dict)
og19_reclass = lm.vec_translate(og19.read(1), og19_rc_dict)
# Add two arrays together
og1819 = np.add(og18_reclass, og19_reclass)
print(np.unique(og1819))
# write to file
basename = 'lm_gesloten_18-19_combi'
prof = og18.profile
prof.update(dtype=rio.uint8, driver='gtiff')
with rio.open(os.path.join(r'c:/apps/temp_geodata', '{}.tif'.format(basename)), 'w', **prof) as dst:
dst.write(og1819.astype(np.uint8), 1)
"""
Functions and classes
"""
import numpy as np
def vec_translate(a, my_dict):
"""
Function to apply my_dict to each element in in array a. See:
https://stackoverflow.com/questions/16992713/translate-every-element-in-numpy-array-according-to-key
Note that key errors are not caught!
"""
return np.vectorize(my_dict.__getitem__)(a)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment