Vertdure commited on
Commit
968c2ae
‱
1 Parent(s): 1f10f5c

Update pages/12_đŸŒČ_VertXtractor.py

Browse files
Files changed (1) hide show
  1. pages/12_đŸŒČ_VertXtractor.py +46 -47
pages/12_đŸŒČ_VertXtractor.py CHANGED
@@ -9,22 +9,19 @@ import json
9
 
10
  st.set_page_config(layout="wide", page_title="Extracteur de donnĂ©es gĂ©ospatiales")
11
 
12
- SWISSTOPO_LAYERS = {
13
- "SWISSIMAGE 10 cm": {"id": "ch.swisstopo.swissimage-dop10", "source": "swisstopo", "type": "image"},
14
- "Carte nationale 1:25'000": {"id": "ch.swisstopo.pixelkarte-farbe-pk25.noscale", "source": "swisstopo", "type": "image"},
15
- "MNT": {"id": "ch.swisstopo.swissalti3d", "source": "swisstopo", "type": "raster"},
16
- "Carte géologique": {"id": "ch.swisstopo.geologie-geologische_karte", "source": "swisstopo", "type": "image"},
17
- "Limites administratives": {"id": "ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill", "source": "swisstopo", "type": "vector"},
18
- "RĂ©seau hydrographique": {"id": "ch.bafu.vec25-gewaessernetz", "source": "swisstopo", "type": "vector"},
19
- "swissBUILDINGS3D 3.0 Beta": {"id": "ch.swisstopo.swissbuildings3d_3_0", "source": "swisstopo", "type": "3d"},
20
- }
21
-
22
- ESRI_LAYERS = {
23
- "World Imagery": {"id": "World_Imagery", "source": "esri", "type": "image"},
24
- "World Elevation": {"id": "Elevation/World_Elevation", "source": "esri", "type": "raster"},
25
- "World Topographic": {"id": "World_Topo_Map", "source": "esri", "type": "image"},
26
- "World Street Map": {"id": "World_Street_Map", "source": "esri", "type": "image"},
27
- "World Terrain": {"id": "World_Terrain_Base", "source": "esri", "type": "image"},
28
  }
29
 
30
  def draw_box_on_map():
@@ -66,47 +63,23 @@ def get_download_url(bbox, layer_info):
66
  def main():
67
  st.title("Extracteur de donnĂ©es Swisstopo et ESRI")
68
 
69
- col1, col2 = st.columns([1, 3])
70
 
71
  with col1:
72
  st.subheader("SĂ©lection des couches")
73
- source = st.radio("Source des données", ["Swisstopo", "ESRI"])
74
-
75
- layers = SWISSTOPO_LAYERS if source == "Swisstopo" else ESRI_LAYERS
76
 
77
- selected_layers = st.multiselect("Couches Ă  extraire", list(layers.keys()))
78
-
79
- st.markdown("---")
80
- st.markdown("## À propos\nExtracteur de donnĂ©es gĂ©ospatiales Swisstopo et ESRI.\nDĂ©veloppĂ© par Vertdure")
81
-
82
- with col2:
83
- st.subheader("1. DĂ©finir la zone d'intĂ©rĂȘt")
84
  method = st.radio("MĂ©thode", ["Dessiner", "GeoJSON"], horizontal=True)
85
- if method == "Dessiner":
86
- if 'bbox' not in st.session_state:
87
- map_data = draw_box_on_map()
88
- if map_data['last_active_drawing']:
89
- coords = map_data['last_active_drawing']['geometry']['coordinates'][0]
90
- bbox = box(min(c[0] for c in coords), min(c[1] for c in coords),
91
- max(c[0] for c in coords), max(c[1] for c in coords))
92
- st.session_state['bbox'] = bbox
93
- st.session_state['geojson_wgs84'], st.session_state['geojson_swiss'] = create_geojson_from_box(bbox)
94
- st.success("Zone sélectionnée!")
95
- else:
96
- st.success("Zone déjà sélectionnée. Cliquez sur 'Effacer la zone' pour redessiner.")
97
- if st.button("Effacer la zone"):
98
- del st.session_state['bbox']
99
- del st.session_state['geojson_wgs84']
100
- del st.session_state['geojson_swiss']
101
- st.experimental_rerun()
102
- else:
103
  uploaded_file = st.file_uploader("GeoJSON", type="geojson")
104
  if uploaded_file:
105
  gdf = gpd.read_file(uploaded_file)
106
  st.session_state['geojson_wgs84'] = json.loads(gdf.to_crs(4326).to_json())
107
  st.session_state['geojson_swiss'] = json.loads(gdf.to_crs(2056).to_json())
108
  st.success("GeoJSON chargĂ©!")
109
-
110
  if st.button("Obtenir les liens de tĂ©lĂ©chargement"):
111
  if 'geojson_wgs84' not in st.session_state or 'geojson_swiss' not in st.session_state:
112
  st.error("DĂ©finissez d'abord une zone d'intĂ©rĂȘt.")
@@ -114,7 +87,7 @@ def main():
114
  st.error("SĂ©lectionnez au moins une couche Ă  extraire.")
115
  else:
116
  for layer_name in selected_layers:
117
- layer_info = layers[layer_name]
118
  bbox = gpd.GeoDataFrame.from_features(st.session_state['geojson_swiss' if layer_info["source"] == "swisstopo" else 'geojson_wgs84']).total_bounds
119
  st.write(f"Traitement de la couche : {layer_name}")
120
  st.write(f"Bbox : {bbox}")
@@ -123,6 +96,32 @@ def main():
123
  st.markdown(f"[TĂ©lĂ©charger {layer_name}]({download_url})")
124
  else:
