stplanpy.route module¶
The functions in this module perform various operations on routes.
- stplanpy.route.directness(fd: geopandas.geodataframe.GeoDataFrame) pandas.core.series.Series ¶
Compute the directness of a route
This function computes the directness of the routes in GeoDataFrame fd. Directness is defined as the distance along a route divided by the distance as the crow flies.
- Parameters
None –
- Returns
Series with directness values.
- Return type
pandas.Series
See also
Examples
import pandas as pd import geopandas as gpd from shapely import wkt from stplanpy import route # Create DataFrames df = pd.DataFrame( {"all": [4, 3, 2, 5], "bike": [2, 0, 1, 3], "go_dutch": [3, 5, 0, 4], "geometry": ["LINESTRING(1 0,0 0,1 1,2 1,3 0)", "LINESTRING(0 2,1 1,2 1,3 2,2 2)", "LINESTRING(1 0,1 1,2 1,2 0)", "LINESTRING(1 2,1 1,2 1,2 2,3 2)"]}) # Convert to WTK df["geometry"] = gpd.GeoSeries.from_wkt(df["geometry"]) # Create GeoDataFrame gdf = gpd.GeoDataFrame(df, geometry='geometry') # Compute directness gdf["directness"] = gdf.directness()
- stplanpy.route.network(fd: geopandas.geodataframe.GeoDataFrame, modes=['bike'], max_rows=1000) geopandas.geodataframe.GeoDataFrame ¶
Reduce route data to a network
This function reduces route data in GeoDataFrame fd to a network for the modes of transporation listed in modes. All line segments of routes that overlap are reduced to one segment and their mode numbers are summed up.
- Parameters
modes (list of str, defaults to ["bike"]) – List of modes of transportation that the network is computed for. Defaults to [“bike”].
max_rows (int, defaults to 4000) – To reduce the memory footprint a GeoDataFrames is split up in blocks of max_rows rows. This value can be increased on computers with enough RAM.
- Returns
GeoDataFrame containing the network.
- Return type
geopandas.GeoDataFrame
See also
Examples
mport pandas as pd port geopandas as gpd om shapely import wkt om stplanpy import route Create DataFrames df = pd.DataFrame( {"all": [4, 3, 2, 5], "bike": [2, 0, 1, 3], "go_dutch": [3, 5, 0, 4], "geometry": ["LINESTRING(1 0,0 0,1 1,2 1,3 0)", "LINESTRING(0 2,1 1,2 1,3 2,2 2)", "LINESTRING(1 0,1 1,2 1,2 0)", "LINESTRING(1 2,1 1,2 1,2 2,3 2)"]}) # Convert to WTK df["geometry"] = gpd.GeoSeries.from_wkt(df["geometry"]) # Create GeoDataFrame gdf = gpd.GeoDataFrame(df, geometry='geometry') # Compute the network network = gdf.network(modes=["bike", "go_dutch"])