Update pages/Vertbox.py
Browse files- pages/Vertbox.py +81 -60
pages/Vertbox.py
CHANGED
@@ -12,9 +12,6 @@ def get_coordinate_systems():
|
|
12 |
return {
|
13 |
"EPSG:4326": "WGS 84",
|
14 |
"EPSG:3857": "Web Mercator",
|
15 |
-
"EPSG:2154": "RGF93 / Lambert-93",
|
16 |
-
"EPSG:27572": "NTF (Paris) / Lambert zone II",
|
17 |
-
"EPSG:2056": "CH1903+ / LV95",
|
18 |
}
|
19 |
|
20 |
def convert_coordinates(bbox, from_crs, to_crs):
|
@@ -23,50 +20,66 @@ def convert_coordinates(bbox, from_crs, to_crs):
|
|
23 |
max_x, max_y = transformer.transform(bbox[2], bbox[3])
|
24 |
return [min_x, min_y, max_x, max_y]
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
draw = Draw(
|
31 |
-
export=True,
|
32 |
-
position='topleft',
|
33 |
-
draw_options={'polyline': False, 'polygon': False, 'circle': False, 'marker': False, 'circlemarker': False},
|
34 |
-
edit_options={'edit': False}
|
35 |
-
)
|
36 |
-
draw.add_to(m)
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
drawnItems.
|
48 |
-
|
49 |
-
var bbox = [bounds.getWest(), bounds.getSouth(), bounds.getEast(), bounds.getNorth()];
|
50 |
-
var bboxString = bbox.join(',');
|
51 |
-
|
52 |
-
window.parent.postMessage({
|
53 |
-
type: 'streamlit:set_widget_value',
|
54 |
-
key: 'bbox_coords',
|
55 |
-
value: bboxString
|
56 |
-
}, '*');
|
57 |
-
});
|
58 |
-
</script>
|
59 |
-
"""))
|
60 |
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
with col1:
|
65 |
folium_static(m, width=800, height=600)
|
66 |
|
67 |
with col2:
|
68 |
-
st.
|
69 |
-
bbox_coords = st.text_input("
|
70 |
|
71 |
if bbox_coords:
|
72 |
try:
|
@@ -74,38 +87,46 @@ with col2:
|
|
74 |
if len(bbox) == 4:
|
75 |
coordinate_systems = get_coordinate_systems()
|
76 |
for epsg, name in coordinate_systems.items():
|
77 |
-
st.
|
78 |
if epsg == "EPSG:4326":
|
79 |
converted_bbox = bbox
|
80 |
else:
|
81 |
converted_bbox = convert_coordinates(bbox, "EPSG:4326", epsg)
|
82 |
-
result = f"
|
83 |
st.code(result, language="plaintext")
|
84 |
-
|
|
|
|
|
85 |
# Formats supplémentaires
|
86 |
-
st.
|
87 |
-
geojson =
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
}
|
101 |
st.code(geojson, language="json")
|
102 |
-
|
103 |
-
|
|
|
|
|
104 |
wkt = f"POLYGON(({bbox[0]} {bbox[1]}, {bbox[2]} {bbox[1]}, {bbox[2]} {bbox[3]}, {bbox[0]} {bbox[3]}, {bbox[0]} {bbox[1]}))"
|
105 |
st.code(wkt, language="plaintext")
|
|
|
|
|
|
|
106 |
else:
|
107 |
st.error("Veuillez entrer 4 coordonnées séparées par des virgules.")
|
108 |
except ValueError:
|
109 |
st.error("Veuillez entrer des coordonnées valides (nombres séparés par des virgules).")
|
110 |
|
111 |
-
|
|
|
|
12 |
return {
|
13 |
"EPSG:4326": "WGS 84",
|
14 |
"EPSG:3857": "Web Mercator",
|
|
|
|
|
|
|
15 |
}
|
16 |
|
17 |
def convert_coordinates(bbox, from_crs, to_crs):
|
|
|
20 |
max_x, max_y = transformer.transform(bbox[2], bbox[3])
|
21 |
return [min_x, min_y, max_x, max_y]
|
22 |
|
23 |
+
# Styles CSS pour imiter bboxfinder.com
|
24 |
+
st.markdown("""
|
25 |
+
<style>
|
26 |
+
.main {
|
27 |
+
padding-top: 0;
|
28 |
+
}
|
29 |
+
.stApp {
|
30 |
+
margin-top: -80px;
|
31 |
+
}
|
32 |
+
.css-1kyxreq {
|
33 |
+
justify-content: center;
|
34 |
+
}
|
35 |
+
.css-5rimss {
|
36 |
+
font-size: 14px;
|
37 |
+
}
|
38 |
+
</style>
|
39 |
+
""", unsafe_allow_html=True)
|
40 |
|
41 |
+
# Layout principal
|
42 |
+
col1, col2 = st.columns([4, 1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
with col1:
|
45 |
+
# Carte
|
46 |
+
m = folium.Map(location=[0, 0], zoom_start=2)
|
47 |
+
draw = Draw(
|
48 |
+
export=True,
|
49 |
+
position='topleft',
|
50 |
+
draw_options={'polyline': False, 'polygon': False, 'circle': False, 'marker': False, 'circlemarker': False},
|
51 |
+
edit_options={'edit': False}
|
52 |
+
)
|
53 |
+
draw.add_to(m)
|
54 |
|
55 |
+
# Script JavaScript pour gérer le dessin et la mise à jour des coordonnées
|
56 |
+
m.get_root().html.add_child(folium.Element("""
|
57 |
+
<script>
|
58 |
+
var drawnItems = new L.FeatureGroup();
|
59 |
+
map.addLayer(drawnItems);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
map.on(L.Draw.Event.CREATED, function (event) {
|
62 |
+
drawnItems.clearLayers();
|
63 |
+
var layer = event.layer;
|
64 |
+
drawnItems.addLayer(layer);
|
65 |
+
var bounds = layer.getBounds();
|
66 |
+
var bbox = [bounds.getWest(), bounds.getSouth(), bounds.getEast(), bounds.getNorth()];
|
67 |
+
var bboxString = bbox.join(',');
|
68 |
+
|
69 |
+
window.parent.postMessage({
|
70 |
+
type: 'streamlit:set_widget_value',
|
71 |
+
key: 'bbox_coords',
|
72 |
+
value: bboxString
|
73 |
+
}, '*');
|
74 |
+
});
|
75 |
+
</script>
|
76 |
+
"""))
|
77 |
|
|
|
78 |
folium_static(m, width=800, height=600)
|
79 |
|
80 |
with col2:
|
81 |
+
st.markdown("<h3 style='text-align: center;'>Coordonnées</h3>", unsafe_allow_html=True)
|
82 |
+
bbox_coords = st.text_input("", key="bbox_coords", label_visibility="collapsed")
|
83 |
|
84 |
if bbox_coords:
|
85 |
try:
|
|
|
87 |
if len(bbox) == 4:
|
88 |
coordinate_systems = get_coordinate_systems()
|
89 |
for epsg, name in coordinate_systems.items():
|
90 |
+
st.markdown(f"<b>{epsg} - {name}</b>", unsafe_allow_html=True)
|
91 |
if epsg == "EPSG:4326":
|
92 |
converted_bbox = bbox
|
93 |
else:
|
94 |
converted_bbox = convert_coordinates(bbox, "EPSG:4326", epsg)
|
95 |
+
result = f"{converted_bbox[0]:.6f},{converted_bbox[1]:.6f},{converted_bbox[2]:.6f},{converted_bbox[3]:.6f}"
|
96 |
st.code(result, language="plaintext")
|
97 |
+
if st.button(f"Copier {epsg}", key=f"copy_{epsg}"):
|
98 |
+
st.write(f"{epsg} copié!")
|
99 |
+
|
100 |
# Formats supplémentaires
|
101 |
+
st.markdown("<b>GeoJSON</b>", unsafe_allow_html=True)
|
102 |
+
geojson = json.dumps({
|
103 |
+
"type": "Feature",
|
104 |
+
"properties": {},
|
105 |
+
"geometry": {
|
106 |
+
"type": "Polygon",
|
107 |
+
"coordinates": [[
|
108 |
+
[bbox[0], bbox[1]],
|
109 |
+
[bbox[2], bbox[1]],
|
110 |
+
[bbox[2], bbox[3]],
|
111 |
+
[bbox[0], bbox[3]],
|
112 |
+
[bbox[0], bbox[1]]
|
113 |
+
]]
|
114 |
+
}
|
115 |
+
}, indent=2)
|
116 |
st.code(geojson, language="json")
|
117 |
+
if st.button("Copier GeoJSON"):
|
118 |
+
st.write("GeoJSON copié!")
|
119 |
+
|
120 |
+
st.markdown("<b>WKT</b>", unsafe_allow_html=True)
|
121 |
wkt = f"POLYGON(({bbox[0]} {bbox[1]}, {bbox[2]} {bbox[1]}, {bbox[2]} {bbox[3]}, {bbox[0]} {bbox[3]}, {bbox[0]} {bbox[1]}))"
|
122 |
st.code(wkt, language="plaintext")
|
123 |
+
if st.button("Copier WKT"):
|
124 |
+
st.write("WKT copié!")
|
125 |
+
|
126 |
else:
|
127 |
st.error("Veuillez entrer 4 coordonnées séparées par des virgules.")
|
128 |
except ValueError:
|
129 |
st.error("Veuillez entrer des coordonnées valides (nombres séparés par des virgules).")
|
130 |
|
131 |
+
# Footer
|
132 |
+
st.markdown("<div style='text-align: center; color: gray;'>Créé avec Streamlit - Inspiré par bboxfinder.com</div>", unsafe_allow_html=True)
|