From d5b17dd83f47112e85d9ab7b5580454e5b1276fc Mon Sep 17 00:00:00 2001 From: David Ory Date: Thu, 17 Sep 2020 20:01:04 -0400 Subject: [PATCH] downtown area type fix --- lasso/parameters.py | 16 ++++++++++++++++ lasso/project.py | 3 +-- lasso/roadway.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/lasso/parameters.py b/lasso/parameters.py index 1cca076..998dbdd 100644 --- a/lasso/parameters.py +++ b/lasso/parameters.py @@ -212,6 +212,14 @@ class Parameters: 53: 1, 60: 1, } + downtown_area_type_shape (str): Location of shapefile defining downtown area type. + Default: + :: + r"metcouncil_data/area_type/downtownzones_TAZ.shp" + downtown_area_type (int): Area type integer for downtown. + Default: + :: + 5 mrcc_roadway_class_shape (str): Shapefile of MRCC links with a property associated with roadway class. Default: :: @@ -470,6 +478,14 @@ def __init__(self, **kwargs): 60: 1, } + self.downtown_area_type_shape = os.path.join( + self.data_file_location, + "area_type", + "downtownzones_TAZ.shp", + ) + + self.downtown_area_type = int(5) + self.osm_assgngrp_dict = os.path.join( self.data_file_location, "lookups", "osm_highway_asgngrp_crosswalk.csv" ) diff --git a/lasso/project.py b/lasso/project.py index 4b7cee9..98f6c6a 100644 --- a/lasso/project.py +++ b/lasso/project.py @@ -537,8 +537,7 @@ def _process_link_additions( else: add_col = [ c - for c in cube_add_df.columns - if c not "OPERATION_final" + for c in cube_add_df.columns if c not in ["OPERATION_final"] ] # can leave out "OPERATION_final" from writing out, is there a reason to write it out? diff --git a/lasso/roadway.py b/lasso/roadway.py index a8c4d10..6aa47ba 100644 --- a/lasso/roadway.py +++ b/lasso/roadway.py @@ -314,6 +314,8 @@ def calculate_area_type( area_type_shape_variable=None, network_variable="area_type", area_type_codes_dict=None, + downtown_area_type_shape=None, + downtown_area_type=None, overwrite=False, ): """ @@ -327,6 +329,8 @@ def calculate_area_type( area_type_shape_variable (str): The variable name of area type in area geodadabase. network_variable (str): The variable name of area type in network standard. Default to "area_type". area_type_codes_dict: The dictionary to map input area_type_shape_variable to network_variable + downtown_area_type_shape: The file path to the downtown area type boundary. + downtown_area_type (int): Integer value of downtown area type overwrite (Bool): True if overwriting existing county variable in network. Default to False. Returns: @@ -393,6 +397,29 @@ def calculate_area_type( WranglerLogger.error(msg) raise ValueError(msg) + downtown_area_type_shape = ( + downtown_area_type_shape if downtown_area_type_shape else self.parameters.downtown_area_type_shape + ) + + if not downtown_area_type_shape: + msg = "No downtown area type shape specified" + WranglerLogger.error(msg) + raise ValueError(msg) + if not os.path.exists(downtown_area_type_shape): + msg = "File not found for downtown area type shape: {}".format(downtown_area_type_shape) + WranglerLogger.error(msg) + raise ValueError(msg) + + downtown_area_type = ( + downtown_area_type + if downtown_area_type + else self.parameters.downtown_area_type + ) + if not downtown_area_type: + msg = "No downtown area type value specified" + WranglerLogger.error(msg) + raise ValueError(msg) + """ Start actual process """ @@ -403,6 +430,9 @@ def calculate_area_type( area_type_gdf = gpd.read_file(area_type_shape) area_type_gdf = area_type_gdf.to_crs(epsg=RoadwayNetwork.CRS) + downtown_gdf = gpd.read_file(downtown_area_type_shape) + downtown_gdf = downtown_gdf.to_crs(epsg=RoadwayNetwork.CRS) + joined_gdf = gpd.sjoin( centroids_gdf, area_type_gdf, how="left", op="intersects" ) @@ -416,6 +446,20 @@ def calculate_area_type( WranglerLogger.debug("Area Type Codes Used: {}".format(area_type_codes_dict)) + d_joined_gdf = gpd.sjoin( + centroids_gdf, downtown_gdf, how="left", op="intersects" + ) + + d_joined_gdf['downtown_area_type'] = ( + d_joined_gdf['Id'] + .fillna(-99) + .astype(int) + ) + + joined_gdf.loc[d_joined_gdf['downtown_area_type'] == 0, area_type_shape_variable] = downtown_area_type + + WranglerLogger.debug("Downtown Area Type used boundary file: {}".format(downtown_area_type_shape)) + self.links_df[network_variable] = joined_gdf[area_type_shape_variable] WranglerLogger.info(