bikenetlib 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bikenetlib/__init__.py +12 -0
- bikenetlib/_version.py +3 -0
- bikenetlib/io.py +57 -0
- bikenetlib/utils.py +755 -0
- bikenetlib/viz.py +0 -0
- bikenetlib-0.0.0.dist-info/METADATA +69 -0
- bikenetlib-0.0.0.dist-info/RECORD +10 -0
- bikenetlib-0.0.0.dist-info/WHEEL +5 -0
- bikenetlib-0.0.0.dist-info/licenses/LICENSE +661 -0
- bikenetlib-0.0.0.dist-info/top_level.txt +1 -0
bikenetlib/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
3
|
+
|
|
4
|
+
from . import io
|
|
5
|
+
from . import utils
|
|
6
|
+
from . import viz
|
|
7
|
+
|
|
8
|
+
__author__ = "MS, AV, MK"
|
|
9
|
+
__author_email__ = "email@domain.com"
|
|
10
|
+
|
|
11
|
+
with contextlib.suppress(PackageNotFoundError):
|
|
12
|
+
__version__ = version("bikenetlib")
|
bikenetlib/_version.py
ADDED
bikenetlib/io.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import geopandas as gpd
|
|
2
|
+
import osmnx as ox
|
|
3
|
+
|
|
4
|
+
def prepare_network(city_name, proj_crs, network_type='all_public', custom_filter=None, retain_all=True, city_boundary_file=None):
|
|
5
|
+
"""Download and prepare a street network from OSM via OSMnx
|
|
6
|
+
|
|
7
|
+
Downloads a network with a given network_type and custom_filter using ox.graph_from_place.
|
|
8
|
+
Then, stores the undirected OSM data in gdfs and projects using proj_crs.
|
|
9
|
+
|
|
10
|
+
Parameters
|
|
11
|
+
----------
|
|
12
|
+
city_name : str
|
|
13
|
+
Name of the city that the analysis should be performed on. Overruled (for data fetching) if city_boundary_file is set.
|
|
14
|
+
proj_crs : str
|
|
15
|
+
Coordinate reference system that is used to project osm data.
|
|
16
|
+
network_type : {“all”, “all_public”, “bike”, “drive”, “drive_service”, “walk”}
|
|
17
|
+
What type of street network to retrieve if custom_filter is None.
|
|
18
|
+
custom_filter : (str | list[str] | None)
|
|
19
|
+
A custom ways filter to be used instead of the network_type presets
|
|
20
|
+
retain_all : bool, default True
|
|
21
|
+
If True, return the entire graph even if it is not connected, useful for disconnected bicycle networks. If False, retain only the largest weakly connected component, useful for road networks.
|
|
22
|
+
city_boundary_file : (str | None), default None
|
|
23
|
+
If not set to None, the study area will be selected from the (Multi)Polygon provided in the city_boundary_file shape file. For example, "copenhagen.shp".
|
|
24
|
+
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
nodes : geopandas.geodataframe.GeoDataFrame
|
|
28
|
+
Extracted OSM nodes, projected
|
|
29
|
+
edges : geopandas.geodataframe.GeoDataFrame
|
|
30
|
+
Extracted OSM edges, projected
|
|
31
|
+
g_undir : networkx.classes.multigraph.MultiGraph
|
|
32
|
+
Extracted networkX graph, undirected
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
# Fetch street network data from osmnx
|
|
36
|
+
if city_boundary_file is None:
|
|
37
|
+
g = ox.graph_from_place(
|
|
38
|
+
city_name, network_type=network_type, custom_filter=custom_filter, retain_all=retain_all
|
|
39
|
+
)
|
|
40
|
+
else:
|
|
41
|
+
shp = gpd.read_file(city_boundary_file)
|
|
42
|
+
city_boundary_polygon = shp.iloc[0].geometry
|
|
43
|
+
g = ox.graph_from_polygon(
|
|
44
|
+
city_boundary_polygon, network_type=network_type, custom_filter=custom_filter, retain_all=retain_all
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
g_undir = g.to_undirected().copy() # convert to undirected (dropping OSMnx keys!)
|
|
48
|
+
|
|
49
|
+
# Export osmnx data to gdfs
|
|
50
|
+
nodes, edges = nx_to_nodes_edges(g_undir, proj_crs)
|
|
51
|
+
return nodes, edges, g_undir
|
|
52
|
+
|
|
53
|
+
def download_pois(): # To develop
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
def save_to_file(): # To develop
|
|
57
|
+
pass
|