Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import geopandas as gpd
|
3 |
import pandas as pd
|
4 |
import os
|
|
|
5 |
from shapely.geometry import shape
|
6 |
from shapely.ops import unary_union
|
7 |
#from datasets import load_dataset
|
@@ -64,6 +65,28 @@ def process_buildings(input_gdf, sensitive_sites_gdf, default_building_height_m,
|
|
64 |
|
65 |
return buffers, intersected_sites, intersection_desc
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
def ss_intersect(geojson1, ss_geoselect, multiplier_factor, default_building_height):
|
69 |
# Read the GeoJSON files
|
@@ -106,9 +129,16 @@ def ss_intersect(geojson1, ss_geoselect, multiplier_factor, default_building_hei
|
|
106 |
# Save the union GeoDataFrame as a GeoJSON file
|
107 |
buffer_union_gdf.to_file("buffer_union.geojson", driver='GeoJSON')
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
# Return the image
|
111 |
-
return "building_buffers.geojson", "buffer_union.geojson", intersection_desc
|
112 |
|
113 |
|
114 |
iface = gr.Interface(
|
@@ -116,11 +146,11 @@ iface = gr.Interface(
|
|
116 |
inputs=[
|
117 |
gr.inputs.File(label="Building Footprints GeoJSON"),
|
118 |
gr.Radio(["Parks Properties", "Park Zones"], label="Which Sensitive Sites?", info="From NYC DPR", type="index"),
|
119 |
-
#gr.inputs.File(label="Sensitive Sites GeoJSON"), #Replaced by radio button above
|
120 |
gr.inputs.Slider(minimum=0.0, maximum=10.0, default=4.3, label="Building Height Multiplier"),
|
121 |
gr.inputs.Number(default=200, label="Default Building Height"), #Can I make this optional?
|
122 |
],
|
123 |
outputs=[
|
|
|
124 |
gr.outputs.File(label="Building Buffers"),
|
125 |
gr.outputs.File(label="Union of Building Buffers"),
|
126 |
gr.outputs.Textbox(label="Building and Sensitive Site Vicinities"),
|
|
|
2 |
import geopandas as gpd
|
3 |
import pandas as pd
|
4 |
import os
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
from shapely.geometry import shape
|
7 |
from shapely.ops import unary_union
|
8 |
#from datasets import load_dataset
|
|
|
65 |
|
66 |
return buffers, intersected_sites, intersection_desc
|
67 |
|
68 |
+
def get_max_extent(*gdfs):
|
69 |
+
minx = min(gdf.total_bounds[0] for gdf in gdfs)
|
70 |
+
miny = min(gdf.total_bounds[1] for gdf in gdfs)
|
71 |
+
maxx = max(gdf.total_bounds[2] for gdf in gdfs)
|
72 |
+
maxy = max(gdf.total_bounds[3] for gdf in gdfs)
|
73 |
+
|
74 |
+
return minx, miny, maxx, maxy
|
75 |
+
|
76 |
+
def create_plot(filename, extent, *gdfs):
|
77 |
+
fig, ax = plt.subplots(1, 1)
|
78 |
+
|
79 |
+
colors = ['blue', 'red', 'green', 'purple', 'orange', 'yellow'] # Extend this list as needed
|
80 |
+
|
81 |
+
for idx, gdf in enumerate(gdfs):
|
82 |
+
gdf.plot(ax=ax, color=colors[idx % len(colors)]) # Cycle through colors
|
83 |
+
|
84 |
+
ax.set_xlim(extent[0], extent[2])
|
85 |
+
ax.set_ylim(extent[1], extent[3])
|
86 |
+
|
87 |
+
plt.savefig(filename)
|
88 |
+
|
89 |
+
|
90 |
|
91 |
def ss_intersect(geojson1, ss_geoselect, multiplier_factor, default_building_height):
|
92 |
# Read the GeoJSON files
|
|
|
129 |
# Save the union GeoDataFrame as a GeoJSON file
|
130 |
buffer_union_gdf.to_file("buffer_union.geojson", driver='GeoJSON')
|
131 |
|
132 |
+
|
133 |
+
# Calculate the maximum extent
|
134 |
+
extent = get_max_extent(input_gdf, buffers_gdf)
|
135 |
+
|
136 |
+
# Create and save the plot
|
137 |
+
create_plot('output_image.png', extent, input_gdf, intersected_sites_gdf, buffer_union_gdf)
|
138 |
+
|
139 |
|
140 |
# Return the image
|
141 |
+
return "output_image.png", "building_buffers.geojson", "buffer_union.geojson", intersection_desc
|
142 |
|
143 |
|
144 |
iface = gr.Interface(
|
|
|
146 |
inputs=[
|
147 |
gr.inputs.File(label="Building Footprints GeoJSON"),
|
148 |
gr.Radio(["Parks Properties", "Park Zones"], label="Which Sensitive Sites?", info="From NYC DPR", type="index"),
|
|
|
149 |
gr.inputs.Slider(minimum=0.0, maximum=10.0, default=4.3, label="Building Height Multiplier"),
|
150 |
gr.inputs.Number(default=200, label="Default Building Height"), #Can I make this optional?
|
151 |
],
|
152 |
outputs=[
|
153 |
+
gr.outputs.Image(label="Result Image"),
|
154 |
gr.outputs.File(label="Building Buffers"),
|
155 |
gr.outputs.File(label="Union of Building Buffers"),
|
156 |
gr.outputs.Textbox(label="Building and Sensitive Site Vicinities"),
|