Vertdure commited on
Commit
4b604d3
β€’
1 Parent(s): 77d5d8c

Update pages/5_πŸ“_VertXtractor.py

Browse files
Files changed (1) hide show
  1. pages/5_πŸ“_VertXtractor.py +75 -64
pages/5_πŸ“_VertXtractor.py CHANGED
@@ -325,69 +325,80 @@ ortho = st.sidebar.checkbox("Orthophotos", value=True)
325
  mnt_resol = st.sidebar.selectbox("MNT Resolution", [0.5, 2.0], index=0)
326
  ortho_resol = st.sidebar.selectbox("Orthophoto Resolution", [0.1, 2.0], index=0)
327
 
328
- # Initialize session state for bbox
329
- if 'bbox' not in st.session_state:
330
- st.session_state.bbox = None
331
-
332
- # Create a map for bbox selection
333
- m = folium.Map(location=[46.8182, 8.2275], zoom_start=8)
334
-
335
- draw = folium.plugins.Draw()
336
- draw.add_to(m)
337
-
338
- folium_static(m)
339
-
340
- # Get bbox from drawn rectangle
341
- if st.button("Get Bounding Box"):
342
- draw_data = st.session_state.get("json_data")
343
- if draw_data and "features" in draw_data:
344
- feature = draw_data["features"][0]
345
- if feature["geometry"]["type"] == "Polygon":
346
- coords = feature["geometry"]["coordinates"][0]
347
- st.session_state.bbox = [
348
- min(coord[0] for coord in coords),
349
- min(coord[1] for coord in coords),
350
- max(coord[0] for coord in coords),
351
- max(coord[1] for coord in coords)
352
- ]
353
-
354
- if st.session_state.bbox:
355
- st.write(f"Selected bounding box (WGS84): {st.session_state.bbox}")
356
-
357
- # Convert bbox to LV95
358
- bbox_results = detect_and_convert_bbox(st.session_state.bbox)
359
-
360
- if bbox_results:
361
- bbox_wgs84, bbox_lv95 = bbox_results
362
- st.write(f"Converted bounding box (LV95): {bbox_lv95}")
 
 
 
 
363
 
364
- if st.button("Get Download Links"):
365
- with st.spinner("Fetching download links..."):
366
- urls = get_urls(bbox_wgs84, mnt, mns, bati3D_v2, bati3D_v3, ortho, mnt_resol, ortho_resol)
367
-
368
- if urls:
369
- st.success(f"Found {len(urls)} files to download:")
370
- for url in urls:
371
- st.write(url)
372
-
373
- # Option to download files
374
- if st.button("Download Files"):
375
- with st.spinner("Downloading files..."):
376
- download_path = download_files(urls, "downloads")
377
- st.success(f"Files downloaded to: {download_path}")
378
- else:
379
- st.warning("No files found for the selected area and options.")
380
 
381
- # Option to download forest data
382
- if st.button("Download Forest Data"):
383
- with st.spinner("Downloading forest data..."):
384
- with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.geojson') as tmp:
385
- geojson_forest(bbox_lv95, tmp.name)
386
- gdf = gpd.read_file(tmp.name)
387
- st.write(gdf)
388
- os.unlink(tmp.name)
389
- st.success("Forest data downloaded and displayed.")
390
- else:
391
- st.error("Selected area is outside Switzerland. Please select an area within Switzerland.")
392
-
393
- st.sidebar.info("This application allows you to download various types of geospatial data for Switzerland. Select the data types you want, draw a bounding box on the map, and click 'Get Download Links' to see available files.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  mnt_resol = st.sidebar.selectbox("MNT Resolution", [0.5, 2.0], index=0)
326
  ortho_resol = st.sidebar.selectbox("Orthophoto Resolution", [0.1, 2.0], index=0)
327
 
328
+ # Main content area
329
+ col1, col2 = st.columns([2, 1])
330
+
331
+ with col1:
332
+ st.subheader("Select Area of Interest")
333
+ m = folium.Map(location=[46.8182, 8.2275], zoom_start=8)
334
+ draw = Draw(
335
+ draw_options={
336
+ 'polyline': False,
337
+ 'polygon': False,
338
+ 'circle': False,
339
+ 'marker': False,
340
+ 'circlemarker': False,
341
+ },
342
+ edit_options={'edit': False}
343
+ )
344
+ draw.add_to(m)
345
+ folium_static(m)
346
+
347
+ with col2:
348
+ st.subheader("Bounding Box")
349
+ if 'bbox' not in st.session_state:
350
+ st.session_state.bbox = None
351
+
352
+ if st.button("Get Bounding Box"):
353
+ draw_data = st.session_state.get("json_data")
354
+ if draw_data and "features" in draw_data:
355
+ feature = draw_data["features"][0]
356
+ if feature["geometry"]["type"] == "rectangle":
357
+ coords = feature["geometry"]["coordinates"][0]
358
+ st.session_state.bbox = [
359
+ min(coord[0] for coord in coords),
360
+ min(coord[1] for coord in coords),
361
+ max(coord[0] for coord in coords),
362
+ max(coord[1] for coord in coords)
363
+ ]
364
+
365
+ if st.session_state.bbox:
366
+ st.write(f"Selected bounding box (WGS84): {st.session_state.bbox}")
367
 
368
+ # Convert bbox to LV95
369
+ bbox_results = detect_and_convert_bbox(st.session_state.bbox)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
 
371
+ if bbox_results:
372
+ bbox_wgs84, bbox_lv95 = bbox_results
373
+ st.write(f"Converted bounding box (LV95): {bbox_lv95}")
374
+
375
+ if st.button("Get Download Links"):
376
+ with st.spinner("Fetching download links..."):
377
+ urls = get_urls(bbox_wgs84, mnt, mns, bati3D_v2, bati3D_v3, ortho, mnt_resol, ortho_resol)
378
+
379
+ if urls:
380
+ st.success(f"Found {len(urls)} files to download:")
381
+ for url in urls:
382
+ st.write(url)
383
+
384
+ # Option to download files
385
+ if st.button("Download Files"):
386
+ with st.spinner("Downloading files..."):
387
+ download_path = download_files(urls, "downloads")
388
+ st.success(f"Files downloaded to: {download_path}")
389
+ else:
390
+ st.warning("No files found for the selected area and options.")
391
+
392
+ # Option to download forest data
393
+ if st.button("Download Forest Data"):
394
+ with st.spinner("Downloading forest data..."):
395
+ with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.geojson') as tmp:
396
+ geojson_forest(bbox_lv95, tmp.name)
397
+ gdf = gpd.read_file(tmp.name)
398
+ st.write(gdf)
399
+ os.unlink(tmp.name)
400
+ st.success("Forest data downloaded and displayed.")
401
+ else:
402
+ st.error("Selected area is outside Switzerland. Please select an area within Switzerland.")
403
+
404
+ st.sidebar.info("This application allows you to download various types of geospatial data for Switzerland. Select the data types you want, draw a bounding box on the map, and click 'Get Download Links' to see available files.")