WALOUS OCS (Occupation du sol) ou UTS (Utilisation du sol) comme WolfArray

[ ]:
# import _add_path # for debugging purposes only - must be removed in production

import numpy as np
from pathlib import Path
import matplotlib.pyplot as plt

from wolfhece import is_enough
if not is_enough('2.2.43'):
    raise ImportError("This code requires wolfhece version 2.2.43 or higher. -- try pip install wolfhece --upgrade")

from wolfhece.wolf_array import WolfArray
from wolfhece.pydownloader import toys_dataset
from wolfhece.pywalous import get_array_WALOUS_OCS, get_array_WALOUS_OCS_2020_10m, get_array_WALOUS_OCS_2023_10m, get_array_WALOUS_OCS_2020_4m, get_array_WALOUS_OCS_2023_4m, update_palette_walous_ocs
from wolfhece.pywalous import update_palette_walous_uts, get_array_WALOUS_UTS

Chargement d’une matrice située en Région Wallonne

[2]:
mnt = WolfArray(toys_dataset("Array_Theux_Pepinster", 'mnt.bin'))
mnt.nullvalue = mnt.array[0,0]
print(mnt)
Shape  : 480 x 1160
Resolution  : 5.0 x 5.0
Spatial extent :
   - Origin : (251000.0 ; 135500.0)
   - End : (253400.0 ; 141300.0)
   - Width x Height : 2400.0 x 5800.0
   - Translation : (0.0 ; 0.0)
Null value : 99999.0


[3]:
mnt.plot_matplotlib()
[3]:
(<Figure size 640x480 with 1 Axes>, <Axes: >)
../_images/tutorials_wolfarray_walous_4_1.png

Récupération de la donnée OCS 2023 à la résolution de la matrice

Dans cette application, on utilise le fichier OCS 2023 à une résolution de 10 m, disponible dans les exemples de données de Wolfhece.

La matrice de base étant à 5 m, un rééchantillonnage est nécessaire et est appliqué automatiquement via l’opérateur ‘rebin’ de la classe WolfArray.

Il est également possible d’appliquer la palette de couleurs spécifique aux données OCS via update_palette_walous_ocs en lui fournissant la palette de la matrice.

Remarque : Le message d’erreur “The datatype of the raster is not supported – 14” est normal car le type de données du GeoTiff est un complexe qui n’est pas supporté complètement par les WolfArray. Cependant, la lecture des données fonctionne correctement via GDAL.

[4]:
ocs = get_array_WALOUS_OCS_2023_10m(mnt.dx, mnt.get_bounds())
update_palette_walous_ocs(ocs.mypal)
ocs.plot_matplotlib()
ERROR:root:The datatype of the raster is not supported -- 14
ERROR:root:Please convert the raster to a supported datatype - or upgrade the code to support this datatype
ERROR:root:See : read_txt_header and import_geotif in wolf_array.py
ERROR:root:The datatype of the raster is not supported -- 14
ERROR:root:Please convert the raster to a supported datatype - or upgrade the code to support this datatype
ERROR:root:See : read_txt_header and import_geotif in wolf_array.py
[4]:
(<Figure size 640x480 with 1 Axes>, <Axes: >)
../_images/tutorials_wolfarray_walous_6_2.png

Même résolution et emprise spatiale que la matrice de base

Les 2 matrices ont la même résolution et la même emprise spatiale.

[5]:
assert ocs.is_like(mnt), "The two arrays should be like each other"

Autres années et résolutions

Il est possible de faire la même opération avec les données de 2020 mais également en utilisant une matrice préparée à la résolution de 4.0 m x 4.0 m.

Remarque : La donnée OCS de base (disponible sur Walonmap) est à 1.0 m x 1.0 m mais est relativement lourde (plus de 1.1 Go).

[6]:
ocs = get_array_WALOUS_OCS_2020_10m(mnt.dx, mnt.get_bounds())
update_palette_walous_ocs(ocs.mypal)
ocs.plot_matplotlib()
WARNING:root:***************************************************
WARNING:root: Conversion of uint8 to int8
WARNING:root: If you save this file, it will be converted to int8
WARNING:root:***************************************************
WARNING:root:Value too high for int8 conversion
WARNING:root:Value set to 0
WARNING:root:Value too high for int8 conversion
WARNING:root:Value set to 0
[6]:
(<Figure size 640x480 with 1 Axes>, <Axes: >)
../_images/tutorials_wolfarray_walous_10_2.png

Donnée UTS

La donnée UTS (Utilisation du sol) est également disponible via la fonctoin get_array_WALOUS_UTS. Il est possible de traiter le 1er ou le second niveau de classification (voir ‘UTS_MAJ_NIV1’ ou ‘UTS_MAJ_NIV2’).

Cette donnée est au format vectoriel (gpkg, gdb, shp, …). Elle n’est pas fournie dans les exemples de données de Wolfhece mais peut être téléchargée via Walonmap (https://walonmap.be/). Pour l’ensemble de la Wallonie, le fichier est relativement lourd (3.0 Go en gpkg).

ATTENTION : La donnée disponible via Walonmap est dans le référentiel Lambert 2008 (EPSG3812). Il faudra le convertir si vous travaillez en Lambert 72 (EPSG:31370).

Exemples de conversion via GDAL :

  • ogr2ogr -f “ESRI Shapefile” -t_srs EPSG:31370 -skipfailures output.shp input.gpkg

  • ogr2ogr -f “gpkg” -t_srs EPSG:31370 -skipfailures output.gpkg input.gpkg

[ ]:
data_dir = Path(r'E:\WAL_UTS__2018_GEOPACKAGE_31370') # For example only. Replace with your own path.
uts = get_array_WALOUS_UTS(data_dir / 'WALOUS_UTS_2018_31370.gpkg',
                           fnout= data_dir / 'Theux.tif',
                           spatial_res= mnt.dx,
                           bounds= mnt.get_bounds(),
                           which='UTS_MAJ_NIV1') # 'UTS_MAJ_NIV1' or 'UTS_MAJ_NIV2'

La palette de couleur n’est pas identique à la donnée OCS.

Il est possible de la définir via update_palette_walous_uts.

[4]:
update_palette_walous_uts('UTS_MAJ_NIV1', uts.mypal)
uts.plot_matplotlib()
[4]:
(<Figure size 640x480 with 1 Axes>, <Axes: >)
../_images/tutorials_wolfarray_walous_14_1.png