Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import geopandas as gpd
|
|
|
3 |
from shapely.geometry import shape
|
4 |
#from datasets import load_dataset
|
5 |
|
@@ -11,6 +12,8 @@ def process_buildings(input_gdf, sensitive_sites_gdf, default_building_height_m,
|
|
11 |
|
12 |
# List to store all buffers
|
13 |
buffers = []
|
|
|
|
|
14 |
|
15 |
# Iterate over each building in the input file
|
16 |
for idx, building in input_gdf.iterrows():
|
@@ -47,17 +50,20 @@ def process_buildings(input_gdf, sensitive_sites_gdf, default_building_height_m,
|
|
47 |
|
48 |
# Check if the buffer intersects with any sensitive sites
|
49 |
intersects = gpd.overlay(building_buffer_gdf, sensitive_sites_gdf, how='intersection')
|
50 |
-
|
51 |
if not intersects.empty:
|
52 |
-
|
53 |
intersected_sites.append(intersects)
|
54 |
else:
|
55 |
-
|
56 |
|
57 |
-
|
|
|
|
|
|
|
58 |
|
59 |
|
60 |
-
def ss_intersect(geojson1, ss_geoselect, multiplier_factor, default_building_height):
|
61 |
# Read the GeoJSON files
|
62 |
input_gdf = gpd.read_file(geojson1.name)
|
63 |
|
@@ -72,7 +78,7 @@ def ss_intersect(geojson1, ss_geoselect, multiplier_factor, default_building_hei
|
|
72 |
|
73 |
default_building_height_m = default_building_height * 0.3048
|
74 |
|
75 |
-
buffers, intersected_sites = process_buildings(input_gdf, sensitive_sites_gdf, default_building_height_m, multiplier_factor)
|
76 |
|
77 |
# Concatenate all buffer GeoDataFrames and save as a GeoJSON file
|
78 |
buffers_gdf = pd.concat(buffers, ignore_index=True)
|
@@ -100,7 +106,7 @@ def ss_intersect(geojson1, ss_geoselect, multiplier_factor, default_building_hei
|
|
100 |
|
101 |
|
102 |
# Return the image
|
103 |
-
return
|
104 |
|
105 |
|
106 |
iface = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
import geopandas as gpd
|
3 |
+
import os
|
4 |
from shapely.geometry import shape
|
5 |
#from datasets import load_dataset
|
6 |
|
|
|
12 |
|
13 |
# List to store all buffers
|
14 |
buffers = []
|
15 |
+
|
16 |
+
intersection_desc = ""
|
17 |
|
18 |
# Iterate over each building in the input file
|
19 |
for idx, building in input_gdf.iterrows():
|
|
|
50 |
|
51 |
# Check if the buffer intersects with any sensitive sites
|
52 |
intersects = gpd.overlay(building_buffer_gdf, sensitive_sites_gdf, how='intersection')
|
53 |
+
|
54 |
if not intersects.empty:
|
55 |
+
building_intersect_desc = f"Building {idx} ({building_name}), height: {building_height_ft}, buffer distance: {buffer_distance_ft} is in the vicinity of a sensitive site."
|
56 |
intersected_sites.append(intersects)
|
57 |
else:
|
58 |
+
building_intersect_desc = f"Building {idx} ({building_name}), height: {building_height_ft}, buffer distance: {buffer_distance_ft} is not in the vicinity of any sensitive sites."
|
59 |
|
60 |
+
intersection_desc = "\n".join(intersection_desc, building_intersect_desc)
|
61 |
+
|
62 |
+
|
63 |
+
return buffers, intersected_sites, intersection_desc
|
64 |
|
65 |
|
66 |
+
def ss_intersect(geojson1, ss_geoselect, multiplier_factor, default_building_height):
|
67 |
# Read the GeoJSON files
|
68 |
input_gdf = gpd.read_file(geojson1.name)
|
69 |
|
|
|
78 |
|
79 |
default_building_height_m = default_building_height * 0.3048
|
80 |
|
81 |
+
buffers, intersected_sites, intersection_desc = process_buildings(input_gdf, sensitive_sites_gdf, default_building_height_m, multiplier_factor)
|
82 |
|
83 |
# Concatenate all buffer GeoDataFrames and save as a GeoJSON file
|
84 |
buffers_gdf = pd.concat(buffers, ignore_index=True)
|
|
|
106 |
|
107 |
|
108 |
# Return the image
|
109 |
+
return "building_buffers.geojson", intersection_desc
|
110 |
|
111 |
|
112 |
iface = gr.Interface(
|