ObjectNat 1.2.0__py3-none-any.whl → 1.2.2__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.

Potentially problematic release.


This version of ObjectNat might be problematic. Click here for more details.

objectnat/__init__.py CHANGED
@@ -1,13 +1,9 @@
1
- """
2
- ObjectNat
3
- ========
4
-
5
-
6
- ObjectNat is an open-source library created for geospatial analysis created by IDU team.
7
-
8
- Homepage https://github.com/DDonnyy/ObjectNat.
9
- """
10
-
11
- from ._config import config
12
- from ._api import *
13
- from ._version import VERSION as __version__
1
+ """
2
+ ObjectNat is an open-source library created for geospatial analysis created by IDU team.
3
+
4
+ Homepage https://github.com/DDonnyy/ObjectNat.
5
+ """
6
+
7
+ from ._config import config
8
+ from ._api import *
9
+ from ._version import VERSION as __version__
objectnat/_version.py CHANGED
@@ -1 +1 @@
1
- VERSION = "1.2.0"
1
+ VERSION = "1.2.2"
@@ -1,108 +1,98 @@
1
- from typing import Literal
2
-
3
- import geopandas as gpd
4
- import networkx as nx
5
- import pandas as pd
6
- from pyproj.exceptions import CRSError
7
- from shapely import Point, concave_hull
8
-
9
- from objectnat.methods.utils.graph_utils import get_closest_nodes_from_gdf, reverse_graph
10
-
11
-
12
- def get_graph_coverage(
13
- gdf_to: gpd.GeoDataFrame,
14
- nx_graph: nx.Graph,
15
- weight_type: Literal["time_min", "length_meter"],
16
- weight_value_cutoff: float = None,
17
- zone: gpd.GeoDataFrame = None,
18
- ):
19
- """
20
- Calculate coverage zones from source points through a graph network using Dijkstra's algorithm
21
- and Voronoi diagrams.
22
-
23
- The function works by:
24
- 1. Finding nearest graph nodes for each input point
25
- 2. Calculating all reachable nodes within cutoff distance using Dijkstra
26
- 3. Creating Voronoi polygons around graph nodes
27
- 4. Combining reachability information with Voronoi cells
28
- 5. Clipping results to specified zone boundary
29
-
30
- Parameters
31
- ----------
32
- gdf_to : gpd.GeoDataFrame
33
- Source points to which coverage is calculated.
34
- nx_graph : nx.Graph
35
- NetworkX graph representing the transportation network.
36
- weight_type : Literal["time_min", "length_meter"]
37
- Edge attribute to use as weight for path calculations.
38
- weight_value_cutoff : float, optional
39
- Maximum weight value for path calculations (e.g., max travel time/distance).
40
- zone : gpd.GeoDataFrame, optional
41
- Boundary polygon to clip the resulting coverage zones. If None, concave hull of reachable nodes will be used.
42
-
43
- Returns
44
- -------
45
- gpd.GeoDataFrame
46
- GeoDataFrame with coverage zones polygons, each associated with its source point, returns in the same CRS as
47
- original gdf_from.
48
-
49
- Notes
50
- -----
51
- - The graph must have a valid CRS attribute in its graph properties
52
- - MultiGraph/MultiDiGraph inputs will be converted to simple Graph/DiGraph
53
-
54
- Examples
55
- --------
56
- >>> from iduedu import get_intermodal_graph # pip install iduedu to get OSM city network graph
57
- >>> points = gpd.read_file('points.geojson')
58
- >>> graph = get_intermodal_graph(osm_id=1114252)
59
- >>> coverage = get_graph_coverage(points, graph, "time_min", 15)
60
- """
61
- original_crs = gdf_to.crs
62
- try:
63
- local_crs = nx_graph.graph["crs"]
64
- except KeyError as exc:
65
- raise ValueError("Graph does not have crs attribute") from exc
66
-
67
- try:
68
- points = gdf_to.copy()
69
- points.to_crs(local_crs, inplace=True)
70
- except CRSError as e:
71
- raise CRSError(f"Graph crs ({local_crs}) has invalid format.") from e
72
-
73
- nx_graph, reversed_graph = reverse_graph(nx_graph, weight_type)
74
-
75
- points.geometry = points.representative_point()
76
-
77
- _, nearest_nodes = get_closest_nodes_from_gdf(points, nx_graph)
78
-
79
- points["nearest_node"] = nearest_nodes
80
-
81
- nearest_paths = nx.multi_source_dijkstra_path(
82
- reversed_graph, nearest_nodes, weight=weight_type, cutoff=weight_value_cutoff
83
- )
84
- reachable_nodes = list(nearest_paths.keys())
85
- graph_points = pd.DataFrame(
86
- data=[{"node": node, "geometry": Point(data["x"], data["y"])} for node, data in nx_graph.nodes(data=True)]
87
- ).set_index("node")
88
- nearest_nodes = pd.DataFrame(
89
- data=[path[0] for path in nearest_paths.values()], index=reachable_nodes, columns=["node_to"]
90
- )
91
- graph_nodes_gdf = gpd.GeoDataFrame(
92
- graph_points.merge(nearest_nodes, left_index=True, right_index=True, how="left"),
93
- geometry="geometry",
94
- crs=local_crs,
95
- )
96
- graph_nodes_gdf["node_to"] = graph_nodes_gdf["node_to"].fillna("non_reachable")
97
- voronois = gpd.GeoDataFrame(geometry=graph_nodes_gdf.voronoi_polygons(), crs=local_crs)
98
- graph_nodes_gdf = graph_nodes_gdf[graph_nodes_gdf["node_to"] != "non_reachable"]
99
- zone_coverages = voronois.sjoin(graph_nodes_gdf).dissolve(by="node_to").reset_index().drop(columns=["node"])
100
- zone_coverages = zone_coverages.merge(
101
- points.drop(columns="geometry"), left_on="node_to", right_on="nearest_node", how="inner"
102
- ).reset_index(drop=True)
103
- zone_coverages.drop(columns=["node_to", "nearest_node"], inplace=True)
104
- if zone is None:
105
- zone = concave_hull(graph_nodes_gdf[~graph_nodes_gdf["node_to"].isna()].union_all(), ratio=0.5)
106
- else:
107
- zone = zone.to_crs(local_crs)
108
- return zone_coverages.clip(zone).to_crs(original_crs)
1
+ from typing import Literal
2
+
3
+ import geopandas as gpd
4
+ import networkx as nx
5
+ import pandas as pd
6
+ from pyproj.exceptions import CRSError
7
+ from shapely import Point, concave_hull
8
+
9
+ from objectnat.methods.utils.graph_utils import get_closest_nodes_from_gdf, reverse_graph
10
+
11
+
12
+ def get_graph_coverage(
13
+ gdf_to: gpd.GeoDataFrame,
14
+ nx_graph: nx.Graph,
15
+ weight_type: Literal["time_min", "length_meter"],
16
+ weight_value_cutoff: float = None,
17
+ zone: gpd.GeoDataFrame = None,
18
+ ):
19
+ """
20
+ Calculate coverage zones from source points through a graph network using Dijkstra's algorithm
21
+ and Voronoi diagrams.
22
+
23
+ The function works by:
24
+ 1. Finding nearest graph nodes for each input point
25
+ 2. Calculating all reachable nodes within cutoff distance using Dijkstra
26
+ 3. Creating Voronoi polygons around graph nodes
27
+ 4. Combining reachability information with Voronoi cells
28
+ 5. Clipping results to specified zone boundary
29
+
30
+ Parameters:
31
+ gdf_to (gpd.GeoDataFrame):
32
+ Source points to which coverage is calculated.
33
+ nx_graph (nx.Graph):
34
+ NetworkX graph representing the transportation network.
35
+ weight_type (Literal["time_min", "length_meter"]):
36
+ Edge attribute to use as weight for path calculations.
37
+ weight_value_cutoff (float):
38
+ Maximum weight value for path calculations (e.g., max travel time/distance).
39
+ zone (gpd.GeoDataFrame):
40
+ Boundary polygon to clip the resulting coverage zones. If None, concave hull of reachable nodes will be used.
41
+
42
+ Returns:
43
+ (gpd.GeoDataFrame):
44
+ GeoDataFrame with coverage zones polygons, each associated with its source point, returns in the same CRS
45
+ as original gdf_from.
46
+
47
+ Notes:
48
+ - The graph must have a valid CRS attribute in its graph properties
49
+ - MultiGraph/MultiDiGraph inputs will be converted to simple Graph/DiGraph
50
+ """
51
+ original_crs = gdf_to.crs
52
+ try:
53
+ local_crs = nx_graph.graph["crs"]
54
+ except KeyError as exc:
55
+ raise ValueError("Graph does not have crs attribute") from exc
56
+
57
+ try:
58
+ points = gdf_to.copy()
59
+ points.to_crs(local_crs, inplace=True)
60
+ except CRSError as e:
61
+ raise CRSError(f"Graph crs ({local_crs}) has invalid format.") from e
62
+
63
+ nx_graph, reversed_graph = reverse_graph(nx_graph, weight_type)
64
+
65
+ points.geometry = points.representative_point()
66
+
67
+ _, nearest_nodes = get_closest_nodes_from_gdf(points, nx_graph)
68
+
69
+ points["nearest_node"] = nearest_nodes
70
+
71
+ nearest_paths = nx.multi_source_dijkstra_path(
72
+ reversed_graph, nearest_nodes, weight=weight_type, cutoff=weight_value_cutoff
73
+ )
74
+ reachable_nodes = list(nearest_paths.keys())
75
+ graph_points = pd.DataFrame(
76
+ data=[{"node": node, "geometry": Point(data["x"], data["y"])} for node, data in nx_graph.nodes(data=True)]
77
+ ).set_index("node")
78
+ nearest_nodes = pd.DataFrame(
79
+ data=[path[0] for path in nearest_paths.values()], index=reachable_nodes, columns=["node_to"]
80
+ )
81
+ graph_nodes_gdf = gpd.GeoDataFrame(
82
+ graph_points.merge(nearest_nodes, left_index=True, right_index=True, how="left"),
83
+ geometry="geometry",
84
+ crs=local_crs,
85
+ )
86
+ graph_nodes_gdf["node_to"] = graph_nodes_gdf["node_to"].fillna("non_reachable")
87
+ voronois = gpd.GeoDataFrame(geometry=graph_nodes_gdf.voronoi_polygons(), crs=local_crs)
88
+ graph_nodes_gdf = graph_nodes_gdf[graph_nodes_gdf["node_to"] != "non_reachable"]
89
+ zone_coverages = voronois.sjoin(graph_nodes_gdf).dissolve(by="node_to").reset_index().drop(columns=["node"])
90
+ zone_coverages = zone_coverages.merge(
91
+ points.drop(columns="geometry"), left_on="node_to", right_on="nearest_node", how="inner"
92
+ ).reset_index(drop=True)
93
+ zone_coverages.drop(columns=["node_to", "nearest_node"], inplace=True)
94
+ if zone is None:
95
+ zone = concave_hull(graph_nodes_gdf[~graph_nodes_gdf["node_to"].isna()].union_all(), ratio=0.5)
96
+ else:
97
+ zone = zone.to_crs(local_crs)
98
+ return zone_coverages.clip(zone).to_crs(original_crs)
@@ -1,45 +1,37 @@
1
- import geopandas as gpd
2
- import numpy as np
3
-
4
-
5
- def get_radius_coverage(gdf_from: gpd.GeoDataFrame, radius: float, resolution: int = 32):
6
- """
7
- Calculate radius-based coverage zones using Voronoi polygons.
8
-
9
- Parameters
10
- ----------
11
- gdf_from : gpd.GeoDataFrame
12
- Source points for which coverage zones are calculated.
13
- radius : float
14
- Maximum coverage radius in meters.
15
- resolution : int, optional
16
- Number of segments used to approximate quarter-circle in buffer (default=32).
17
-
18
- Returns
19
- -------
20
- gpd.GeoDataFrame
21
- GeoDataFrame with smoothed coverage zone polygons in the same CRS as original gdf_from.
22
-
23
- Notes
24
- -----
25
- - Automatically converts to local UTM CRS for accurate distance measurements
26
- - Final zones are slightly contracted then expanded for smoothing effect
27
-
28
- Examples
29
- --------
30
- >>> facilities = gpd.read_file('healthcare.shp')
31
- >>> coverage = get_radius_coverage(facilities, radius=500)
32
- """
33
- original_crs = gdf_from.crs
34
- local_crs = gdf_from.estimate_utm_crs()
35
- gdf_from = gdf_from.to_crs(local_crs)
36
- bounds = gdf_from.buffer(radius).union_all()
37
- coverage_polys = gpd.GeoDataFrame(geometry=gdf_from.voronoi_polygons().clip(bounds, keep_geom_type=True))
38
- coverage_polys = coverage_polys.sjoin(gdf_from)
39
- coverage_polys["area"] = coverage_polys.area
40
- coverage_polys["buffer"] = np.pow(coverage_polys["area"], 1 / 3)
41
- coverage_polys.geometry = coverage_polys.buffer(-coverage_polys["buffer"], resolution=1, join_style="mitre").buffer(
42
- coverage_polys["buffer"] * 0.9, resolution=resolution
43
- )
44
- coverage_polys.drop(columns=["buffer", "area"], inplace=True)
45
- return coverage_polys.to_crs(original_crs)
1
+ import geopandas as gpd
2
+ import numpy as np
3
+
4
+
5
+ def get_radius_coverage(gdf_from: gpd.GeoDataFrame, radius: float, resolution: int = 32):
6
+ """
7
+ Calculate radius-based coverage zones using Voronoi polygons.
8
+
9
+ Parameters:
10
+ gdf_from (gpd.GeoDataFrame):
11
+ Source points for which coverage zones are calculated.
12
+ radius (float):
13
+ Maximum coverage radius in meters.
14
+ resolution (int):
15
+ Number of segments used to approximate quarter-circle in buffer (default=32).
16
+
17
+ Returns:
18
+ (gpd.GeoDataFrame):
19
+ GeoDataFrame with smoothed coverage zone polygons in the same CRS as original gdf_from.
20
+
21
+ Notes:
22
+ - Automatically converts to local UTM CRS for accurate distance measurements
23
+ - Final zones are slightly contracted then expanded for smoothing effect
24
+ """
25
+ original_crs = gdf_from.crs
26
+ local_crs = gdf_from.estimate_utm_crs()
27
+ gdf_from = gdf_from.to_crs(local_crs)
28
+ bounds = gdf_from.buffer(radius).union_all()
29
+ coverage_polys = gpd.GeoDataFrame(geometry=gdf_from.voronoi_polygons().clip(bounds, keep_geom_type=True))
30
+ coverage_polys = coverage_polys.sjoin(gdf_from)
31
+ coverage_polys["area"] = coverage_polys.area
32
+ coverage_polys["buffer"] = np.pow(coverage_polys["area"], 1 / 3)
33
+ coverage_polys.geometry = coverage_polys.buffer(-coverage_polys["buffer"], resolution=1, join_style="mitre").buffer(
34
+ coverage_polys["buffer"] * 0.9, resolution=resolution
35
+ )
36
+ coverage_polys.drop(columns=["buffer", "area"], inplace=True)
37
+ return coverage_polys.to_crs(original_crs)
@@ -1,142 +1,126 @@
1
- from typing import Literal
2
-
3
- import geopandas as gpd
4
- import networkx as nx
5
- import numpy as np
6
- import pandas as pd
7
- from pyproj.exceptions import CRSError
8
- from shapely import Point, concave_hull
9
-
10
- from objectnat.methods.isochrones.isochrone_utils import create_separated_dist_polygons
11
- from objectnat.methods.utils.graph_utils import get_closest_nodes_from_gdf, reverse_graph
12
-
13
-
14
- def get_stepped_graph_coverage(
15
- gdf_to: gpd.GeoDataFrame,
16
- nx_graph: nx.Graph,
17
- weight_type: Literal["time_min", "length_meter"],
18
- step_type: Literal["voronoi", "separate"],
19
- weight_value_cutoff: float = None,
20
- zone: gpd.GeoDataFrame = None,
21
- step: float = None,
22
- ):
23
- """
24
- Calculate stepped coverage zones from source points through a graph network using Dijkstra's algorithm
25
- and Voronoi-based or buffer-based isochrone steps.
26
-
27
- This function combines graph-based accessibility with stepped isochrone logic. It:
28
- 1. Finds nearest graph nodes for each input point
29
- 2. Computes reachability for increasing weights (e.g. time or distance) in defined steps
30
- 3. Generates Voronoi-based or separate buffer zones around network nodes
31
- 4. Aggregates zones into stepped coverage layers
32
- 5. Optionally clips results to a boundary zone
33
-
34
- Parameters
35
- ----------
36
- gdf_to : gpd.GeoDataFrame
37
- Source points from which stepped coverage is calculated.
38
- nx_graph : nx.Graph
39
- NetworkX graph representing the transportation network.
40
- weight_type : Literal["time_min", "length_meter"]
41
- Type of edge weight to use for path calculation:
42
- - "time_min": Edge travel time in minutes
43
- - "length_meter": Edge length in meters
44
- step_type : Literal["voronoi", "separate"]
45
- Method for generating stepped zones:
46
- - "voronoi": Stepped zones based on Voronoi polygons around graph nodes
47
- - "separate": Independent buffer zones per step
48
- weight_value_cutoff : float, optional
49
- Maximum weight value (e.g., max travel time or distance) to limit the coverage extent.
50
- zone : gpd.GeoDataFrame, optional
51
- Optional boundary polygon to clip resulting stepped zones. If None, concave hull of reachable area is used.
52
- step : float, optional
53
- Step interval for coverage zone construction. Defaults to:
54
- - 100 meters for distance-based weight
55
- - 1 minute for time-based weight
56
-
57
- Returns
58
- -------
59
- gpd.GeoDataFrame
60
- GeoDataFrame with polygons representing stepped coverage zones for each input point, annotated by step range.
61
-
62
- Notes
63
- -----
64
- - Input graph must have a valid CRS defined.
65
- - MultiGraph or MultiDiGraph inputs will be simplified.
66
- - Designed for accessibility and spatial equity analyses over multimodal networks.
67
-
68
- Examples
69
- --------
70
- >>> from iduedu import get_intermodal_graph
71
- >>> points = gpd.read_file('destinations.geojson')
72
- >>> graph = get_intermodal_graph(osm_id=1114252)
73
- >>> stepped_coverage = get_stepped_graph_coverage(
74
- ... points, graph, "time_min", step_type="voronoi", weight_value_cutoff=30, step=5
75
- ... )
76
- >>> # Using buffer-style zones
77
- >>> stepped_separate = get_stepped_graph_coverage(
78
- ... points, graph, "length_meter", step_type="separate", weight_value_cutoff=1000, step=200
79
- ... )
80
- """
81
- if step is None:
82
- if weight_type == "length_meter":
83
- step = 100
84
- else:
85
- step = 1
86
- original_crs = gdf_to.crs
87
- try:
88
- local_crs = nx_graph.graph["crs"]
89
- except KeyError as exc:
90
- raise ValueError("Graph does not have crs attribute") from exc
91
-
92
- try:
93
- points = gdf_to.copy()
94
- points.to_crs(local_crs, inplace=True)
95
- except CRSError as e:
96
- raise CRSError(f"Graph crs ({local_crs}) has invalid format.") from e
97
-
98
- nx_graph, reversed_graph = reverse_graph(nx_graph, weight_type)
99
-
100
- points.geometry = points.representative_point()
101
-
102
- distances, nearest_nodes = get_closest_nodes_from_gdf(points, nx_graph)
103
-
104
- points["nearest_node"] = nearest_nodes
105
- points["distance"] = distances
106
-
107
- dist = nx.multi_source_dijkstra_path_length(
108
- reversed_graph, nearest_nodes, weight=weight_type, cutoff=weight_value_cutoff
109
- )
110
-
111
- graph_points = pd.DataFrame(
112
- data=[{"node": node, "geometry": Point(data["x"], data["y"])} for node, data in nx_graph.nodes(data=True)]
113
- )
114
-
115
- nearest_nodes = pd.DataFrame.from_dict(dist, orient="index", columns=["dist"]).reset_index()
116
-
117
- graph_nodes_gdf = gpd.GeoDataFrame(
118
- graph_points.merge(nearest_nodes, left_on="node", right_on="index", how="left").reset_index(drop=True),
119
- geometry="geometry",
120
- crs=local_crs,
121
- )
122
- graph_nodes_gdf.drop(columns=["index", "node"], inplace=True)
123
- if weight_value_cutoff is None:
124
- weight_value_cutoff = max(nearest_nodes["dist"])
125
- if step_type == "voronoi":
126
- graph_nodes_gdf["dist"] = np.minimum(np.ceil(graph_nodes_gdf["dist"] / step) * step, weight_value_cutoff)
127
- voronois = gpd.GeoDataFrame(geometry=graph_nodes_gdf.voronoi_polygons(), crs=local_crs)
128
- zone_coverages = voronois.sjoin(graph_nodes_gdf).dissolve(by="dist", as_index=False, dropna=False)
129
- zone_coverages = zone_coverages[["dist", "geometry"]].explode(ignore_index=True)
130
- if zone is None:
131
- zone = concave_hull(graph_nodes_gdf[~graph_nodes_gdf["node_to"].isna()].union_all(), ratio=0.5)
132
- else:
133
- zone = zone.to_crs(local_crs)
134
- zone_coverages = zone_coverages.clip(zone).to_crs(original_crs)
135
- else: # step_type == 'separate':
136
- speed = 83.33 # TODO HARDCODED WALK SPEED
137
- weight_value = weight_value_cutoff
138
- zone_coverages = create_separated_dist_polygons(graph_nodes_gdf, weight_value, weight_type, step, speed)
139
- if zone is not None:
140
- zone = zone.to_crs(local_crs)
141
- zone_coverages = zone_coverages.clip(zone).to_crs(original_crs)
142
- return zone_coverages
1
+ from typing import Literal
2
+
3
+ import geopandas as gpd
4
+ import networkx as nx
5
+ import numpy as np
6
+ import pandas as pd
7
+ from pyproj.exceptions import CRSError
8
+ from shapely import Point, concave_hull
9
+
10
+ from objectnat.methods.isochrones.isochrone_utils import create_separated_dist_polygons
11
+ from objectnat.methods.utils.graph_utils import get_closest_nodes_from_gdf, reverse_graph
12
+
13
+
14
+ def get_stepped_graph_coverage(
15
+ gdf_to: gpd.GeoDataFrame,
16
+ nx_graph: nx.Graph,
17
+ weight_type: Literal["time_min", "length_meter"],
18
+ step_type: Literal["voronoi", "separate"],
19
+ weight_value_cutoff: float = None,
20
+ zone: gpd.GeoDataFrame = None,
21
+ step: float = None,
22
+ ):
23
+ """
24
+ Calculate stepped coverage zones from source points through a graph network using Dijkstra's algorithm
25
+ and Voronoi-based or buffer-based isochrone steps.
26
+
27
+ This function combines graph-based accessibility with stepped isochrone logic. It:
28
+ 1. Finds nearest graph nodes for each input point
29
+ 2. Computes reachability for increasing weights (e.g. time or distance) in defined steps
30
+ 3. Generates Voronoi-based or separate buffer zones around network nodes
31
+ 4. Aggregates zones into stepped coverage layers
32
+ 5. Optionally clips results to a boundary zone
33
+
34
+ Parameters:
35
+ gdf_to (gpd.GeoDataFrame):
36
+ Source points from which stepped coverage is calculated.
37
+ nx_graph (nx.Graph):
38
+ NetworkX graph representing the transportation network.
39
+ weight_type (Literal["time_min", "length_meter"]):
40
+ Type of edge weight to use for path calculation:
41
+ - "time_min": Edge travel time in minutes
42
+ - "length_meter": Edge length in meters
43
+ step_type (Literal["voronoi", "separate"]):
44
+ Method for generating stepped zones:
45
+ - "voronoi": Stepped zones based on Voronoi polygons around graph nodes
46
+ - "separate": Independent buffer zones per step
47
+ weight_value_cutoff (float, optional):
48
+ Maximum weight value (e.g., max travel time or distance) to limit the coverage extent.
49
+ zone (gpd.GeoDataFrame, optional):
50
+ Optional boundary polygon to clip resulting stepped zones. If None, concave hull of reachable area is used.
51
+ step (float, optional):
52
+ Step interval for coverage zone construction. Defaults to:
53
+ - 100 meters for distance-based weight
54
+ - 1 minute for time-based weight
55
+
56
+ Returns:
57
+ (gpd.GeoDataFrame): GeoDataFrame with polygons representing stepped coverage zones for each input point,
58
+ annotated by step range.
59
+
60
+ Notes:
61
+ - Input graph must have a valid CRS defined.
62
+ - MultiGraph or MultiDiGraph inputs will be simplified to Graph/DiGraph.
63
+ - Designed for accessibility and spatial equity analyses over multimodal networks.
64
+ """
65
+ if step is None:
66
+ if weight_type == "length_meter":
67
+ step = 100
68
+ else:
69
+ step = 1
70
+ original_crs = gdf_to.crs
71
+ try:
72
+ local_crs = nx_graph.graph["crs"]
73
+ except KeyError as exc:
74
+ raise ValueError("Graph does not have crs attribute") from exc
75
+
76
+ try:
77
+ points = gdf_to.copy()
78
+ points.to_crs(local_crs, inplace=True)
79
+ except CRSError as e:
80
+ raise CRSError(f"Graph crs ({local_crs}) has invalid format.") from e
81
+
82
+ nx_graph, reversed_graph = reverse_graph(nx_graph, weight_type)
83
+
84
+ points.geometry = points.representative_point()
85
+
86
+ distances, nearest_nodes = get_closest_nodes_from_gdf(points, nx_graph)
87
+
88
+ points["nearest_node"] = nearest_nodes
89
+ points["distance"] = distances
90
+
91
+ dist = nx.multi_source_dijkstra_path_length(
92
+ reversed_graph, nearest_nodes, weight=weight_type, cutoff=weight_value_cutoff
93
+ )
94
+
95
+ graph_points = pd.DataFrame(
96
+ data=[{"node": node, "geometry": Point(data["x"], data["y"])} for node, data in nx_graph.nodes(data=True)]
97
+ )
98
+
99
+ nearest_nodes = pd.DataFrame.from_dict(dist, orient="index", columns=["dist"]).reset_index()
100
+
101
+ graph_nodes_gdf = gpd.GeoDataFrame(
102
+ graph_points.merge(nearest_nodes, left_on="node", right_on="index", how="left").reset_index(drop=True),
103
+ geometry="geometry",
104
+ crs=local_crs,
105
+ )
106
+ graph_nodes_gdf.drop(columns=["index", "node"], inplace=True)
107
+ if weight_value_cutoff is None:
108
+ weight_value_cutoff = max(nearest_nodes["dist"])
109
+ if step_type == "voronoi":
110
+ graph_nodes_gdf["dist"] = np.minimum(np.ceil(graph_nodes_gdf["dist"] / step) * step, weight_value_cutoff)
111
+ voronois = gpd.GeoDataFrame(geometry=graph_nodes_gdf.voronoi_polygons(), crs=local_crs)
112
+ zone_coverages = voronois.sjoin(graph_nodes_gdf).dissolve(by="dist", as_index=False, dropna=False)
113
+ zone_coverages = zone_coverages[["dist", "geometry"]].explode(ignore_index=True)
114
+ if zone is None:
115
+ zone = concave_hull(graph_nodes_gdf[~graph_nodes_gdf["node_to"].isna()].union_all(), ratio=0.5)
116
+ else:
117
+ zone = zone.to_crs(local_crs)
118
+ zone_coverages = zone_coverages.clip(zone).to_crs(original_crs)
119
+ else: # step_type == 'separate':
120
+ speed = 83.33 # TODO HARDCODED WALK SPEED
121
+ weight_value = weight_value_cutoff
122
+ zone_coverages = create_separated_dist_polygons(graph_nodes_gdf, weight_value, weight_type, step, speed)
123
+ if zone is not None:
124
+ zone = zone.to_crs(local_crs)
125
+ zone_coverages = zone_coverages.clip(zone).to_crs(original_crs)
126
+ return zone_coverages