Vertdure commited on
Commit
0dd9e26
1 Parent(s): d10f6f3

Update pages/12_🌲_VertXtractor.py

Browse files
Files changed (1) hide show
  1. pages/12_🌲_VertXtractor.py +24 -3
pages/12_🌲_VertXtractor.py CHANGED
@@ -13,6 +13,7 @@ import numpy as np
13
  # Liste des couches de données Swisstopo
14
  LAYERS = {
15
  "Bâtiments": "ch.swisstopo.vec25-gebaeude",
 
16
  "Réseau hydrographique": "ch.swisstopo.vec25-gewaessernetz",
17
  "Réseau routier": "ch.swisstopo.vec25-strassen",
18
  "Couverture du sol": "ch.swisstopo.vec25-landesbedeckung",
@@ -25,7 +26,6 @@ LAYERS = {
25
  "Noms géographiques": "ch.swisstopo.swissnames3d",
26
  }
27
 
28
- # Fonction pour extraire les données Swisstopo
29
  def extract_swisstopo_data(min_x, min_y, max_x, max_y, layer):
30
  bbox = box(min_x, min_y, max_x, max_y)
31
  api_url = "https://api3.geo.admin.ch/rest/services/api/MapServer/identify"
@@ -50,9 +50,30 @@ def extract_swisstopo_data(min_x, min_y, max_x, max_y, layer):
50
  gdf = gpd.GeoDataFrame.from_features(features, crs="EPSG:2056")
51
  return gdf
52
 
53
- # Fonction pour télécharger l'image SWISSIMAGE (inchangée)
54
  def download_swissimage(min_x, min_y, max_x, max_y):
55
- # ... (le code reste le même)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  # Interface utilisateur Streamlit
58
  st.title("Extracteur de données Swisstopo")
 
13
  # Liste des couches de données Swisstopo
14
  LAYERS = {
15
  "Bâtiments": "ch.swisstopo.vec25-gebaeude",
16
+ "Bâtiments 3D": "ch.swisstopo.swissbuildings3d_2",
17
  "Réseau hydrographique": "ch.swisstopo.vec25-gewaessernetz",
18
  "Réseau routier": "ch.swisstopo.vec25-strassen",
19
  "Couverture du sol": "ch.swisstopo.vec25-landesbedeckung",
 
26
  "Noms géographiques": "ch.swisstopo.swissnames3d",
27
  }
28
 
 
29
  def extract_swisstopo_data(min_x, min_y, max_x, max_y, layer):
30
  bbox = box(min_x, min_y, max_x, max_y)
31
  api_url = "https://api3.geo.admin.ch/rest/services/api/MapServer/identify"
 
50
  gdf = gpd.GeoDataFrame.from_features(features, crs="EPSG:2056")
51
  return gdf
52
 
 
53
  def download_swissimage(min_x, min_y, max_x, max_y):
54
+ api_url = "https://data.geo.admin.ch/api/stac/v0.9/collections/ch.swisstopo.swissimage-dop10/items"
55
+
56
+ params = {
57
+ "bbox": f"{min_x},{min_y},{max_x},{max_y}",
58
+ "datetime": "2022-01-01T00:00:00Z/..",
59
+ "limit": 1
60
+ }
61
+
62
+ response = requests.get(api_url, params=params)
63
+ response.raise_for_status()
64
+
65
+ data = response.json()
66
+ if data['features']:
67
+ asset_url = data['features'][0]['assets']['rgb']['href']
68
+ image_response = requests.get(asset_url)
69
+ image_response.raise_for_status()
70
+
71
+ with zipfile.ZipFile(BytesIO(image_response.content)) as zf:
72
+ image_file = [f for f in zf.namelist() if f.endswith('.tif')][0]
73
+ with zf.open(image_file) as file:
74
+ image = Image.open(file)
75
+ return np.array(image)
76
+ return None
77
 
78
  # Interface utilisateur Streamlit
79
  st.title("Extracteur de données Swisstopo")