Update src/streamlit_app.py
Browse files- src/streamlit_app.py +32 -31
src/streamlit_app.py
CHANGED
|
@@ -109,39 +109,40 @@ draw = Draw(
|
|
| 109 |
)
|
| 110 |
m.add_child(draw)
|
| 111 |
|
| 112 |
-
st.
|
| 113 |
-
st.
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
df
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
| 141 |
else:
|
| 142 |
st.info("No polygon drawn yet. Draw a polygon on the map to spatially filter properties.")
|
| 143 |
-
else:
|
| 144 |
-
st.info("No polygon drawn yet. Draw a polygon on the map to spatially filter properties.")
|
| 145 |
|
| 146 |
# --- 3. Attribute Filtering Form ---
|
| 147 |
st.subheader("Filter Property Attributes")
|
|
|
|
| 109 |
)
|
| 110 |
m.add_child(draw)
|
| 111 |
|
| 112 |
+
with st.expander("Draw a polygon on the map to spatially filter properties"):
|
| 113 |
+
st.subheader("Draw a Polygon on the Map")
|
| 114 |
+
st.info("Draw a polygon on the map to spatially filter properties. The filtered results will appear below.")
|
| 115 |
+
output = st_folium(m, width=1000, height=600, returned_objects=["all_draw_features"])
|
| 116 |
+
|
| 117 |
+
polygon_drawn = False
|
| 118 |
+
shapely_polygon = None
|
| 119 |
+
polygon_coords = None
|
| 120 |
+
|
| 121 |
+
if output and output["all_draw_features"]:
|
| 122 |
+
polygons = [
|
| 123 |
+
feature["geometry"]["coordinates"]
|
| 124 |
+
for feature in output["all_draw_features"]
|
| 125 |
+
if feature["geometry"]["type"] == "Polygon"
|
| 126 |
+
]
|
| 127 |
+
|
| 128 |
+
if polygons:
|
| 129 |
+
polygon_coords = polygons[-1][0] # Get the coordinates of the last drawn polygon
|
| 130 |
+
# Shapely Polygon expects (lon, lat) tuples, Folium provides (lat, lon)
|
| 131 |
+
shapely_polygon = Polygon([(lon, lat) for lat, lon in polygon_coords])
|
| 132 |
+
polygon_drawn = True
|
| 133 |
+
|
| 134 |
+
# Apply spatial filter to the full dataframe based on centroid containment
|
| 135 |
+
filtered_df = df[
|
| 136 |
+
df.apply(
|
| 137 |
+
lambda row: shapely_polygon.contains(Point(row['longitude'], row['latitude'])),
|
| 138 |
+
axis=1
|
| 139 |
+
)
|
| 140 |
+
].copy()
|
| 141 |
+
st.success(f"Initially filtered {len(filtered_df)} properties within the drawn polygon.")
|
| 142 |
+
else:
|
| 143 |
+
st.info("No polygon drawn yet. Draw a polygon on the map to spatially filter properties.")
|
| 144 |
else:
|
| 145 |
st.info("No polygon drawn yet. Draw a polygon on the map to spatially filter properties.")
|
|
|
|
|
|
|
| 146 |
|
| 147 |
# --- 3. Attribute Filtering Form ---
|
| 148 |
st.subheader("Filter Property Attributes")
|