npc0 commited on
Commit
a2f75f4
·
verified ·
1 Parent(s): af5ac46

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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.subheader("Draw a Polygon on the Map")
113
- st.info("Draw a polygon on the map to spatially filter properties. The filtered results will appear below.")
114
- output = st_folium(m, width=1000, height=600, returned_objects=["all_draw_features"])
115
-
116
- polygon_drawn = False
117
- shapely_polygon = None
118
- polygon_coords = None
119
-
120
- if output and output["all_draw_features"]:
121
- polygons = [
122
- feature["geometry"]["coordinates"]
123
- for feature in output["all_draw_features"]
124
- if feature["geometry"]["type"] == "Polygon"
125
- ]
126
-
127
- if polygons:
128
- polygon_coords = polygons[-1][0] # Get the coordinates of the last drawn polygon
129
- # Shapely Polygon expects (lon, lat) tuples, Folium provides (lat, lon)
130
- shapely_polygon = Polygon([(lon, lat) for lat, lon in polygon_coords])
131
- polygon_drawn = True
132
-
133
- # Apply spatial filter to the full dataframe based on centroid containment
134
- filtered_df = df[
135
- df.apply(
136
- lambda row: shapely_polygon.contains(Point(row['longitude'], row['latitude'])),
137
- axis=1
138
- )
139
- ].copy()
140
- st.success(f"Initially filtered {len(filtered_df)} properties within the drawn polygon.")
 
 
 
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")