You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a user, I'd like to have a single method for specifically updating the distance of links since this is a common chore.
Status
Defined
Planned
Implemented
Tested
Resolution Ideas
defupdate_distance(
self,
links_df: GeoDataFrame=None,
use_shapes: bool=False,
units: str="miles",
network_variable: str="distance",
overwrite: bool=True,
inplace=True,
):
""" Calculate link distance in specified units to network variable using either straight line distance or (if specified) shape distance if available. Args: links_df: Links GeoDataFrame. Useful if want to update a portion of network links (i.e. only centroid connectors). If not provided, will use entire self.links_df. use_shapes: if True, will add length information from self.shapes_df rather than crow-fly. If no corresponding shape found in self.shapes_df, will default to crow-fly. units: units to use. Defaults to the standard unit of miles. Available units: "meters", "miles". network_variable: variable to store link distance in. Defaults to "distance". overwrite: Defaults to True and will overwrite all existing calculated distances. False will only update NaNs. inplace: updates self.links_df Returns: links_df with updated distance """ifunitsnotin ["miles", "meters"]:
raiseNotImplementedErroriflinks_dfisNone:
links_df=self.links_df.copy()
msg="Update distance in {} to variable: {}".format(units, network_variable)
ifoverwrite:
msg+"\n - overwriting existing calculated values if found."ifuse_shapes:
msg+"\n - using shapes_df length if found."WranglerLogger.debug(msg)
""" Start actual process """temp_links_gdf=links_df.copy()
temp_links_gdf.crs="EPSG:4326"temp_links_gdf=temp_links_gdf.to_crs(epsg=26915) # in metersconversion_from_meters= {"miles": 1/1609.34, "meters": 1}
temp_links_gdf[network_variable] = (
temp_links_gdf.geometry.length*conversion_from_meters[units]
)
ifuse_shapes:
_needed_shapes_gdf=self.shapes_df.merge(
links_df[self.shape_foreign_key],
on=self.shape_foreign_key,
how="inner",
)
_needed_shapes_gdf=_needed_shapes_gdf.to_crs(epsg=26915)
_needed_shapes_gdf[network_variable] = (
_needed_shapes_gdf.geometry.length*conversion_from_meters[units]
)
temp_links_gdf=update_df(
temp_links_gdf,
_needed_shapes_gdf,
merge_key=self.shape_foreign_key,
update_fields=[network_variable],
method="update if found",
)
ifoverwrite:
links_df[network_variable] =temp_links_gdf[network_variable]
else:
links_df=update_df(
links_df,
temp_links_gdf,
merge_key=self.unique_link_key,
update_fields=[network_variable],
method="update nan",
)
ifinplace:
self.links_df=links_dfelse:
returnlinks_df
The text was updated successfully, but these errors were encountered:
As a user, I'd like to have a single method for specifically updating the distance of links since this is a common chore.
Status
Resolution Ideas
The text was updated successfully, but these errors were encountered: