File size: 2,964 Bytes
96ab3b1
e99c0c5
9121678
5f57a82
 
e99c0c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pandas as pd
import geopandas as gpd
from shapely.ops import unary_union
from arcgis_operations import get_gdf_from_feature_layer
from geospatial_operations import process_buildings, get_max_extent, create_plot

def ss_intersect(geojson1, ss_geoselect, multiplier_factor, default_building_height): 
    # Read the GeoJSON files
    input_gdf = gpd.read_file(geojson1.name)

    # Check that CRS is EPSG:4326
    if input_gdf.crs.to_epsg() != 4326:
        raise ValueError("Input GeoJSON files must be in CRS EPSG:4326")
    
    if ss_geoselect==0:
        sensitive_sites_gdf = gpd.read_file("sensitive_sites/NYC_Parks_Properties.geojson")
    else:
        sensitive_sites_gdf = gpd.read_file("sensitive_sites/NYC_Parks_Zones.geojson")

    default_building_height_m = default_building_height * 0.3048

    buffers, intersected_sites, intersection_desc = process_buildings(input_gdf, sensitive_sites_gdf, default_building_height_m, multiplier_factor)

    # Concatenate all buffer GeoDataFrames and save as a GeoJSON file
    buffers_gdf = pd.concat(buffers, ignore_index=True)
    buffers_gdf = buffers_gdf.to_crs("EPSG:4326")
    buffers_gdf.to_file("building_buffers.geojson", driver='GeoJSON')

    # Concatenate all intersected sensitive sites and save as a GeoJSON file
    if intersected_sites:
        intersected_sites_gdf = pd.concat(intersected_sites, ignore_index=True)
        intersected_sites_gdf = intersected_sites_gdf.to_crs("EPSG:4326")
    else: #if there aren't any intersections, return an empty geojson
        intersected_sites_gdf = gpd.read_file("files/No_intersecting_buildings.geojson")
        print("No buildings are in the vicinity of any sensitive sites.")
    
    intersected_sites_gdf.to_file("intersected_sensitive_sites.geojson", driver='GeoJSON')

    # Perform the union operation if there is more than one buffer
    if len(buffers) > 1:
        # Perform a unary union on the geometry column of the GeoDataFrame
        buffer_union = unary_union(buffers_gdf['geometry'])

        # Create a new GeoDataFrame from the union result
        buffer_union_gdf = gpd.GeoDataFrame(geometry=[buffer_union], crs="EPSG:4326")

        # Save the union GeoDataFrame as a GeoJSON file
        buffer_union_gdf.to_file("buffer_union.geojson", driver='GeoJSON')


    # Calculate the maximum extent
    extent = get_max_extent(input_gdf, buffers_gdf)

    lots_url = "https://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/MAPPLUTO/FeatureServer/0" # Access MapPLUTO # Eventually should be a checkbox
    lots_gdf = get_gdf_from_feature_layer(lots_url)

    # Create and save the plot - which is the output image
    create_plot('output_image.png', extent, lots_gdf, sensitive_sites_gdf, buffer_union_gdf, intersected_sites_gdf, input_gdf)
            
    # Return the image, geojson files, and text description
    return 'output_image.png', "building_buffers.geojson", "buffer_union.geojson", intersection_desc