Spaces:
Sleeping
Sleeping
fix multi-geometry issue
Browse files
app.py
CHANGED
@@ -22,6 +22,11 @@ def preprocess_gdf(gdf):
|
|
22 |
return gdf
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
# wide streamlit display
|
26 |
st.set_page_config(layout="wide")
|
27 |
|
@@ -72,6 +77,15 @@ else:
|
|
72 |
input_gdf = preprocess_gdf(gpd.read_file(file_url))
|
73 |
if len(input_gdf) > 1:
|
74 |
st.warning(f"Only the first polygon in the KML will be processed; all other geometries will be ignored.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
st.session_state.input_gdf = input_gdf
|
76 |
# st.toast("Data loaded and cached")
|
77 |
|
|
|
22 |
return gdf
|
23 |
|
24 |
|
25 |
+
def is_valid_polygon(geometry_gdf):
|
26 |
+
geometry = geometry_gdf.geometry.item()
|
27 |
+
return (geometry.type == "Polygon") and (not geometry.is_empty)
|
28 |
+
|
29 |
+
|
30 |
# wide streamlit display
|
31 |
st.set_page_config(layout="wide")
|
32 |
|
|
|
77 |
input_gdf = preprocess_gdf(gpd.read_file(file_url))
|
78 |
if len(input_gdf) > 1:
|
79 |
st.warning(f"Only the first polygon in the KML will be processed; all other geometries will be ignored.")
|
80 |
+
|
81 |
+
for i in range(len(input_gdf)):
|
82 |
+
geometry_gdf = input_gdf[input_gdf.index == i]
|
83 |
+
if is_valid_polygon(geometry_gdf):
|
84 |
+
break
|
85 |
+
else:
|
86 |
+
st.error(f"No polygon found inside KML. Please check the KML file.")
|
87 |
+
st.stop()
|
88 |
+
|
89 |
st.session_state.input_gdf = input_gdf
|
90 |
# st.toast("Data loaded and cached")
|
91 |
|