Skip to content

Commit

Permalink
downtown area type fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidOry committed Sep 18, 2020
1 parent d3057b0 commit d5b17dd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
16 changes: 16 additions & 0 deletions lasso/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
::
Expand Down Expand Up @@ -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"
)
Expand Down
3 changes: 1 addition & 2 deletions lasso/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

This comment has been minimized.

Copy link
@DavidOry

DavidOry Sep 18, 2020

Author Member

@e-lo This line was giving me a compile error, so I made this change. Please have a look.

]
# can leave out "OPERATION_final" from writing out, is there a reason to write it out?

Expand Down
44 changes: 44 additions & 0 deletions lasso/roadway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
"""
Expand All @@ -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:
Expand Down Expand Up @@ -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
"""
Expand All @@ -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"
)
Expand All @@ -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

This comment has been minimized.

Copy link
@DavidOry

DavidOry Sep 18, 2020

Author Member

@e-lo In pandas, you can index one dataframe with another. So convenient :).


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(
Expand Down

0 comments on commit d5b17dd

Please sign in to comment.