Update pages/Vertbox.py
Browse files- pages/Vertbox.py +29 -27
pages/Vertbox.py
CHANGED
@@ -13,6 +13,9 @@ def get_coordinate_systems():
|
|
13 |
return {
|
14 |
"EPSG:4326": "WGS 84",
|
15 |
"EPSG:3857": "Web Mercator",
|
|
|
|
|
|
|
16 |
}
|
17 |
|
18 |
def convert_coordinates(bbox, from_crs, to_crs):
|
@@ -21,21 +24,13 @@ def convert_coordinates(bbox, from_crs, to_crs):
|
|
21 |
max_x, max_y = transformer.transform(bbox[2], bbox[3])
|
22 |
return [min_x, min_y, max_x, max_y]
|
23 |
|
24 |
-
# Styles CSS
|
25 |
st.markdown("""
|
26 |
<style>
|
27 |
-
.main {
|
28 |
-
|
29 |
-
}
|
30 |
-
.
|
31 |
-
margin-top: -80px;
|
32 |
-
}
|
33 |
-
.css-1kyxreq {
|
34 |
-
justify-content: center;
|
35 |
-
}
|
36 |
-
.css-5rimss {
|
37 |
-
font-size: 14px;
|
38 |
-
}
|
39 |
</style>
|
40 |
""", unsafe_allow_html=True)
|
41 |
|
@@ -53,14 +48,14 @@ st.sidebar.info(
|
|
53 |
"[LinkedIn](https://www.linkedin.com/in/yourprofile)"
|
54 |
)
|
55 |
|
56 |
-
#
|
57 |
col1, col2 = st.columns([4, 1])
|
58 |
|
59 |
with col1:
|
60 |
st.title("Improved BBox Finder")
|
61 |
|
62 |
-
#
|
63 |
-
m = leafmap.Map(center=[
|
64 |
draw = Draw(
|
65 |
export=True,
|
66 |
position='topleft',
|
@@ -69,7 +64,7 @@ with col1:
|
|
69 |
)
|
70 |
draw.add_to(m)
|
71 |
|
72 |
-
#
|
73 |
m.add_child(folium.Element("""
|
74 |
<script>
|
75 |
var drawnItems = new L.FeatureGroup();
|
@@ -97,23 +92,30 @@ with col2:
|
|
97 |
st.markdown("<h3 style='text-align: center;'>Coordinates</h3>", unsafe_allow_html=True)
|
98 |
bbox_coords = st.text_input("", key="bbox_coords", label_visibility="collapsed")
|
99 |
|
|
|
|
|
|
|
|
|
100 |
if bbox_coords:
|
101 |
try:
|
102 |
bbox = [float(coord.strip()) for coord in bbox_coords.split(',')]
|
103 |
if len(bbox) == 4:
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
for epsg, name in coordinate_systems.items():
|
106 |
-
|
107 |
-
if epsg == "EPSG:4326":
|
108 |
-
converted_bbox = bbox
|
109 |
-
else:
|
110 |
converted_bbox = convert_coordinates(bbox, "EPSG:4326", epsg)
|
111 |
-
|
112 |
-
|
113 |
-
if st.button(f"Copy {epsg}", key=f"copy_{epsg}"):
|
114 |
-
st.write(f"{epsg} copied!")
|
115 |
|
116 |
-
# Additional formats
|
117 |
st.markdown("<b>GeoJSON</b>", unsafe_allow_html=True)
|
118 |
geojson = json.dumps({
|
119 |
"type": "Feature",
|
|
|
13 |
return {
|
14 |
"EPSG:4326": "WGS 84",
|
15 |
"EPSG:3857": "Web Mercator",
|
16 |
+
"EPSG:2154": "RGF93 / Lambert-93 (France)",
|
17 |
+
"EPSG:27572": "NTF (Paris) / Lambert zone II (France)",
|
18 |
+
"EPSG:25832": "ETRS89 / UTM zone 32N (Germany)",
|
19 |
}
|
20 |
|
21 |
def convert_coordinates(bbox, from_crs, to_crs):
|
|
|
24 |
max_x, max_y = transformer.transform(bbox[2], bbox[3])
|
25 |
return [min_x, min_y, max_x, max_y]
|
26 |
|
27 |
+
# Styles CSS
|
28 |
st.markdown("""
|
29 |
<style>
|
30 |
+
.main { padding-top: 0; }
|
31 |
+
.stApp { margin-top: -80px; }
|
32 |
+
.css-1kyxreq { justify-content: center; }
|
33 |
+
.css-5rimss { font-size: 14px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
</style>
|
35 |
""", unsafe_allow_html=True)
|
36 |
|
|
|
48 |
"[LinkedIn](https://www.linkedin.com/in/yourprofile)"
|
49 |
)
|
50 |
|
51 |
+
# Main layout
|
52 |
col1, col2 = st.columns([4, 1])
|
53 |
|
54 |
with col1:
|
55 |
st.title("Improved BBox Finder")
|
56 |
|
57 |
+
# Map
|
58 |
+
m = leafmap.Map(center=[46.2, 6.15], zoom=8) # Centered on Geneva
|
59 |
draw = Draw(
|
60 |
export=True,
|
61 |
position='topleft',
|
|
|
64 |
)
|
65 |
draw.add_to(m)
|
66 |
|
67 |
+
# JavaScript to handle drawing and coordinate updates
|
68 |
m.add_child(folium.Element("""
|
69 |
<script>
|
70 |
var drawnItems = new L.FeatureGroup();
|
|
|
92 |
st.markdown("<h3 style='text-align: center;'>Coordinates</h3>", unsafe_allow_html=True)
|
93 |
bbox_coords = st.text_input("", key="bbox_coords", label_visibility="collapsed")
|
94 |
|
95 |
+
# CRS selection
|
96 |
+
coordinate_systems = get_coordinate_systems()
|
97 |
+
selected_crs = st.selectbox("Select Coordinate Reference System", options=list(coordinate_systems.keys()), format_func=lambda x: f"{x} - {coordinate_systems[x]}")
|
98 |
+
|
99 |
if bbox_coords:
|
100 |
try:
|
101 |
bbox = [float(coord.strip()) for coord in bbox_coords.split(',')]
|
102 |
if len(bbox) == 4:
|
103 |
+
st.markdown(f"<b>Selected CRS: {selected_crs}</b>", unsafe_allow_html=True)
|
104 |
+
converted_bbox = convert_coordinates(bbox, "EPSG:4326", selected_crs)
|
105 |
+
result = f"{converted_bbox[0]:.6f},{converted_bbox[1]:.6f},{converted_bbox[2]:.6f},{converted_bbox[3]:.6f}"
|
106 |
+
st.code(result, language="plaintext")
|
107 |
+
if st.button(f"Copy {selected_crs}"):
|
108 |
+
st.write(f"{selected_crs} coordinates copied!")
|
109 |
+
|
110 |
+
# Display in other common CRSs
|
111 |
+
st.markdown("<b>Other common CRSs:</b>", unsafe_allow_html=True)
|
112 |
for epsg, name in coordinate_systems.items():
|
113 |
+
if epsg != selected_crs:
|
|
|
|
|
|
|
114 |
converted_bbox = convert_coordinates(bbox, "EPSG:4326", epsg)
|
115 |
+
result = f"{converted_bbox[0]:.6f},{converted_bbox[1]:.6f},{converted_bbox[2]:.6f},{converted_bbox[3]:.6f}"
|
116 |
+
st.code(f"{epsg}: {result}", language="plaintext")
|
|
|
|
|
117 |
|
118 |
+
# Additional formats (GeoJSON, WKT)
|
119 |
st.markdown("<b>GeoJSON</b>", unsafe_allow_html=True)
|
120 |
geojson = json.dumps({
|
121 |
"type": "Feature",
|