Roadway ¶
The roadway module contains submodules which define and extend the links, nodes, and shapes dataframe objects which within a RoadwayNetwork object as well as other classes and methods which support and extend the RoadwayNetwork class.
Roadway Network Objects ¶
Submodules which define and extend the links, nodes, and shapes dataframe objects which within a RoadwayNetwork object. Includes classes which define:
- dataframe schemas to be used for dataframe validation using
pandera
- methods which extend the dataframes
Tables ¶
Datamodels for Roadway Network Tables.
This module contains the datamodels used to validate the format and types of Roadway Network tables.
Includes:
- RoadLinksTable
- RoadNodesTable
- RoadShapesTable
- ExplodedScopedLinkPropertyTable
network_wrangler.models.roadway.tables.ExplodedScopedLinkPropertyTable ¶
Bases: DataFrameModel
Datamodel used to validate an exploded links_df by scope.
Source code in network_wrangler/models/roadway/tables.py
network_wrangler.models.roadway.tables.RoadLinksTable ¶
Bases: DataFrameModel
Datamodel used to validate if links_df is of correct format and types.
Attributes:
-
model_link_id
(int
) –Unique identifier for the link.
-
A
(int
) –model_node_id
of the link’s start node. Foreign key toroad_nodes
. -
B
(int
) –model_node_id
of the link’s end node. Foreign key toroad_nodes
. -
geometry
(GeoSeries
) –Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Simple A→B geometry of the link.
-
name
(str
) –Name of the link.
-
rail_only
(bool
) –If the link is only for rail. Default is False.
-
bus_only
(bool
) –If the link is only for buses. Default is False.
-
drive_access
(bool
) –If the link allows driving. Default is True.
-
bike_access
(bool
) –If the link allows biking. Default is True.
-
walk_access
(bool
) –If the link allows walking. Default is True.
-
truck_access
(bool
) –If the link allows trucks. Default is True.
-
distance
(float
) –Length of the link.
-
roadway
(str
) –Type of roadway per OSM definitions. Default is “road”.
-
projects
(str
) –Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Comma-separated list of project names applied to the link. Default is “”.
-
managed
(int
) –Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Indicator for the type of managed lane facility. Values can be:
- 0 indicating no managed lane on this link.
- 1 indicates that there is a managed lane on the link (std network) or that the link is a managed lane (model network).
- -1 indicates that there is a parallel managed lane derived from this link (model network).
-
shape_id
(str
) –Identifier referencing the primary key of the shapes table. Default is None.
-
lanes
(int
) –Default number of lanes on the link. Default is 1.
-
sc_lanes
(Optional[list[dict]]
) –List of scoped link values for the number of lanes. Default is None. Example:
[{'timespan':['12:00':'15:00'], 'value': 3},{'timespan':['15:00':'19:00'], 'value': 2}]
. -
price
(float
) –Default price to use the link. Default is 0.
-
sc_price
(Optional[list[dict]]
) –List of scoped link values for the price. Default is None. Example:
[{'timespan':['15:00':'19:00'],'category': 'sov', 'value': 2.5}]
. -
ref
(Optional[str]
) –Reference numbers for link referring to a route or exit number per the OSM definition. Default is None.
-
access
(Optional[Any]
) –User-defined method to note access restrictions for the link. Default is None.
-
ML_projects
(Optional[str]
) –Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Comma-separated list of project names applied to the managed lane. Default is “”.
-
ML_lanes
(Optional[int]
) –Default number of lanes on the managed lane. Default is None.
-
ML_price
(Optional[float]
) –Default price to use the managed lane. Default is 0.
-
ML_access
(Optional[Any]
) –User-defined method to note access restrictions for the managed lane. Default is None.
-
ML_access_point
(Optional[bool]
) –If the link is an access point for the managed lane. Default is False.
-
ML_egress_point
(Optional[bool]
) –If the link is an egress point for the managed lane. Default is False.
-
sc_ML_lanes
(Optional[list[dict]]
) –List of scoped link values for the number of lanes on the managed lane. Default is None.
-
sc_ML_price
(Optional[list[dict]]
) –List of scoped link values for the price of the managed lane. Default is None.
-
sc_ML_access
(Optional[list[dict]]
) –List of scoped link values for the access restrictions of the managed lane. Default is None.
-
ML_geometry
(Optional[GeoSeries]
) –Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Simple A→B geometry of the managed lane. Default is None.
-
ML_shape_id
(Optional[str]
) –Identifier referencing the primary key of the shapes table for the managed lane. Default is None.
-
osm_link_id
(Optional[str]
) –Identifier referencing the OSM link ID. Default is “”.
-
GP_A
(Optional[int]
) –Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Identifier referencing the primary key of the associated general purpose link start node for a managed lane link in a model network. Default is None.
-
GP_B
(Optional[int]
) –Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Identifier referencing the primary key of the associated general purpose link end node for a managed lane link in a model network. Default is None.
User Defined Properties
Additional properites may be defined and are assumed to have the same definition of OpenStreetMap if they have overlapping property names.
Properties for parallel managed lanes ¶
Properties for parallel managed lanes are prefixed with ML_
. (Almost) any property,
including an ad-hoc one, can be made to apply to a parallel managed lane by applying
the prefix ML_
, e.g. ML_lanes
Warning
The following properties should not be assigned an ML_
prefix by the user
because they are assigned one within networkwrangler:
name
A
B
model_link_id
Time- or category-dependent properties ¶
The following properties can be time-dependent, category-dependent, or both by adding sc_
.
The “plain” property without the prefix becomes the default when no scoped property applies.
Property | # of Lanes | Price |
---|---|---|
Default value | lanes |
price |
Time- and/or category-dependent value | sc_lanes |
sc_price |
Default value for managed lane | ML_lanes |
ML_price |
Time- and/or category-dependent value for managed lane | sc_ML_lanes |
sc_ML_price |
previous format for scoped properties
Some previous tooling was developed around a previous method for serializing scoped properties. In order to retain compatability with this format:
load_roadway_from_dir()
,read_links()
, and associated functions will “sniff” the network for the old format and apply the converter functiontranslate_links_df_v0_to_v1()
write_links()
has an boolean attribute toconvert_complex_properties_to_single_field
which can also be invoked fromwrite_roadway()
asconvert_complex_link_properties_to_single_field
.
Defining time-dependent properties ¶
Time-dependent properties are defined as a list of dictionaries with timespans and values.
- Timespans must be defined as a list of HH:MM or HH:MM:SS using a 24-hour clock:
('06:00':'09:00')
. - Timespans must not intersect.
Time-dependent property
$3 peak-period pricing
Defining time- and category-dependent properties ¶
Properties co-dependent on time- and category are defined as a list of dictionaries with value, category and time defined.
time- and category-dependent property
A pricing strategy which only applies in peak period for trucks and sovs:
Tip
There is no limit on other, user-defined properties being listed as time-dependent or time- and category-dependent.
User-defined variable by time of day
Define a variable access
to represent which categories can access the network and vary it by time of day.
Source code in network_wrangler/models/roadway/tables.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
network_wrangler.models.roadway.tables.RoadLinksTable.check_scoped_fields ¶
Checks that all fields starting with ‘sc_’ or ‘sc_ML_’ are valid ScopedLinkValueList.
Custom check to validate fields starting with ‘sc_’ or ‘sc_ML_’ against a ScopedLinkValueItem model, handling both mandatory and optional fields.
Source code in network_wrangler/models/roadway/tables.py
network_wrangler.models.roadway.tables.RoadNodesTable ¶
Bases: DataFrameModel
Datamodel used to validate if nodes_df is of correct format and types.
Must have a record for each node used by the links
table and by the transit shapes
, stop_times
, and stops
tables.
Attributes:
-
model_node_id
(int
) –Unique identifier for the node.
-
osm_node_id
(Optional[str]
) –Reference to open street map node id. Used for querying. Not guaranteed to be unique.
-
X
(float
) –Longitude of the node in WGS84. Must be in the range of -180 to 180.
-
Y
(float
) –Latitude of the node in WGS84. Must be in the range of -90 to 90.
-
geometry
(GeoSeries
) –Warning: this attribute is controlled by wrangler and should not be explicitly user-edited.
Source code in network_wrangler/models/roadway/tables.py
network_wrangler.models.roadway.tables.RoadShapesTable ¶
Bases: DataFrameModel
Datamodel used to validate if shapes_df is of correct format and types.
Should have a record for each shape_id
referenced in links
table.
Attributes:
-
shape_id
(str
) –Unique identifier for the shape.
-
geometry
(GeoSeries
) –Warning: this attribute is controlled by wrangler and should not be explicitly user-edited. Geometry of the shape.
-
ref_shape_id
(Optional[str]
) –Reference to another
shape_id
that it may have been created from. Default is None.
Source code in network_wrangler/models/roadway/tables.py
Complex roadway types defined using Pydantic models to facilitation validation.
network_wrangler.models.roadway.types.LocationReferences
module-attribute
¶
LocationReferences = conlist(LocationReference, min_length=2)
List of at least two LocationReferences which define a path.
network_wrangler.models.roadway.types.LocationReference ¶
Bases: BaseModel
SharedStreets-defined object for location reference.
Source code in network_wrangler/models/roadway/types.py
network_wrangler.models.roadway.types.ScopedLinkValueItem ¶
Bases: RecordModel
Define the value of a link property for a particular timespan or category.
Attributes:
-
`category`
(str
) –Category or link user that this scoped value applies to, ex:
HOV2
,truck
, etc. Categories are user-defined with the exception ofany
which is reserved as the default category. Default isDEFAULT_CATEGORY
, which isall
. -
`timespan`
(list[TimeString]
) –timespan of the link property as defined as a list of two HH:MM(:SS) strings. Default is
DEFAULT_TIMESPAN
, which is["00:00", "24:00"]
. -
`value`
(Union[float, int, str]
) –Value of the link property for the given category and timespan.
Conflicting or matching scopes are not allowed in a list of ScopedLinkValueItems:
matching
: a scope that could be applied for a given category/timespan combination. This includes the default scopes as well as scopes that are contained within the given category AND timespan combination.overlapping
: a scope that fully or partially overlaps a given category OR timespan combination. This includes the default scopes, allmatching
scopes and all scopes where at least one minute of timespan or one category overlap.conflicting
: a scope that is overlapping but not matching for a given category/timespan.
NOTE: Default scope values of category: any
and timespan:["00:00", "24:00"]
are not considered conflicting, but are applied to residual scopes.
Source code in network_wrangler/models/roadway/types.py
network_wrangler.models.roadway.types.ScopedLinkValueList ¶
Bases: RootListMixin
, RootModel
List of non-conflicting ScopedLinkValueItems.
Source code in network_wrangler/models/roadway/types.py
network_wrangler.models.roadway.types.ScopedLinkValueList.check_conflicting_scopes ¶
Check for conflicting scopes in the list.
Source code in network_wrangler/models/roadway/types.py
network_wrangler.models.roadway.types.ScopedLinkValueList.overlapping_timespans ¶
Identify overlapping timespans in the list.
Roadway Links ¶
Functions to read in and write out a RoadLinksTable.
network_wrangler.roadway.links.io.read_links ¶
read_links(filename, in_crs=LAT_LON_CRS, config=DefaultConfig, nodes_df=None, filter_to_nodes=False)
Reads links and returns a geodataframe of links conforming to RoadLinksTable.
Sets index to be a copy of the primary key. Validates output dataframe using RoadLinksTable
Parameters:
-
filename
(str
) –file to read links in from.
-
in_crs
(int
, default:LAT_LON_CRS
) –coordinate reference system number any link geometries are stored in. Defaults to 4323.
-
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig instance. Defaults to DefaultConfig.
-
nodes_df
(DataFrame[RoadNodesTable]
, default:None
) –a RoadNodesTable to gather geometry from. Necesary if geometry is not provided. Defaults to None.
-
filter_to_nodes
(bool
, default:False
) –if True, will filter links to only those that connect to nodes. Requires nodes_df to be provided. Defaults to False.
Source code in network_wrangler/roadway/links/io.py
network_wrangler.roadway.links.io.write_links ¶
write_links(links_df, out_dir='.', convert_complex_properties_to_single_field=False, prefix='', file_format='json', overwrite=False, include_geometry=False)
Writes links to a file.
Parameters:
-
links_df
(DataFrame[RoadLinksTable]
) –DataFrame[RoadLinksTable] to write out.
-
convert_complex_properties_to_single_field
(bool
, default:False
) –if True, will convert complex properties to a single column consistent with v0 format. This format is NOT valid with parquet and many other softwares. Defaults to False.
-
out_dir
(Union[str, Path]
, default:'.'
) –directory to write files to. Defaults to “.”.
-
prefix
(str
, default:''
) –prefix to add to the filename. Defaults to “”.
-
file_format
(GeoFileTypes
, default:'json'
) –file format to write out to. Defaults to “json”.
-
overwrite
(bool
, default:False
) –if True, will overwrite existing files. Defaults to False.
-
include_geometry
(bool
, default:False
) –if True, will include geometry in the output. Defaults to False.
Source code in network_wrangler/roadway/links/io.py
Functions for creating RoadLinksTables.
network_wrangler.roadway.links.create.copy_links ¶
copy_links(links_df, link_id_lookup, node_id_lookup, updated_geometry_col=None, nodes_df=None, offset_meters=-5, copy_properties=None, rename_properties=None, name_prefix='copy of', validate=True)
Copy links and optionally offset them.
Will get geometry from another column if provided, otherwise will use nodes_df and then offset_meters to offset from previous geometry.
Parameters:
-
links_df
(DataFrame[RoadLinksTable]
) –links dataframe of links to copy
-
link_id_lookup
(dict[int, int]
) –lookup of new link ID from old link id.
-
node_id_lookup
(dict[int, int]
) –lookup of new node ID from old node id.
-
updated_geometry_col
(str
, default:None
) –name of the column to store the updated geometry. Will nodes_df for missing geometries if provided and offset_meters if not. Defaults to None.
-
nodes_df
(DataFrame[RoadNodesTable]
, default:None
) –nodes dataframe of nodes to use for new link geometry. Defaults to None. If not provided, will use offset_meters.
-
offset_meters
(float
, default:-5
) –distance to offset links if nodes_df is not provided. Defaults to -5.
-
copy_properties
(list[str]
, default:None
) –properties to keep. Defaults to [].
-
rename_properties
(dict[str, str]
, default:None
) –properties to rename. Defaults to {}. Will default to REQUIRED_RENAMES if keys in that dict are not provided.
-
name_prefix
(str
, default:'copy of'
) –format string for new names. Defaults to “copy of”.
-
validate
(bool
, default:True
) –whether to validate the output dataframe. Defaults to True. If set to false, you should validate the output dataframe before using it.
Returns:
-
DataFrame[RoadLinksTable]
–DataFrame[RoadLinksTable]: offset links dataframe
Source code in network_wrangler/roadway/links/create.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
network_wrangler.roadway.links.create.data_to_links_df ¶
Create a links dataframe from list of link properties + link geometries or associated nodes.
Sets index to be a copy of the primary key. Validates output dataframe using LinksSchema.
Parameters:
-
links_df
(DataFrame
) –df or list of dictionaries of link properties
-
in_crs
(int
, default:LAT_LON_CRS
) –coordinate reference system id for incoming links if geometry already exists. Defaults to LAT_LON_CRS. Will convert everything to LAT_LON_CRSif it doesn’t match.
-
nodes_df
(Union[None, DataFrame[RoadNodesTable]]
, default:None
) –Associated notes geodataframe to use if geometries or location references not present. Defaults to None.
Returns:
-
DataFrame[RoadLinksTable]
–pd.DataFrame: description
Source code in network_wrangler/roadway/links/create.py
network_wrangler.roadway.links.create.shape_id_from_link_geometry ¶
Create a unique shape_id from the geometry of the link.
Deletes links from RoadLinksTable.
network_wrangler.roadway.links.delete.check_deletion_breaks_transit_shapes ¶
Check if any transit shapes go on the deleted links.
Parameters:
-
links_df
(DataFrame[RoadLinksTable]
) –DataFrame[RoadLinksTable] to delete links from.
-
del_link_ids
(list[int]
) –list of link ids to delete.
-
transit_net
(TransitNetwork
) –input TransitNetwork
Source code in network_wrangler/roadway/links/delete.py
network_wrangler.roadway.links.delete.delete_links_by_ids ¶
Delete links from a links table.
Parameters:
-
links_df
(DataFrame[RoadLinksTable]
) –DataFrame[RoadLinksTable] to delete links from.
-
del_link_ids
(list[int]
) –list of link ids to delete.
-
ignore_missing
(bool
, default:False
) –if True, will not raise an error if a link id to delete is not in the network. Defaults to False.
-
transit_net
(Optional[TransitNetwork]
, default:None
) –If provided, will check TransitNetwork and warn if deletion breaks transit shapes. Defaults to None.
Source code in network_wrangler/roadway/links/delete.py
Edits RoadLinksTable properties.
NOTE: Each public method will return a new, whole copy of the RoadLinksTable with associated edits. Private methods may return mutated originals.
Usage:
# Returns copy of links_df with lanes set to 2 for links in link_idx
links_df = edit_link_property(links_df, link_idx, "lanes", {"set": 2})
# Returns copy of links_df with price reduced by 50 for links in link_idx and raises error
# if existing value doesn't match 100
links_df = edit_link_properties(
links_df,
link_idx,
"price",
{"existing": 100, "change": -50},
)
# Returns copy of links_df with geometry of links with node_ids updated based on nodes_df
links_df = edit_link_geometry_from_nodes(links_df, nodes_df, node_ids)
network_wrangler.roadway.links.edit.edit_link_geometry_from_nodes ¶
Returns a copy of links with updated geometry for given links for a given list of nodes.
Should be called by any function that changes a node location.
Parameters:
-
links_df
(DataFrame[RoadLinksTable]
) –RoadLinksTable to update
-
nodes_df
(DataFrame[RoadNodesTable]
) –RoadNodesTable to get updated node geometry from
-
node_ids
(list[int]
) –list of node PKs with updated geometry
Source code in network_wrangler/roadway/links/edit.py
network_wrangler.roadway.links.edit.edit_link_properties ¶
Return copy of RoadLinksTable with edited link properties for a list of links.
Parameters:
-
links_df
(DataFrame[RoadLinksTable]
) –links to edit
-
link_idx
(list
) –list of link indices to change
-
property_changes
(dict[str, dict]
) –dictionary of property changes
-
project_name
(Optional[str]
, default:None
) –optional name of the project to be applied
-
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig instance. Defaults to DefaultConfig.
Source code in network_wrangler/roadway/links/edit.py
Functions to filter a RoadLinksTable based on various properties.
network_wrangler.roadway.links.filters.filter_link_properties_managed_lanes ¶
Filters links dataframe to only include managed lanes.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_access_dummy ¶
Filters links dataframe to only include all access dummy links connecting managed lanes.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_centroid_connector ¶
Filters links dataframe to only include all general purpose links.
network_wrangler.roadway.links.filters.filter_links_drive_access ¶
Filters links dataframe to only include all links that vehicles can operate on.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_dummy ¶
Filters links dataframe to only include all dummy links connecting managed lanes.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_egress_dummy ¶
Filters links dataframe to only include all egress dummy links connecting managed lanes.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_general_purpose ¶
Filters links dataframe to only include all general purpose links.
NOTE: This will only return links without parallel managed lanes in a non-model-ready network.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_general_purpose_no_parallel_managed ¶
Filters links df to only include general purpose links without parallel managed lanes.
NOTE: This will only return links without parallel managed lanes in a non-model-ready network.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_managed_lanes ¶
Filters links dataframe to only include managed lanes.
network_wrangler.roadway.links.filters.filter_links_not_in_ids ¶
Filters links dataframe to NOT have link_ids.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_parallel_general_purpose ¶
Filters links dataframe to only include general purpose links parallel to managed.
NOTE This will return Null when not a model network.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_pedbike_only ¶
Filters links dataframe to only include links that only ped/bikes can be on.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_to_ids ¶
Filters links dataframe by link_ids.
network_wrangler.roadway.links.filters.filter_links_to_ml_access_points ¶
Filters links dataframe to only include all managed lane access points.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_to_ml_egress_points ¶
Filters links dataframe to only include all managed lane egress points.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_to_modes ¶
Filters links dataframe to only include links that are accessible by the modes in the list.
Parameters:
-
links_df
(RoadLinksTable
) –links dataframe
-
modes
(List[str]
) –list of modes to filter by.
Returns:
-
RoadLinksTable
(DataFrame[RoadLinksTable]
) –filtered links dataframe
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_to_node_ids ¶
Filters links dataframe to only include links with either A or B in node_ids.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_to_path ¶
Return selection of links dataframe with nodes along path defined by node_id_path_list.
Parameters:
-
links_df
(DataFrame[RoadLinksTable]
) –Links dataframe to select from
-
node_id_path_list
(list[int]
) –List of node ids.
-
ignore_missing
(bool
, default:False
) –if True, will ignore if links noted by path node sequence don’t exist in links_df and will just return what does exist. Defaults to False.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_transit_access ¶
Filters links dataframe to only include all links that transit can operate on.
Source code in network_wrangler/roadway/links/filters.py
network_wrangler.roadway.links.filters.filter_links_transit_only ¶
Filters links dataframe to only include all links that only transit can operate on.
Source code in network_wrangler/roadway/links/filters.py
Functions for updating roadway links with geometry from shapes.
network_wrangler.roadway.links.geo.true_shape ¶
Updates geometry to have shape of shapes_df where available.
Source code in network_wrangler/roadway/links/geo.py
Utilities for filtering and querying scoped properties based on scoping dimensions.
This module provides various utility functions for filtering and querying scoped properties based on scoping dimensions such as category and timespan. It includes functions for filtering scoped values based on non-overlapping or overlapping timespans, non-overlapping or overlapping categories, and matching exact category and timespan. It also includes functions for creating exploded dataframes for scoped properties and filtering them based on scope.
Public Functions: - prop_for_scope: Creates a dataframe with the value of a property for a given category and timespan. Can return maximum overlapping timespan value given a minimum number of overlapping minutes, or strictly enforce timespans.
Internal function terminology for scopes:
matching
scope value: a scope that could be applied for a given category/timespan combination. This includes the default scopes as well as scopes that are contained within the given category AND timespan combination.overlapping
scope value: a scope that fully or partially overlaps a given category OR timespan combination. This includes the default scopes, allmatching
scopes and all scopes where at lest one minute of timespan or one category overlap.conflicting
scope value: a scope that is overlapping but not matching for a given category/ timespan. By definition default scope values are not conflicting.independent
scope value: a scope value that is not overlapping.
Usage:
network_wrangler.roadway.links.scopes.prop_for_scope ¶
prop_for_scope(links_df, prop_name, timespan=DEFAULT_TIMESPAN, category=DEFAULT_CATEGORY, strict_timespan_match=False, min_overlap_minutes=60, allow_default=True)
Creates a df with the value of a property for a given category and timespan.
Parameters:
-
links_df
(DataFrame[RoadLinksTable]
) –(RoadLinksTable
-
prop_name
(str
) –name of property to query
-
timespan
(Union[None, list[TimeString]]
, default:DEFAULT_TIMESPAN
) –TimespanString of format [‘HH:MM’,’HH:MM’] to query orig_df for overlapping records.
-
category
(Union[str, int, None]
, default:DEFAULT_CATEGORY
) –category to query orig_df for overlapping records. Defaults to None.
-
strict_timespan_match
(bool
, default:False
) –boolean indicating if the returned df should only contain records that fully contain the query timespan. If set to True, min_overlap_minutes does not apply. Defaults to False.
-
min_overlap_minutes
(int
, default:60
) –minimum number of minutes the timespans need to overlap to keep. Defaults to 0.
-
allow_default
(bool
, default:True
) –boolean indicating if the default value should be returned if no scoped values are found. Defaults to True.
Returns:
-
DataFrame
–pd.DataFrame with
model_link_id
andprop_name
Source code in network_wrangler/roadway/links/scopes.py
Utilities for summarizing a RoadLinksTable.
network_wrangler.roadway.links.summary.link_summary ¶
Summarizes links by link_summary_cats
: count, distance, and lane miles.
Source code in network_wrangler/roadway/links/summary.py
network_wrangler.roadway.links.summary.link_summary_cnt ¶
Dictionary of number of links by link_summary_cats
.
network_wrangler.roadway.links.summary.link_summary_lane_miles ¶
Dictionary of lane miles by link_summary_cats
.
network_wrangler.roadway.links.summary.link_summary_miles ¶
Dictionary of miles by link_summary_cats
.
Utilities for validating a RoadLinksTable beyond its data model.
network_wrangler.roadway.links.validate.validate_links_df ¶
Validates a links df to RoadLinksTable and optionally checks if nodes are in the links.
Parameters:
-
links_df
(DataFrame
) –The links dataframe.
-
nodes_df
(DataFrame
, default:None
) –The nodes dataframe. Defaults to None.
-
strict
(bool
, default:False
) –If True, will validate to links_df without trying to parse it first.
-
errors_filename
(Path
, default:Path('link_errors.csv')
) –The output file for the validation errors. Defaults to “link_errors.csv”.
Returns:
-
bool
(bool
) –True if the links dataframe is valid.
Source code in network_wrangler/roadway/links/validate.py
network_wrangler.roadway.links.validate.validate_links_file ¶
validate_links_file(links_filename, nodes_df=None, strict=False, errors_filename=Path('link_errors.csv'))
Validates a links file to RoadLinksTable and optionally checks if nodes are in the links.
Parameters:
-
links_filename
(Path
) –The links file.
-
nodes_df
(DataFrame
, default:None
) –The nodes dataframe. Defaults to None.
-
strict
(bool
, default:False
) –If True, will validate to links_df without trying to parse it first.
-
errors_filename
(Path
, default:Path('link_errors.csv')
) –The output file for the validation errors. Defaults to “link_errors.csv”.
Returns:
-
bool
(bool
) –True if the links file is valid.
Source code in network_wrangler/roadway/links/validate.py
network_wrangler.roadway.links.validate.validate_links_have_nodes ¶
Checks if links have nodes and returns a boolean.
raises: NodesInLinksMissingError if nodes_df is missing and A or B node
Source code in network_wrangler/roadway/links/validate.py
Dataframe accessor shortcuts for RoadLinksTables allowing for easy filtering and editing.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor ¶
Wrapper for various filters of RoadLinksTable.
Methods:
-
links_df.of_type.managed
–filters links dataframe to only include managed lanes.
-
links_df.of_type.parallel_general_purpose
–filters links dataframe to only include general purpose links parallel to managed.
-
links_df.of_type.general_purpose
–filters links dataframe to only include all general purpose links.
-
links_df.of_type.general_purpose_no_parallel_managed
–filters links dataframe to only include general purpose links without parallel managed lanes.
-
links_df.of_type.access_dummy
–filters links dataframe to only include all access dummy links connecting managed lanes.
-
links_df.of_type.egress_dummy
–filters links dataframe to only include all egress dummy links connecting managed lanes.
-
links_df.of_type.dummy
–filters links dataframe to only include all dummy links connecting managed lanes.
-
links_df.of_type.pedbike_only
–filters links dataframe to only include all links that only ped/bikes can be on.
-
links_df.of_type.transit_only
–filters links dataframe to only include all links that only transit can be on.
-
links_df.of_type.transit_access
–filters links dataframe to only include all links that transit can access.
-
links_df.of_type.drive_access
–filters links dataframe to only include all links that drive can access.
-
links_df.of_type.summary_df
–returns a summary of the links dataframe.
Source code in network_wrangler/roadway/links/df_accessors.py
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.access_dummy
property
¶
Filters links dataframe to access dummy links connecting managed lanes.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.drive_access
property
¶
Filters links dataframe to only include all links that drive can access.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.dummy
property
¶
Filters links dataframe to dummy links connecting managed lanes.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.egress_dummy
property
¶
Filters links dataframe to egress dummy links connecting managed lanes.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.general_purpose
property
¶
Filters links dataframe to only include general purpose links.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.general_purpose_no_parallel_managed
property
¶
Filters links general purpose links without parallel managed lanes.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.managed
property
¶
Filters links dataframe to only include managed lanes.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.parallel_general_purpose
property
¶
Filters links dataframe to general purpose links parallel to managed lanes.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.pedbike_only
property
¶
Filters links dataframe to links that only ped/bikes can be on.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.summary_df
property
¶
Returns a summary of the links dataframe.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.transit_access
property
¶
Filters links dataframe to all links that transit can access.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.transit_only
property
¶
Filters links dataframe to links that only transit can be on.
network_wrangler.roadway.links.df_accessors.LinkOfTypeAccessor.__init__ ¶
LinkOfTypeAccessor for RoadLinksTable.
Source code in network_wrangler/roadway/links/df_accessors.py
network_wrangler.roadway.links.df_accessors.ModeLinkAccessor ¶
Wrapper for filtering RoadLinksTable by modal ability: : links_df.mode_query(modes_list).
Parameters:
-
modes
(list[str]
) –list of modes to filter by.
Source code in network_wrangler/roadway/links/df_accessors.py
network_wrangler.roadway.links.df_accessors.ModeLinkAccessor.__call__ ¶
Filters links dataframe to links that are accessible by the modes in the list.
network_wrangler.roadway.links.df_accessors.ModeLinkAccessor.__init__ ¶
ModeLinkAccessor for RoadLinksTable.
Source code in network_wrangler/roadway/links/df_accessors.py
network_wrangler.roadway.links.df_accessors.TrueShapeAccessor ¶
Wrapper for returning a gdf with true_shapes: links_df.true_shape(shapes_df).
Source code in network_wrangler/roadway/links/df_accessors.py
network_wrangler.roadway.links.df_accessors.TrueShapeAccessor.__call__ ¶
Updates geometry to have shape of shapes_df where available.
network_wrangler.roadway.links.df_accessors.TrueShapeAccessor.__init__ ¶
TrueShapeAccessor for RoadLinksTable.
Source code in network_wrangler/roadway/links/df_accessors.py
Roadway Nodes ¶
Functions for reading and writing nodes data.
network_wrangler.roadway.nodes.io.get_nodes ¶
Get nodes from a transit network, roadway network, or roadway file.
Parameters:
-
transit_net
(Optional[TransitNetwork]
, default:None
) –TransitNetwork instance
-
roadway_net
(Optional[RoadwayNetwork]
, default:None
) –RoadwayNetwork instance
-
roadway_path
(Optional[Union[str, Path]]
, default:None
) –path to a directory with roadway network
-
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig instance. Defaults to DefaultConfig.
Source code in network_wrangler/roadway/nodes/io.py
network_wrangler.roadway.nodes.io.nodes_df_to_geojson ¶
Converts a nodes dataframe to a geojson.
Attribution: Geoff Boeing: https://geoffboeing.com/2015/10/exporting-python-data-geojson/.
Source code in network_wrangler/roadway/nodes/io.py
network_wrangler.roadway.nodes.io.read_nodes ¶
read_nodes(filename, in_crs=LAT_LON_CRS, boundary_gdf=None, boundary_geocode=None, boundary_file=None, config=DefaultConfig)
Reads nodes and returns a geodataframe of nodes.
Sets index to be a copy of the primary key. Validates output dataframe using NodesSchema.
Parameters:
-
filename
((Path, str)
) –file to read links in from.
-
in_crs
(int
, default:LAT_LON_CRS
) –coordinate reference system number that node data is in. Defaults to LAT_LON_CRS.
-
boundary_gdf
(Optional[GeoDataFrame]
, default:None
) –GeoDataFrame to filter the input data to. Only used for geographic data. efaults to None.
-
boundary_geocode
(Optional[str]
, default:None
) –Geocode to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_file
(Optional[Path]
, default:None
) –File to load as a boundary to filter the input data to. Only used for geographic data. Defaults to None.
-
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig instance. Defaults to DefaultConfig.
Source code in network_wrangler/roadway/nodes/io.py
network_wrangler.roadway.nodes.io.write_nodes ¶
Writes RoadNodesTable to file.
Parameters:
-
nodes_df
(DataFrame[RoadNodesTable]
) –nodes dataframe
-
out_dir
(Union[str, Path]
) –directory to write nodes to
-
prefix
(str
) –prefix to add to nodes file name
-
file_format
(GeoFileTypes
, default:'geojson'
) –format to write nodes in. e.g. “geojson” shp” “parquet” “csv” “txt”. Defaults to “geojson”.
-
overwrite
(bool
, default:True
) –whether to overwrite existing nodes file. Defaults to True.
Source code in network_wrangler/roadway/nodes/io.py
Functions for creating nodes from data sources.
network_wrangler.roadway.nodes.create.data_to_nodes_df ¶
Turn nodes data into official nodes dataframe.
Adds missing geometry. Makes sure X and Y are consistent with geometry GeoSeries. Converts to LAT_LON_CRS. Copies and sets idx to primary_key. Validates output to NodesSchema.
Parameters:
-
nodes_df
–Nodes dataframe or list of dictionaries that can be converted to a dataframe.
-
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig instance. Defaults to DefaultConfig. NOTE: Not currently used.
-
in_crs
(int
, default:LAT_LON_CRS
) –Coordinate references system id incoming data xy is in, if it isn’t already in a GeoDataFrame. Defaults to LAT_LON_CRS.
Returns:
-
DataFrame[RoadNodesTable]
–gpd.GeoDataFrame: description
Source code in network_wrangler/roadway/nodes/create.py
network_wrangler.roadway.nodes.create.generate_node_ids ¶
Generate unique node ids for nodes_df.
Parameters:
-
nodes_df
(DataFrame[RoadNodesTable]
) –nodes dataframe to generate unique ids for.
-
range
(tuple[int]
) –range of ids to generate from.
-
n
(int
) –number of ids to generate.
Returns:
-
list[int]
–list[int]: list of unique node ids.
Source code in network_wrangler/roadway/nodes/create.py
Functions for deleting nodes from a nodes table.
network_wrangler.roadway.nodes.delete.delete_nodes_by_ids ¶
Delete nodes from a nodes table.
Parameters:
-
nodes_df
(DataFrame[RoadNodesTable]
) –DataFrame[RoadNodesTable] to delete nodes from.
-
del_node_ids
(list[int]
) –list of node ids to delete.
-
ignore_missing
(bool
, default:False
) –if True, will not raise an error if a node id to delete is not in the network. Defaults to False.
Source code in network_wrangler/roadway/nodes/delete.py
Edits RoadNodesTable properties.
NOTE: Each public method will return a new, whole copy of the RoadNodesTable with associated edits. Private methods may return mutated originals.
network_wrangler.roadway.nodes.edit.NodeGeometryChange ¶
Bases: RecordModel
Value for setting node geometry given a model_node_id.
Source code in network_wrangler/roadway/nodes/edit.py
network_wrangler.roadway.nodes.edit.NodeGeometryChangeTable ¶
Bases: DataFrameModel
DataFrameModel for setting node geometry given a model_node_id.
Source code in network_wrangler/roadway/nodes/edit.py
network_wrangler.roadway.nodes.edit.edit_node_geometry ¶
Returns copied nodes table with geometry edited.
Should be called from network so that accompanying links and shapes are also updated.
Parameters:
-
nodes_df
(DataFrame[RoadNodesTable]
) –RoadNodesTable to edit
-
node_geometry_change_table
(DataFrame[NodeGeometryChangeTable]
) –NodeGeometryChangeTable with geometry changes
Source code in network_wrangler/roadway/nodes/edit.py
network_wrangler.roadway.nodes.edit.edit_node_property ¶
edit_node_property(nodes_df, node_idx, prop_name, prop_change, project_name=None, config=DefaultConfig, _geometry_ok=False)
Return copied nodes table with node property edited.
Parameters:
-
nodes_df
(DataFrame[RoadNodesTable]
) –RoadNodesTable to edit
-
node_idx
(list[int]
) –list of node indices to change
-
prop_name
(str
) –property name to change
-
prop_change
(Union[dict, RoadPropertyChange]
) –dictionary of value from project_card
-
project_name
(Optional[str]
, default:None
) –optional name of the project to be applied
-
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig instance.
-
_geometry_ok
(bool
, default:False
) –if False, will not let you change geometry-related fields. Should only be changed to True by internal processes that know that geometry is changing and will update it in appropriate places in network. Defaults to False. GENERALLY DO NOT TURN THIS ON.
Source code in network_wrangler/roadway/nodes/edit.py
Functions to filter nodes dataframe.
network_wrangler.roadway.nodes.filters.filter_nodes_to_ids ¶
Filters nodes dataframe by node_ids.
Parameters:
-
nodes_df
(DataFrame
) –nodes dataframe
-
node_ids
(List[int]
) –list of node_ids to filter by.
Returns:
-
DataFrame[RoadNodesTable]
–pd.DataFrame: filtered nodes dataframe
Source code in network_wrangler/roadway/nodes/filters.py
network_wrangler.roadway.nodes.filters.filter_nodes_to_link_ids ¶
Filters nodes dataframe to those used by given link_ids.
Parameters:
-
link_ids
(List[int]
) –list of link_ids
-
links_df
(RoadLinksTable
) –links dataframe
-
nodes_df
(RoadNodesTable
, default:None
) –nodes dataframe
Returns:
-
DataFrame[RoadNodesTable]
–pd.DataFrame: nodes dataframe
Source code in network_wrangler/roadway/nodes/filters.py
network_wrangler.roadway.nodes.filters.filter_nodes_to_links ¶
Filters RoadNodesTable to those used by given links dataframe.
Parameters:
-
links_df
(RoadLinksTable
) –links dataframe
-
nodes_df
(RoadNodesTable
) –nodes dataframe
Source code in network_wrangler/roadway/nodes/filters.py
Roadway Shapes ¶
Functions to read and write RoadShapesTable.
network_wrangler.roadway.shapes.io.read_shapes ¶
read_shapes(filename, in_crs=LAT_LON_CRS, boundary_gdf=None, boundary_geocode=None, boundary_file=None, filter_to_shape_ids=None, config=DefaultConfig)
Reads shapes and returns a geodataframe of shapes if filename is found.
Otherwise, returns empty GeoDataFrame conforming to ShapesSchema.
Sets index to be a copy of the primary key. Validates output dataframe using ShapesSchema.
Parameters:
-
filename
(str
) –file to read shapes in from.
-
in_crs
(int
, default:LAT_LON_CRS
) –coordinate reference system number file is in. Defaults to LAT_LON_CRS.
-
boundary_gdf
(Optional[GeoDataFrame]
, default:None
) –GeoDataFrame to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_geocode
(Optional[str]
, default:None
) –Geocode to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_file
(Optional[Path]
, default:None
) –File to load as a boundary to filter the input data to. Only used for geographic data. Defaults to None.
-
filter_to_shape_ids
(Optional[list]
, default:None
) –List of shape_ids to filter the input data to. Defaults to None.
-
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig instance. Defaults to DefaultConfig.
Source code in network_wrangler/roadway/shapes/io.py
network_wrangler.roadway.shapes.io.write_shapes ¶
Writes shapes to file.
Parameters:
-
shapes_df
(DataFrame[RoadShapesTable]
) –DataFrame of shapes to write.
-
out_dir
(Union[str, Path]
) –directory to write shapes to.
-
prefix
(str
) –prefix to add to file name.
-
format
(str
) –format to write shapes in.
-
overwrite
(bool
) –whether to overwrite file if it exists.
Source code in network_wrangler/roadway/shapes/io.py
Functions to create RoadShapesTable from various data.
network_wrangler.roadway.shapes.create.add_offset_shapes ¶
add_offset_shapes(shapes_df, shape_ids, offset_dist_meters=10, id_scalar=DefaultConfig.IDS.ROAD_SHAPE_ID_SCALAR)
Appends a RoadShapesTable with new shape records for shape_ids which are offset from orig.
Parameters:
-
shapes_df
(RoadShapesTable
) –Original RoadShapesTable to add on to.
-
shape_ids
(list
) –Shape_ids to create offsets for.
-
offset_dist_meters
(float
, default:10
) –Distance in meters to offset by. Defaults to 10.
-
id_scalar
(int
, default:ROAD_SHAPE_ID_SCALAR
) –Increment to add to shape_id. Defaults to SHAPE_ID_SCALAR.
Returns:
-
RoadShapesTable
(DataFrame[RoadShapesTable]
) –with added offset shape_ids and a column
ref_shape_id
which references the shape_id which was offset to create it.
Source code in network_wrangler/roadway/shapes/create.py
network_wrangler.roadway.shapes.create.create_offset_shapes ¶
create_offset_shapes(shapes_df, shape_ids, offset_dist_meters=10, id_scalar=DefaultConfig.IDS.ROAD_SHAPE_ID_SCALAR)
Create a RoadShapesTable of new shape records for shape_ids which are offset.
Parameters:
-
shapes_df
(RoadShapesTable
) –Original RoadShapesTable to add on to.
-
shape_ids
(list
) –Shape_ids to create offsets for.
-
offset_dist_meters
(float
, default:10
) –Distance in meters to offset by. Defaults to 10.
-
id_scalar
(int
, default:ROAD_SHAPE_ID_SCALAR
) –Increment to add to shape_id. Defaults to ROAD_SHAPE_ID_SCALAR.
Returns:
-
RoadShapesTable
(DataFrame[RoadShapesTable]
) –of offset shapes and a column
ref_shape_id
which references the shape_id which was offset to create it.
Source code in network_wrangler/roadway/shapes/create.py
network_wrangler.roadway.shapes.create.df_to_shapes_df ¶
Sets index to be a copy of the primary key, validates to RoadShapesTable and aligns CRS.
Parameters:
-
shapes_df
(GeoDataFrame
) –description
-
in_crs
(int
, default:LAT_LON_CRS
) –coordinate reference system number of incoming df. ONLY used if shapes_df is not already set. Defaults to LAT_LON_CRS.
-
config
(WranglerConfig
, default:DefaultConfig
) –WranglerConfig instance. Defaults to DefaultConfig. NOTE: Not currently used.
Returns:
-
DataFrame[RoadShapesTable]
–DataFrame[RoadShapesTable]
Source code in network_wrangler/roadway/shapes/create.py
Edits RoadShapesTable properties.
NOTE: Each public method will return a whole copy of the RoadShapesTable with associated edits. Private methods may return mutated originals.
network_wrangler.roadway.shapes.edit.edit_shape_geometry_from_nodes ¶
Updates the geometry for shapes for a given list of nodes.
Should be called by any function that changes a node location.
This will mutate the geometry of a shape in place for the start and end node
Parameters:
-
shapes_df
(DataFrame[RoadShapesTable]
) –RoadShapesTable
-
links_df
(DataFrame[RoadLinksTable]
) –RoadLinksTable
-
nodes_df
(DataFrame[RoadNodesTable]
) –RoadNodesTable
-
node_ids
(list[int]
) –list of node PKs with updated geometry
Source code in network_wrangler/roadway/shapes/edit.py
Functions to delete shapes from RoadShapesTable.
network_wrangler.roadway.shapes.delete.delete_shapes_by_ids ¶
Deletes shapes from shapes_df by shape_id.
Parameters:
-
shapes_df
(DataFrame[RoadShapesTable]
) –RoadShapesTable
-
del_shape_ids
(list[int]
) –list of shape_ids to delete
-
ignore_missing
(bool
, default:False
) –if True, will not raise an error if shape_id is not found in shapes_df
Returns:
-
DataFrame[RoadShapesTable]
–DataFrame[RoadShapesTable]: a copy of shapes_df with shapes removed
Source code in network_wrangler/roadway/shapes/delete.py
Helpter functions which filter a RoadShapesTable.
network_wrangler.roadway.shapes.filters.filter_shapes_to_links ¶
Shapes which are referenced in RoadLinksTable.
Source code in network_wrangler/roadway/shapes/filters.py
Functions that query RoadShapesTable.
network_wrangler.roadway.shapes.shapes.shape_ids_without_links ¶
List of shape ids that don’t have associated links.
Source code in network_wrangler/roadway/shapes/shapes.py
Roadway Projects ¶
Functions for applying roadway link or node addition project cards to the roadway network.
network_wrangler.roadway.projects.add.apply_new_roadway ¶
Add the new roadway features defined in the project card.
New nodes are added first so that links can refer to any added nodes.
Parameters:
-
roadway_net
(RoadwayNetwork
) –input RoadwayNetwork to apply change to
-
roadway_addition
(dict
) –dictionary conforming to RoadwayAddition model such as:
-
project_name
(Optional[str]
, default:None
) –optional name of the project to be applied
Source code in network_wrangler/roadway/projects/add.py
Wrapper function for applying code to change roadway network.
network_wrangler.roadway.projects.calculate.apply_calculated_roadway ¶
Changes roadway network object by executing pycode.
Parameters:
-
roadway_net
(RoadwayNetwork
) –network to manipulate
-
pycode
(str
) –python code which changes values in the roadway network object
Source code in network_wrangler/roadway/projects/calculate.py
Wrapper function for applying roadway deletion project card to RoadwayNetwork.
network_wrangler.roadway.projects.delete.apply_roadway_deletion ¶
Delete the roadway links or nodes defined in the project card.
If deleting links and specified in RoadwayDeletion, will also clean up the shapes and nodes used by links. Defaults to not cleaning up shapes or nodes.
Parameters:
-
roadway_net
(RoadwayNetwork
) –input RoadwayNetwork to apply change to
-
roadway_deletion
(Union[dict, RoadwayDeletion]
) –dictionary conforming to RoadwayDeletion
-
transit_net
(Optional[TransitNetwork]
, default:None
) –input TransitNetwork which will be used to check if deletion breaks transit shapes. If None, will not check for broken shapes.
Source code in network_wrangler/roadway/projects/delete.py
Functions for applying roadway property change project cards to the roadway network.
network_wrangler.roadway.projects.edit_property.apply_roadway_property_change ¶
Changes roadway properties for the selected features based on the project card.
Parameters:
-
roadway_net
(RoadwayNetwork
) –input RoadwayNetwork to apply change to
-
selection
–roadway selection object
-
property_changes
– -
project_name
(Optional[str]
, default:None
) –optional name of the project to be applied
Source code in network_wrangler/roadway/projects/edit_property.py
Roadway Supporting Modules ¶
Functions for reading and writing roadway networks.
network_wrangler.roadway.io.convert_roadway_file_serialization ¶
convert_roadway_file_serialization(in_path, in_format='geojson', out_dir=Path(), out_format='parquet', out_prefix='', overwrite=True, boundary_gdf=None, boundary_geocode=None, boundary_file=None, chunk_size=None)
Converts a files in a roadway from one serialization format to another without parsing.
Does not do any validation.
Parameters:
-
in_path
(Path
) –the path to the input directory.
-
in_format
(RoadwayFileTypes
, default:'geojson'
) –the file formatof the input files. Defaults to “geojson”.
-
out_dir
(Path
, default:Path()
) –the path were the output will be saved.
-
out_format
(RoadwayFileTypes
, default:'parquet'
) –the format of the output files. Defaults to “parquet”.
-
out_prefix
(str
, default:''
) –the name prefix of the roadway files that will be generated. Defaults to “”.
-
overwrite
(bool
, default:True
) –if True, will overwrite the files if they already exist. Defaults to True.
-
boundary_gdf
(Optional[GeoDataFrame]
, default:None
) –GeoDataFrame to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_geocode
(Optional[str]
, default:None
) –Geocode to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_file
(Optional[Path]
, default:None
) –File to load as a boundary to filter the input data to. Only used for geographic data. Defaults to None.
-
chunk_size
(Optional[int]
, default:None
) –Size of chunk to process if want to force chunking. Defaults to None. Chunking will only apply to converting from json to parquet files.
Source code in network_wrangler/roadway/io.py
network_wrangler.roadway.io.convert_roadway_network_serialization ¶
convert_roadway_network_serialization(input_path, output_format='geojson', out_dir='.', input_file_format='geojson', out_prefix='', overwrite=True, boundary_gdf=None, boundary_geocode=None, boundary_file=None, filter_links_to_nodes=False)
Converts a roadway network from one serialization format to another with parsing.
Performs validation and parsing.
Parameters:
-
input_path
(Union[str, Path]
) –the path to the input directory.
-
output_format
(RoadwayFileTypes
, default:'geojson'
) –the format of the output files. Defaults to “geojson”.
-
out_dir
(Union[str, Path]
, default:'.'
) –the path were the output will be saved.
-
input_file_format
(RoadwayFileTypes
, default:'geojson'
) –the format of the input files. Defaults to “geojson”.
-
out_prefix
(str
, default:''
) –the name prefix of the roadway files that will be generated. Defaults to “”.
-
overwrite
(bool
, default:True
) –if True, will overwrite the files if they already exist. Defaults to True.
-
boundary_gdf
(Optional[GeoDataFrame]
, default:None
) –GeoDataFrame to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_geocode
(Optional[str]
, default:None
) –Geocode to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_file
(Optional[Path]
, default:None
) –File to load as a boundary to filter the input data to. Only used for geographic data. Defaults to None.
-
filter_links_to_nodes
(bool
, default:False
) –if True, will filter the links to only those that have nodes. Defaults to False unless boundary_gdf, boundary_geocode, or boundary_file are provided.
Source code in network_wrangler/roadway/io.py
network_wrangler.roadway.io.id_roadway_file_paths_in_dir ¶
Identifies the paths to the links, nodes, and shapes files in a directory.
Source code in network_wrangler/roadway/io.py
network_wrangler.roadway.io.load_roadway ¶
load_roadway(links_file, nodes_file, shapes_file=None, in_crs=LAT_LON_CRS, read_in_shapes=False, boundary_gdf=None, boundary_geocode=None, boundary_file=None, filter_links_to_nodes=None, config=DefaultConfig)
Reads a network from the roadway network standard.
Validates that it conforms to the schema.
Parameters:
-
links_file
(Path
) –full path to the link file
-
nodes_file
(Path
) –full path to the node file
-
shapes_file
(Optional[Path]
, default:None
) –full path to the shape file. NOTE if not found, it will defaul to None and not raise an error.
-
in_crs
(int
, default:LAT_LON_CRS
) –coordinate reference system that network is in. Defaults to LAT_LON_CRS which defaults to 4326 which is WGS84 lat/long.
-
read_in_shapes
(bool
, default:False
) –if True, will read shapes into network instead of only lazily reading them when they are called. Defaults to False.
-
boundary_gdf
(Optional[GeoDataFrame]
, default:None
) –GeoDataFrame to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_geocode
(Optional[str]
, default:None
) –Geocode to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_file
(Optional[Path]
, default:None
) –File to load as a boundary to filter the input data to. Only used for geographic data. Defaults to None.
-
filter_links_to_nodes
(Optional[bool]
, default:None
) –if True, will filter the links to only those that have nodes. Defaults to False unless boundary_gdf, boundary_geocode, or boundary_file are provided which defaults it to True.
-
config
(ConfigInputTypes
, default:DefaultConfig
) –a Configuration object to update with the new configuration. Can be a dictionary, a path to a file, or a list of paths to files or a WranglerConfig instance. Defaults to None and will load defaults.
Returns:
-
RoadwayNetwork
–(RoadwayNetwork) instance of RoadwayNetwork
Source code in network_wrangler/roadway/io.py
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
network_wrangler.roadway.io.load_roadway_from_dataframes ¶
Creates a RoadwayNetwork from DataFrames with validation.
Validates the DataFrames against their respective Pandera schemas before creating the network instance. This method is useful if the user is already working with networks in DataFrames and doesn’t want to write it to disk just to read it again.
Parameters:
-
links_df
(DataFrame
) –DataFrame containing roadway links data
-
nodes_df
(DataFrame
) –DataFrame containing roadway nodes data
-
shapes_df
(Optional[GeoDataFrame]
, default:None
) –Optional GeoDataFrame containing roadway shapes data
-
config
(ConfigInputTypes
, default:DefaultConfig
) –a Configuration object to update with the new configuration. Can be a dictionary, a path to a file, or a list of paths to files or a WranglerConfig instance. Defaults to None and will load defaults.
Returns:
-
RoadwayNetwork
–(RoadwayNetwork) instance with validated data
Source code in network_wrangler/roadway/io.py
network_wrangler.roadway.io.load_roadway_from_dir ¶
load_roadway_from_dir(dir, file_format='geojson', read_in_shapes=False, boundary_gdf=None, boundary_geocode=None, boundary_file=None, filter_links_to_nodes=None, config=DefaultConfig)
Reads a network from the roadway network standard.
Validates that it conforms to the schema.
Parameters:
-
dir
(Union[Path, str]
) –the directory where the network files are located
-
file_format
(RoadwayFileTypes
, default:'geojson'
) –the file format of the files. Defaults to “geojson”
-
read_in_shapes
(bool
, default:False
) –if True, will read shapes into network instead of only lazily reading them when they are called. Defaults to False.
-
boundary_gdf
(Optional[GeoDataFrame]
, default:None
) –GeoDataFrame to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_geocode
(Optional[str]
, default:None
) –Geocode to filter the input data to. Only used for geographic data. Defaults to None.
-
boundary_file
(Optional[Path]
, default:None
) –File to load as a boundary to filter the input data to. Only used for geographic data. Defaults to None.
-
filter_links_to_nodes
(Optional[bool]
, default:None
) –if True, will filter the links to only those that have nodes. Defaults to False unless boundary_gdf, boundary_geocode, or boundary_file are provided which defaults it to True.
-
config
(ConfigInputTypes
, default:DefaultConfig
) –a Configuration object to update with the new configuration. Can be a dictionary, a path to a file, or a list of paths to files or a WranglerConfig instance. Defaults to None and will load defaults.
Returns:
-
RoadwayNetwork
–(RoadwayNetwork) instance of RoadwayNetwork
Source code in network_wrangler/roadway/io.py
network_wrangler.roadway.io.write_roadway ¶
write_roadway(net, out_dir='.', convert_complex_link_properties_to_single_field=False, prefix='', file_format='geojson', overwrite=True, true_shape=False)
Writes a network in the roadway network standard.
Parameters:
-
net
(Union[RoadwayNetwork, ModelRoadwayNetwork]
) –RoadwayNetwork or ModelRoadwayNetwork instance to write out.
-
out_dir
(Union[Path, str]
, default:'.'
) –the path were the output will be saved. Defaults to “.”.
-
prefix
(str
, default:''
) –the name prefix of the roadway files that will be generated.
-
file_format
(RoadwayFileTypes
, default:'geojson'
) –the format of the output files. Defaults to “geojson”.
-
convert_complex_link_properties_to_single_field
(bool
, default:False
) –if True, will convert complex link properties to a single column consistent with v0 format. This format is NOT valid with parquet and many other softwares. Defaults to False.
-
overwrite
(bool
, default:True
) –if True, will overwrite the files if they already exist. Defaults to True.
-
true_shape
(bool
, default:False
) –if True, will write the true shape of the links as found from shapes. Defaults to False.
Source code in network_wrangler/roadway/io.py
Functions to clip a RoadwayNetwork object to a boundary.
Clipped roadway is an independent roadway network that is a subset of the original roadway network.
Unlike a Subnet, it is geographic selection defined by a bounday rather than a logical selection defined by a graph.
Example usage:
from network_wrangler.roadway load_roadway_from_dir, write_roadway
from network_wrangler.roadway.clip import clip_roadway
stpaul_net = load_roadway_from_dir(example_dir / "stpaul")
boundary_file = test_dir / "data" / "ecolab.geojson"
clipped_network = clip_roadway(stpaul_net, boundary_file=boundary_file)
write_roadway(clipped_network, out_dir, prefix="ecolab", format="geojson", true_shape=True)
network_wrangler.roadway.clip.clip_roadway ¶
Clip a RoadwayNetwork object to a boundary.
Retains only the links within or crossing the boundary and all the nodes that those links connect to. At least one of boundary_gdf, boundary_geocode, or boundary_file must be provided.
Parameters:
-
network
(RoadwayNetwork
) –RoadwayNetwork object to be clipped.
-
boundary_gdf
(GeoDataFrame
, default:None
) –GeoDataframe of one or more polygons which define the boundary to clip to. Defaults to None.
-
boundary_geocode
(Union[str, dict]
, default:None
) –Place name to clip data to as ascertained from open street maps’s Nomatim API (e.g. “Hennipen County, MN, USA”). Defaults to None.
-
boundary_file
(Union[str, Path]
, default:None
) –Geographic data file that can be read by GeoPandas (e.g. geojson, parquet, shp) that defines a geographic polygon area to clip to. Defaults to None.
Source code in network_wrangler/roadway/clip.py
network_wrangler.roadway.clip.clip_roadway_to_dfs ¶
Clips a RoadwayNetwork object to a boundary and returns the resulting GeoDataFrames.
Retains only the links within or crossing the boundary and all the nodes that those links connect to.
Parameters:
-
network
(RoadwayNetwork
) –RoadwayNetwork object to be clipped.
-
boundary_gdf
(GeoDataFrame
, default:None
) –GeoDataframe of one or more polygons which define the boundary to clip to. Defaults to None.
-
boundary_geocode
(Union[str, dict]
, default:None
) –Place name to clip data to as ascertained from open street maps’s Nomatim API (e.g. “Hennipen County, MN, USA”). Defaults to None.
-
boundary_file
(Union[str, Path]
, default:None
) –Geographic data file that can be read by GeoPandas (e.g. geojson, parquet, shp) that defines a geographic polygon area to clip to. Defaults to None.
Source code in network_wrangler/roadway/clip.py
Functions to create a model roadway network from a roadway network.
network_wrangler.roadway.model_roadway.COPY_FROM_GP_TO_ML
module-attribute
¶
COPY_FROM_GP_TO_ML = ['ref', 'roadway', 'access', 'distance', 'bike_access', 'drive_access', 'walk_access', 'bus_only', 'rail_only']
List of attributes to copy from a general purpose lane to access and egress dummy links.
network_wrangler.roadway.model_roadway.COPY_TO_ACCESS_EGRESS
module-attribute
¶
List of attributes that must be provided in managed lanes.
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork ¶
Roadway Network Object compatible with travel modeling.
Compatability includes: (1) separation of managed lane facilities and their connection to general purpose lanes using dummy links.
Attr
Source code in network_wrangler/roadway/model_roadway.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork.compare_links_df
property
¶
Comparison of the original network and the model network.
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork.compare_net_df
property
¶
Comparison of the original network and the model network.
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork.dummy_links_df
property
¶
GP lanes on links that have managed lanes next to them.
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork.gp_links_df
property
¶
GP lanes on links that have managed lanes next to them.
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork.ml_config
property
¶
Convenience method for lanaged lane configuration.
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork.ml_links_df
property
¶
Managed lanes links.
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork.shapes_df
property
¶
Shapes dataframe.
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork.summary
property
¶
Quick summary dictionary of number of links, nodes.
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork.__init__ ¶
Constructor for ModelRoadwayNetwork.
NOTE: in order to be associated with the RoadwayNetwork, this should be called from RoadwayNetwork.model_net which will lazily construct it.
Parameters:
-
net
–Associated roadway network.
-
ml_link_id_lookup
(dict[int, int]
, default:None
) –lookup from general purpose link ids to link ids of their managed lane counterparts. Defaults to None which will generate a new one using the provided method.
-
ml_node_id_lookup
(dict[int, int]
, default:None
) –lookup from general purpose node ids to node ids of their managed lane counterparts. Defaults to None which will generate a new one using the provided method.
Source code in network_wrangler/roadway/model_roadway.py
network_wrangler.roadway.model_roadway.ModelRoadwayNetwork.write ¶
write(out_dir=Path(), convert_complex_link_properties_to_single_field=False, prefix='', file_format='geojson', overwrite=True, true_shape=False)
Writes a network in the roadway network standard.
Parameters:
-
out_dir
(Path
, default:Path()
) –the path were the output will be saved.
-
convert_complex_link_properties_to_single_field
(bool
, default:False
) –if True, will convert complex properties to a single column consistent with v0 format. This format is NOT valid with parquet and many other softwares. Defaults to False.
-
prefix
(str
, default:''
) –the name prefix of the roadway files that will be generated.
-
file_format
(RoadwayFileTypes
, default:'geojson'
) –the format of the output files. Defaults to “geojson”.
-
overwrite
(bool
, default:True
) –if True, will overwrite the files if they already exist. Defaults to True.
-
true_shape
(bool
, default:False
) –if True, will write the true shape of the links as found from shapes. Defaults to False.
Source code in network_wrangler/roadway/model_roadway.py
network_wrangler.roadway.model_roadway.model_links_nodes_from_net ¶
Create a roadway network with managed lanes links separated out.
Add new parallel managed lane links, access/egress links, and add shapes corresponding to the new links
Parameters:
-
net
(RoadwayNetwork
) –RoadwayNetwork instance
-
ml_link_id_lookup
(dict[int, int]
) –lookup table for managed lane link ids to their general purpose lane counterparts.
-
ml_node_id_lookup
(dict[int, int]
) –lookup table for managed lane node ids to their general purpose lane counterparts.
Source code in network_wrangler/roadway/model_roadway.py
network_wrangler.roadway.model_roadway.strip_ML_from_prop_list ¶
Strips ‘ML_’ from property list but keeps necessary access/egress point cols.
Source code in network_wrangler/roadway/model_roadway.py
Utility functions for RoadwayNetwork and ModelRoadwayNetwork classes.
network_wrangler.roadway.utils.compare_links ¶
Compare the summary of links in a list of dataframes.
Parameters:
-
links
(list[DataFrame]
) –list of dataframes
-
names
(Optional[list[str]]
, default:None
) –list of names for the dataframes
Source code in network_wrangler/roadway/utils.py
network_wrangler.roadway.utils.compare_networks ¶
Compare the summary of networks in a list of networks.
Parameters:
-
nets
(list[Union[RoadwayNetwork, ModelRoadwayNetwork]]
) –list of networks
-
names
(Optional[list[str]]
, default:None
) –list of names for the networks
Source code in network_wrangler/roadway/utils.py
network_wrangler.roadway.utils.create_unique_shape_id ¶
A unique hash id using the coordinates of the geometry using first and last locations.
Args: line_string: Line Geometry as a LineString
Returns: string
Source code in network_wrangler/roadway/utils.py
network_wrangler.roadway.utils.diff_nets ¶
Diff two RoadwayNetworks and return True if they are different.
Ignore locationReferences as they are not used in the network.
Parameters:
-
net1
(RoadwayNetwork
) –First network to compare
-
net2
(RoadwayNetwork
) –Second network to compare
Source code in network_wrangler/roadway/utils.py
network_wrangler.roadway.utils.set_df_index_to_pk ¶
Sets the index of the dataframe to be a copy of the primary key.
Parameters:
-
df
(DataFrame
) –data frame to set the index of
Source code in network_wrangler/roadway/utils.py
Validates a roadway network to the wrangler data model specifications.
network_wrangler.roadway.validate.validate_roadway_files ¶
Validates the roadway network files strictly to the wrangler data model specifications.
Parameters:
-
links_file
(str
) –The path to the links file.
-
nodes_file
(str
) –The path to the nodes file.
-
shapes_file
(str
, default:None
) –The path to the shapes file.
-
strict
(bool
, default:False
) –If True, will validate the roadway network strictly without parsing and filling in data.
-
output_dir
(str
, default:Path()
) –The output directory for the validation report. Defaults to “.”.
Source code in network_wrangler/roadway/validate.py
network_wrangler.roadway.validate.validate_roadway_in_dir ¶
Validates a roadway network in a directory to the wrangler data model specifications.
Parameters:
-
directory
(str
) –The roadway network file directory.
-
file_format(str)
–The formats of roadway network file name.
-
strict
(bool
, default:False
) –If True, will validate the roadway network strictly without parsing and filling in data.
-
output_dir
(str
, default:Path()
) –The output directory for the validation report. Defaults to “.”.
Source code in network_wrangler/roadway/validate.py
Segment class and related functions for working with segments of a RoadwayNetwork.
A segment is a contiguous length of RoadwayNetwork defined by start/end nodes + link selections.
Segments are defined by a selection dictionary and then searched for on the network using a shortest path graph search.
Usage:
selection_dict = {
"links": {"name": ["6th", "Sixth", "sixth"]},
"from": {"osm_node_id": "187899923"},
"to": {"osm_node_id": "187865924"},
}
segment = Segment(net, selection)
segment.segment_links_df
segment.segment_nodes
network_wrangler.roadway.segment.DEFAULT_MAX_SEARCH_BREADTH
module-attribute
¶
Factor to multiply sp_weight_col by to use for weights in shortest path.
network_wrangler.roadway.segment.DEFAULT_SUBNET_SP_WEIGHT_FACTOR
module-attribute
¶
Column to use for weights in shortest path.
network_wrangler.roadway.segment.Segment ¶
A contiguous length of RoadwayNetwork defined by start/end nodes + link selections.
Segments are defined by a selection dictionary and then searched for on the network using a shortest path graph search.
Usage:
selection_dict = {
"links": {"name":['6th','Sixth','sixth']},
"from": {"osm_node_id": '187899923'},
"to": {"osm_node_id": '187865924'}
}
net = RoadwayNetwork(...)
segment = Segment(net = net, selection)
# lazily evaluated dataframe of links in segment (if found) from segment.net
segment.segment_links_df
# lazily evaluated list of nodes primary keys that are in segment (if found)
segment.segment_nodes
attr
Source code in network_wrangler/roadway/segment.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
network_wrangler.roadway.segment.Segment.from_node_id
property
¶
Find start node in selection dict and return its primary key.
network_wrangler.roadway.segment.Segment.segment_from_node_s
property
¶
Roadway network nodes filtered to segment start node.
network_wrangler.roadway.segment.Segment.segment_links
property
¶
Primary keys of links in segment.
network_wrangler.roadway.segment.Segment.segment_links_df
property
¶
Roadway network links filtered to segment links.
network_wrangler.roadway.segment.Segment.segment_nodes
property
¶
Primary keys of nodes in segment.
network_wrangler.roadway.segment.Segment.segment_nodes_df
property
¶
Roadway network nodes filtered to nodes in segment.
network_wrangler.roadway.segment.Segment.segment_sel_dict
property
¶
Selection dictionary which only has keys related to initial segment link selection.
network_wrangler.roadway.segment.Segment.segment_to_node_s
property
¶
Roadway network nodes filtered to segment end node.
network_wrangler.roadway.segment.Segment.to_node_id
property
¶
Find end node in selection dict and return its primary key.
network_wrangler.roadway.segment.Segment.__init__ ¶
Initialize a roadway segment object.
Parameters:
-
net
(RoadwayNetwork
) –Associated RoadwayNetwork object
-
selection
(RoadwayLinkSelection
) –Selection of type
segment
. -
max_search_breadth
(int
, default:DEFAULT_MAX_SEARCH_BREADTH
) –Maximum number of nodes to search for in connected_path_search. Defaults to DEFAULT_MAX_SEGMENT_SEARCH_BREADTH.
Source code in network_wrangler/roadway/segment.py
network_wrangler.roadway.segment.Segment.connected_path_search ¶
Finds a path from from_node_id to to_node_id based on the weight col value/factor.
Source code in network_wrangler/roadway/segment.py
network_wrangler.roadway.segment.Segment.get_node ¶
Get single node based on the selection data.
Source code in network_wrangler/roadway/segment.py
network_wrangler.roadway.segment.Segment.get_node_id ¶
Get the primary key of a node based on the selection data.
network_wrangler.roadway.segment.generate_subnet_from_link_selection_dict ¶
generate_subnet_from_link_selection_dict(net, link_selection_dict, modes=DEFAULT_SEARCH_MODES, sp_weight_col=SUBNET_SP_WEIGHT_COL, sp_weight_factor=DEFAULT_SUBNET_SP_WEIGHT_FACTOR, **kwargs)
Generates a Subnet object from a link selection dictionary.
First will search based on “name” in selection_dict but if not found, will search using the “ref” field instead.
Parameters:
-
net
(RoadwayNetwork
) –RoadwayNetwork object.
-
link_selection_dict
(dict
) –dictionary of attributes to search for.
-
modes
(list[str]
, default:DEFAULT_SEARCH_MODES
) –List of modes to limit subnet to. Defaults to DEFAULT_SEARCH_MODES.
-
sp_weight_col
(str
, default:SUBNET_SP_WEIGHT_COL
) –Column to use for weights in shortest path. Defaults to SUBNET_SP_WEIGHT_COL.
-
sp_weight_factor
(float
, default:DEFAULT_SUBNET_SP_WEIGHT_FACTOR
) –Factor to multiply sp_weight_col by to use for weights in shortest path. Defaults to DEFAULT_SUBNET_SP_WEIGHT_FACTOR.
-
kwargs
–other kwargs to pass to Subnet initiation
Returns:
-
Subnet
(Subnet
) –Subnet object.
Source code in network_wrangler/roadway/segment.py
network_wrangler.roadway.segment.identify_segment_endpoints ¶
This has not been revisited or refactored and may or may not contain useful code.
Parameters:
-
net
–RoadwayNetwork to find segments for
-
mode
(str
, default:'drive'
) –list of modes of the network, one of
drive
,transit
,walk
,bike
. Defaults to “drive”. -
min_connecting_links
(int
, default:10
) –number of links that should be connected with same name or ref to be considered a segment (minus max_link_deviation). Defaults to 10.
-
max_link_deviation
(int
, default:2
) –maximum links that don’t have the same name or ref to still be considered a segment. Defaults to 2.
Source code in network_wrangler/roadway/segment.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
|
Subnet class for RoadwayNetwork object.
network_wrangler.roadway.subnet.DEFAULT_SUBNET_MAX_SEARCH_BREADTH
module-attribute
¶
Factor to multiply sp_weight_col by to use for weights in shortest path.
network_wrangler.roadway.subnet.DEFAULT_SUBNET_SP_WEIGHT_FACTOR
module-attribute
¶
Column to use for weights in shortest path.
network_wrangler.roadway.subnet.Subnet ¶
Subnet is a connected selection of links/nodes from a RoadwayNetwork object.
Subnets are used for things like identifying Segments.
Usage:
selection_dict = {
"links": {"name": ["6th", "Sixth", "sixth"]},
"from": {"osm_node_id": "187899923"},
"to": {"osm_node_id": "187865924"},
}
segment = Segment(net=RoadwayNetwork(...), selection_dict=selection_dict)
# used to store graph
self._segment_route_nodes = shortest_path(segment.subnet.graph, start_node_pk, end_node_pk)
attr
Source code in network_wrangler/roadway/subnet.py
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
network_wrangler.roadway.subnet.Subnet.exists
property
¶
Returns True if subnet_links_df is not None and has at least one link.
network_wrangler.roadway.subnet.Subnet.graph_hash
property
¶
Hash of the links in order to detect a network change from when graph created.
network_wrangler.roadway.subnet.Subnet.num_links
property
¶
Number of links in the subnet.
network_wrangler.roadway.subnet.Subnet.subnet_links_df
property
¶
Links in the subnet.
network_wrangler.roadway.subnet.Subnet.subnet_nodes
property
¶
List of node_ids in the subnet.
network_wrangler.roadway.subnet.Subnet.subnet_nodes_df
property
¶
Nodes filtered to subnet.
network_wrangler.roadway.subnet.Subnet.__init__ ¶
__init__(net, modes=DEFAULT_SEARCH_MODES, subnet_links_df=None, i=0, sp_weight_factor=DEFAULT_SUBNET_SP_WEIGHT_FACTOR, sp_weight_col=SUBNET_SP_WEIGHT_COL, max_search_breadth=DEFAULT_SUBNET_MAX_SEARCH_BREADTH)
Generates and returns a Subnet object.
Parameters:
-
net
(RoadwayNetwork
) –Associated RoadwayNetwork object.
-
modes
(Optional[list]
, default:DEFAULT_SEARCH_MODES
) –List of modes to limit subnet to. Defaults to DEFAULT_SEARCH_MODES.
-
subnet_links_df
(DataFrame
, default:None
) –Initial links to include in subnet. Optional if define a selection_dict and will default to result of self.generate_subnet_from_selection_dict(selection_dict)
-
i
(int
, default:0
) –Expansion iteration number. Shouldn’t need to change this as it will be done internally. Defaults to 0.
-
sp_weight_col
(str
, default:SUBNET_SP_WEIGHT_COL
) –Column to use for weights in shortest path. Will not likely need to be changed. Defaults to “i” which is the iteration #.
-
sp_weight_factor
(float
, default:DEFAULT_SUBNET_SP_WEIGHT_FACTOR
) –Factor to multiply sp_weight_col by to use for weights in shortest path. Will not likely need to be changed. Defaults to DEFAULT_SP_WEIGHT_FACTOR.
-
max_search_breadth
(int
, default:DEFAULT_SUBNET_MAX_SEARCH_BREADTH
) –Maximum expansions of the subnet network to find the shortest path after the initial selection based on
name
. Will not likely need to be changed unless network contains a lot of ambiguity. Defaults to DEFAULT_MAX_SEARCH_BREADTH.
Source code in network_wrangler/roadway/subnet.py
network_wrangler.roadway.subnet.Subnet.expand_to_nodes ¶
Expand network to include list of nodes.
Will stop expanding and generate a SubnetExpansionError if meet max_search_breadth before finding the nodes.
Parameters:
-
nodes_list
(list
) –a list of node primary keys to expand subnet to include.
-
max_search_breadth
(int
) –maximum number of expansions to make before giving up.
Source code in network_wrangler/roadway/subnet.py
Functions to convert RoadwayNetwork to osmnx graph and perform graph operations.
network_wrangler.roadway.graph.DEFAULT_GRAPH_WEIGHT_COL
module-attribute
¶
Factor to multiply sp_weight_col by to use for weights in shortest path.
network_wrangler.roadway.graph.ox_major_version
module-attribute
¶
Column to use for weights in shortest path.
network_wrangler.roadway.graph.assess_connectivity ¶
Network graph and list of disconnected subgraphs described by a list of their member nodes.
Parameters:
-
net
(RoadwayNetwork
) –RoadwayNetwork object
-
mode
(str
, default:''
) –mode of the network, one of
drive
,transit
,walk
,bike
-
ignore_end_nodes
(bool
, default:True
) –if True, ignores stray singleton nodes
Tuple of
-
–
Network Graph (osmnx flavored networkX DiGraph)
-
–
List of disconnected subgraphs described by the list of their member nodes (as described by their
model_node_id
)
Source code in network_wrangler/roadway/graph.py
network_wrangler.roadway.graph.links_nodes_to_ox_graph ¶
Create an osmnx-flavored network graph from nodes and links dfs.
osmnx doesn’t like values that are arrays, so remove the variables that have arrays. osmnx also requires that certain variables be filled in, so do that too.
Parameters:
-
links_df
(GeoDataFrame
) –links_df from RoadwayNetwork
-
nodes_df
(GeoDataFrame
) –nodes_df from RoadwayNetwork
-
sp_weight_col
(str
, default:'distance'
) –column to use for weights. Defaults to
distance
. -
sp_weight_factor
(float
, default:1
) –multiple to apply to the weights. Defaults to 1.
Source code in network_wrangler/roadway/graph.py
network_wrangler.roadway.graph.net_to_graph ¶
Converts a network to a MultiDiGraph.
Parameters:
-
net
(RoadwayNetwork
) –RoadwayNetwork object
-
mode
(Optional[str]
, default:None
) –mode of the network, one of
drive
,transit
,walk
,bike
Source code in network_wrangler/roadway/graph.py
network_wrangler.roadway.graph.shortest_path ¶
Calculates the shortest path between two nodes in a network.
Parameters:
-
G
(MultiDiGraph
) –osmnx MultiDiGraph, created using links_nodes_to_ox_graph
-
O_id
–primary key for start node
-
D_id
–primary key for end node
-
sp_weight_property
–link property to use as weight in finding shortest path. Defaults to “weight”.
- Boolean if shortest path found
- nx Directed graph of graph links
- route of shortest path nodes as List
- links in shortest path selected from links_df