125
  st.error(f"Impossible d'obtenir le lien pour {layer_name}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
  if __name__ == "__main__":
128
  main()
 
9
 
10
  st.set_page_config(layout="wide", page_title="Extracteur de donnĂ©es gĂ©ospatiales")
11
 
12
+ LAYERS = {
13
+ "Swisstopo - SWISSIMAGE 10 cm": {"id": "ch.swisstopo.swissimage-dop10", "source": "swisstopo", "type": "image"},
14
+ "Swisstopo - Carte nationale 1:25'000": {"id": "ch.swisstopo.pixelkarte-farbe-pk25.noscale", "source": "swisstopo", "type": "image"},
15
+ "Swisstopo - MNT": {"id": "ch.swisstopo.swissalti3d", "source": "swisstopo", "type": "raster"},
16
+ "Swisstopo - Carte géologique": {"id": "ch.swisstopo.geologie-geologische_karte", "source": "swisstopo", "type": "image"},
17
+ "Swisstopo - Limites administratives": {"id": "ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill", "source": "swisstopo", "type": "vector"},
18
+ "Swisstopo - RĂ©seau hydrographique": {"id": "ch.bafu.vec25-gewaessernetz", "source": "swisstopo", "type": "vector"},
19
+ "Swisstopo - swissBUILDINGS3D 3.0 Beta": {"id": "ch.swisstopo.swissbuildings3d_3_0", "source": "swisstopo", "type": "3d"},
20
+ "ESRI - World Imagery": {"id": "World_Imagery", "source": "esri", "type": "image"},
21
+ "ESRI - World Elevation": {"id": "Elevation/World_Elevation", "source": "esri", "type": "raster"},
22
+ "ESRI - World Topographic": {"id": "World_Topo_Map", "source": "esri", "type": "image"},
23
+ "ESRI - World Street Map": {"id": "World_Street_Map", "source": "esri", "type": "image"},
24
+ "ESRI - World Terrain": {"id": "World_Terrain_Base", "source": "esri", "type": "image"},
 
 
 
25
  }
26
 
27
  def draw_box_on_map():
 
63
  def main():
64
  st.title("Extracteur de donnĂ©es Swisstopo et ESRI")
65
 
66
+ col1, col2 = st.columns([1, 2])
67
 
68
  with col1:
69
  st.subheader("SĂ©lection des couches")
70
+ selected_layers = st.multiselect("Couches Ă  extraire", list(LAYERS.keys()))
 
 
71
 
72
+ st.subheader("DĂ©finir la zone d'intĂ©rĂȘt")
 
 
 
 
 
 
73
  method = st.radio("MĂ©thode", ["Dessiner", "GeoJSON"], horizontal=True)
74
+
75
+ if method == "GeoJSON":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  uploaded_file = st.file_uploader("GeoJSON", type="geojson")
77
  if uploaded_file:
78
  gdf = gpd.read_file(uploaded_file)
79
  st.session_state['geojson_wgs84'] = json.loads(gdf.to_crs(4326).to_json())
80
  st.session_state['geojson_swiss'] = json.loads(gdf.to_crs(2056).to_json())
81
  st.success("GeoJSON chargĂ©!")
82
+
83
  if st.button("Obtenir les liens de tĂ©lĂ©chargement"):
84
  if 'geojson_wgs84' not in st.session_state or 'geojson_swiss' not in st.session_state:
85
  st.error("DĂ©finissez d'abord une zone d'intĂ©rĂȘt.")
 
87
  st.error("SĂ©lectionnez au moins une couche Ă  extraire.")
88
  else:
89
  for layer_name in selected_layers:
90
+ layer_info = LAYERS[layer_name]
91
  bbox = gpd.GeoDataFrame.from_features(st.session_state['geojson_swiss' if layer_info["source"] == "swisstopo" else 'geojson_wgs84']).total_bounds
92
  st.write(f"Traitement de la couche : {layer_name}")
93
  st.write(f"Bbox : {bbox}")
 
96
  st.markdown(f"[TĂ©lĂ©charger {layer_name}]({download_url})")
97
  else:
98
  st.error(f"Impossible d'obtenir le lien pour {layer_name}")
99
+
100
+ st.markdown("---")
101
+ st.markdown("## À propos\nExtracteur de donnĂ©es gĂ©ospatiales Swisstopo et ESRI.\nDĂ©veloppĂ© par Vertdure")
102
+
103
+ with col2:
104
+ if 'bbox' not in st.session_state:
105
+ map_data = draw_box_on_map()
106
+ if map_data['last_active_drawing']:
107
+ coords = map_data['last_active_drawing']['geometry']['coordinates'][0]
108
+ bbox = box(min(c[0] for c in coords), min(c[1] for c in coords),
109
+ max(c[0] for c in coords), max(c[1] for c in coords))
110
+ st.session_state['bbox'] = bbox
111
+ st.session_state['geojson_wgs84'], st.session_state['geojson_swiss'] = create_geojson_from_box(bbox)
112
+ st.success("Zone sélectionnée!")
113
+ else:
114
+ st.success("Zone déjà sélectionnée. Utilisez le bouton ci-dessous pour redessiner.")
115
+ if st.button("Redessiner la zone"):
116
+ del st.session_state['bbox']
117
+ del st.session_state['geojson_wgs84']
118
+ del st.session_state['geojson_swiss']
119
+ st.experimental_rerun()
120
+ else:
121
+ # Afficher la carte avec la zone sélectionnée
122
+ m = folium.Map(location=[46.8, 8.2], zoom_start=8)
123
+ folium.GeoJson(st.session_state['geojson_wgs84']).add_to(m)
124
+ st_folium(m, width=700, height=500)
125
 
126
  if __name__ == "__main__":
127
  main()