Update pages/12_🌲_VertXtractor.py
Browse files- pages/12_🌲_VertXtractor.py +32 -13
pages/12_🌲_VertXtractor.py
CHANGED
@@ -17,9 +17,10 @@ LAYERS = {
|
|
17 |
"Carte géologique": {"id": "ch.swisstopo.geologie-geologische_karte", "source": "swisstopo", "type": "image"},
|
18 |
"Limites administratives": {"id": "ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill", "source": "swisstopo", "type": "vector"},
|
19 |
"Réseau hydrographique": {"id": "ch.bafu.vec25-gewaessernetz", "source": "swisstopo", "type": "vector"},
|
|
|
20 |
# ESRI
|
21 |
"World Imagery": {"id": "World_Imagery", "source": "esri", "type": "image"},
|
22 |
-
"World Elevation": {"id": "
|
23 |
"World Topographic": {"id": "World_Topo_Map", "source": "esri", "type": "image"},
|
24 |
"World Street Map": {"id": "World_Street_Map", "source": "esri", "type": "image"},
|
25 |
"World Terrain": {"id": "World_Terrain_Base", "source": "esri", "type": "image"},
|
@@ -38,24 +39,42 @@ def create_geojson_from_box(bbox):
|
|
38 |
@st.cache_data
|
39 |
def get_download_url(bbox, layer_info):
|
40 |
if layer_info["source"] == "swisstopo":
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
else: # ESRI
|
51 |
-
service_url = f"https://server.arcgisonline.com/arcgis/rest/services/{layer_info['id']}/
|
52 |
params = {
|
53 |
"bbox": f"{bbox[0]},{bbox[1]},{bbox[2]},{bbox[3]}",
|
54 |
"bboxSR": 4326,
|
55 |
"size": "1000,1000",
|
56 |
-
"format": "
|
57 |
"f": "json",
|
58 |
-
"imageSR": 4326
|
|
|
|
|
|
|
59 |
}
|
60 |
try:
|
61 |
response = requests.get(service_url, params=params)
|
|
|
17 |
"Carte géologique": {"id": "ch.swisstopo.geologie-geologische_karte", "source": "swisstopo", "type": "image"},
|
18 |
"Limites administratives": {"id": "ch.swisstopo.swissboundaries3d-gemeinde-flaeche.fill", "source": "swisstopo", "type": "vector"},
|
19 |
"Réseau hydrographique": {"id": "ch.bafu.vec25-gewaessernetz", "source": "swisstopo", "type": "vector"},
|
20 |
+
"swissBUILDINGS3D 3.0 Beta": {"id": "ch.swisstopo.swissbuildings3d_3_0", "source": "swisstopo", "type": "3d"},
|
21 |
# ESRI
|
22 |
"World Imagery": {"id": "World_Imagery", "source": "esri", "type": "image"},
|
23 |
+
"World Elevation": {"id": "World_Elevation", "source": "esri", "type": "raster"},
|
24 |
"World Topographic": {"id": "World_Topo_Map", "source": "esri", "type": "image"},
|
25 |
"World Street Map": {"id": "World_Street_Map", "source": "esri", "type": "image"},
|
26 |
"World Terrain": {"id": "World_Terrain_Base", "source": "esri", "type": "image"},
|
|
|
39 |
@st.cache_data
|
40 |
def get_download_url(bbox, layer_info):
|
41 |
if layer_info["source"] == "swisstopo":
|
42 |
+
if layer_info["type"] == "3d":
|
43 |
+
api_url = "https://data.geo.admin.ch/api/stac/v0.9/collections/ch.swisstopo.swissbuildings3d_3_0/items"
|
44 |
+
params = {
|
45 |
+
"bbox": ",".join(map(str, bbox)),
|
46 |
+
"limit": 1,
|
47 |
+
"datetime": "2023-01-01/2024-12-31"
|
48 |
+
}
|
49 |
+
response = requests.get(api_url, params=params)
|
50 |
+
data = response.json()
|
51 |
+
if data['features']:
|
52 |
+
feature = data['features'][0]
|
53 |
+
asset_keys = feature['assets'].keys()
|
54 |
+
data_key = 'gltf' if 'gltf' in asset_keys else next(iter(asset_keys))
|
55 |
+
return feature['assets'][data_key]['href']
|
56 |
+
else:
|
57 |
+
api_url = f"https://data.geo.admin.ch/api/stac/v0.9/collections/{layer_info['id']}/items"
|
58 |
+
params = {"bbox": ",".join(map(str, bbox)), "limit": 1}
|
59 |
+
response = requests.get(api_url, params=params)
|
60 |
+
data = response.json()
|
61 |
+
if data['features']:
|
62 |
+
feature = data['features'][0]
|
63 |
+
asset_keys = feature['assets'].keys()
|
64 |
+
data_key = 'rgb' if 'rgb' in asset_keys else 'data' if 'data' in asset_keys else next(iter(asset_keys))
|
65 |
+
return feature['assets'][data_key]['href']
|
66 |
else: # ESRI
|
67 |
+
service_url = f"https://server.arcgisonline.com/arcgis/rest/services/{layer_info['id']}/MapServer/export"
|
68 |
params = {
|
69 |
"bbox": f"{bbox[0]},{bbox[1]},{bbox[2]},{bbox[3]}",
|
70 |
"bboxSR": 4326,
|
71 |
"size": "1000,1000",
|
72 |
+
"format": "png",
|
73 |
"f": "json",
|
74 |
+
"imageSR": 4326,
|
75 |
+
"transparent": "true",
|
76 |
+
"dpi": 96,
|
77 |
+
"world_file": "true"
|
78 |
}
|
79 |
try:
|
80 |
response = requests.get(service_url, params=params)
|