Create Vertbox
Browse files- pages/Vertbox +80 -0
pages/Vertbox
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import streamlit as st
|
3 |
+
import leafmap.foliumap as leafmap
|
4 |
+
import pyproj
|
5 |
+
|
6 |
+
st.set_page_config(layout="wide")
|
7 |
+
|
8 |
+
st.sidebar.info(
|
9 |
+
"""
|
10 |
+
- Web App URL: <https://streamlit.gishub.org>
|
11 |
+
- GitHub repository: <https://github.com/giswqs/streamlit-geospatial>
|
12 |
+
"""
|
13 |
+
)
|
14 |
+
|
15 |
+
st.sidebar.title("Contact")
|
16 |
+
st.sidebar.info(
|
17 |
+
"""
|
18 |
+
Verdur at [website](https://example.com) | [GitHub](https://github.com/verdur)
|
19 |
+
"""
|
20 |
+
)
|
21 |
+
|
22 |
+
@st.cache_data
|
23 |
+
def get_coordinate_systems():
|
24 |
+
return [
|
25 |
+
"EPSG:4326 (WGS 84)",
|
26 |
+
"EPSG:3857 (Web Mercator)",
|
27 |
+
"EPSG:2154 (RGF93 / Lambert-93)",
|
28 |
+
"EPSG:27572 (NTF (Paris) / Lambert zone II)",
|
29 |
+
"EPSG:2056 (CH1903+ / LV95)", # Système de coordonnées suisse
|
30 |
+
]
|
31 |
+
|
32 |
+
def convert_coordinates(bbox, from_crs, to_crs):
|
33 |
+
transformer = pyproj.Transformer.from_crs(from_crs, to_crs, always_xy=True)
|
34 |
+
min_x, min_y = transformer.transform(bbox[0], bbox[1])
|
35 |
+
max_x, max_y = transformer.transform(bbox[2], bbox[3])
|
36 |
+
return [min_x, min_y, max_x, max_y]
|
37 |
+
|
38 |
+
def app():
|
39 |
+
st.title("Boîte de sélection sur carte et conversion de coordonnées")
|
40 |
+
st.markdown(
|
41 |
+
"""
|
42 |
+
Cette application vous permet de dessiner une boîte sur une carte et d'obtenir ses coordonnées
|
43 |
+
dans différents systèmes de coordonnées, y compris le système suisse CH1903+ / LV95.
|
44 |
+
Utilisez l'outil de dessin pour créer une boîte, puis sélectionnez les systèmes de coordonnées
|
45 |
+
souhaités pour voir les résultats.
|
46 |
+
"""
|
47 |
+
)
|
48 |
+
|
49 |
+
row1_col1, row1_col2 = st.columns([3, 1.3])
|
50 |
+
|
51 |
+
with row1_col2:
|
52 |
+
coordinate_systems = get_coordinate_systems()
|
53 |
+
selected_systems = st.multiselect(
|
54 |
+
"Sélectionnez les systèmes de coordonnées:",
|
55 |
+
coordinate_systems,
|
56 |
+
default=["EPSG:4326 (WGS 84)", "EPSG:2056 (CH1903+ / LV95)"]
|
57 |
+
)
|
58 |
+
|
59 |
+
with row1_col1:
|
60 |
+
m = leafmap.Map(center=(46.8182, 8.2275), zoom=8) # Centré sur la Suisse
|
61 |
+
m.add_drawn_features()
|
62 |
+
output = m.to_streamlit(height=500)
|
63 |
+
|
64 |
+
if output is not None and output["type"] == "FeatureCollection":
|
65 |
+
for feature in output["features"]:
|
66 |
+
if feature["geometry"]["type"] == "Polygon":
|
67 |
+
bbox = feature["bbox"]
|
68 |
+
st.subheader("Coordonnées de la boîte:")
|
69 |
+
for system in selected_systems:
|
70 |
+
epsg = system.split()[0]
|
71 |
+
if epsg == "EPSG:4326":
|
72 |
+
converted_bbox = bbox
|
73 |
+
else:
|
74 |
+
converted_bbox = convert_coordinates(bbox, "EPSG:4326", epsg)
|
75 |
+
st.write(f"{system}:")
|
76 |
+
st.write(f" Min X, Min Y: {converted_bbox[0]:.6f}, {converted_bbox[1]:.6f}")
|
77 |
+
st.write(f" Max X, Max Y: {converted_bbox[2]:.6f}, {converted_bbox[3]:.6f}")
|
78 |
+
|
79 |
+
if __name__ == "__main__":
|
80 |
+
app()
|