Update app.py
Browse files
app.py
CHANGED
@@ -86,7 +86,7 @@ def process_buildings(input_gdf, sensitive_sites_gdf, default_building_height_m,
|
|
86 |
|
87 |
return buffers, intersected_sites, intersection_desc
|
88 |
|
89 |
-
def get_max_extent(*gdfs):
|
90 |
minx = min(gdf.total_bounds[0] for gdf in gdfs)
|
91 |
miny = min(gdf.total_bounds[1] for gdf in gdfs)
|
92 |
maxx = max(gdf.total_bounds[2] for gdf in gdfs)
|
@@ -95,9 +95,9 @@ def get_max_extent(*gdfs):
|
|
95 |
return minx, miny, maxx, maxy
|
96 |
|
97 |
def create_plot(filename, extent, *gdfs): # takes in unlimited number of gdfs
|
98 |
-
fig, ax = plt.subplots(figsize=(
|
99 |
|
100 |
-
colors = ['tan', '
|
101 |
|
102 |
for idx, gdf in enumerate(gdfs):
|
103 |
gdf.plot(ax=ax, color=colors[idx % len(colors)]) # Cycle through colors
|
@@ -136,9 +136,11 @@ def ss_intersect(geojson1, ss_geoselect, multiplier_factor, default_building_hei
|
|
136 |
if intersected_sites:
|
137 |
intersected_sites_gdf = pd.concat(intersected_sites, ignore_index=True)
|
138 |
intersected_sites_gdf = intersected_sites_gdf.to_crs("EPSG:4326")
|
139 |
-
|
140 |
-
|
141 |
print("No buildings are in the vicinity of any sensitive sites.")
|
|
|
|
|
142 |
|
143 |
# Perform the union operation if there is more than one buffer
|
144 |
if len(buffers) > 1:
|
@@ -158,10 +160,10 @@ def ss_intersect(geojson1, ss_geoselect, multiplier_factor, default_building_hei
|
|
158 |
lots_url = "https://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/MAPPLUTO/FeatureServer/0" # Access MapPLUTO # Eventually should be a checkbox
|
159 |
lots_gdf = get_gdf_from_feature_layer(lots_url)
|
160 |
|
161 |
-
# Create and save the plot
|
162 |
-
create_plot('output_image.png', extent, lots_gdf, buffer_union_gdf, intersected_sites_gdf, input_gdf)
|
163 |
|
164 |
-
# Return the image
|
165 |
return 'output_image.png', "building_buffers.geojson", "buffer_union.geojson", intersection_desc
|
166 |
|
167 |
|
|
|
86 |
|
87 |
return buffers, intersected_sites, intersection_desc
|
88 |
|
89 |
+
def get_max_extent(*gdfs): # takes in unlimited number of gdfs and calculates max/min xy extents
|
90 |
minx = min(gdf.total_bounds[0] for gdf in gdfs)
|
91 |
miny = min(gdf.total_bounds[1] for gdf in gdfs)
|
92 |
maxx = max(gdf.total_bounds[2] for gdf in gdfs)
|
|
|
95 |
return minx, miny, maxx, maxy
|
96 |
|
97 |
def create_plot(filename, extent, *gdfs): # takes in unlimited number of gdfs
|
98 |
+
fig, ax = plt.subplots(figsize=(5, 3)) #Sets image size by width & height (in inches)
|
99 |
|
100 |
+
colors = ['tan', 'mediumseagreen', 'thistle', 'lightcoral', 'brown', 'yellow'] # Extend/improve this list as needed
|
101 |
|
102 |
for idx, gdf in enumerate(gdfs):
|
103 |
gdf.plot(ax=ax, color=colors[idx % len(colors)]) # Cycle through colors
|
|
|
136 |
if intersected_sites:
|
137 |
intersected_sites_gdf = pd.concat(intersected_sites, ignore_index=True)
|
138 |
intersected_sites_gdf = intersected_sites_gdf.to_crs("EPSG:4326")
|
139 |
+
else: #if there aren't any intersections, return an empty geojson
|
140 |
+
intersected_sites_gdf = gpd.read_file("files/No_intersecting_buildings.geojson")
|
141 |
print("No buildings are in the vicinity of any sensitive sites.")
|
142 |
+
|
143 |
+
intersected_sites_gdf.to_file("intersected_sensitive_sites.geojson", driver='GeoJSON')
|
144 |
|
145 |
# Perform the union operation if there is more than one buffer
|
146 |
if len(buffers) > 1:
|
|
|
160 |
lots_url = "https://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/MAPPLUTO/FeatureServer/0" # Access MapPLUTO # Eventually should be a checkbox
|
161 |
lots_gdf = get_gdf_from_feature_layer(lots_url)
|
162 |
|
163 |
+
# Create and save the plot - which is the output image
|
164 |
+
create_plot('output_image.png', extent, lots_gdf, sensitive_sites_gdf, buffer_union_gdf, intersected_sites_gdf, input_gdf)
|
165 |
|
166 |
+
# Return the image, geojson files, and text description
|
167 |
return 'output_image.png', "building_buffers.geojson", "buffer_union.geojson", intersection_desc
|
168 |
|
169 |
|