Skip to content

Commit

Permalink
osmnx compat
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfleis committed Feb 3, 2024
1 parent 2ceac22 commit e8df8ec
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions momepy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def _generate_primal(graph, gdf_network, fields, multigraph, oneway_column=None)
else:
graph.add_edge(first, last, **attributes)

node_attrs = {node: {"x": node[0], "y": node[1]} for node in graph.nodes}
nx.set_node_attributes(graph, node_attrs)


def _generate_dual(graph, gdf_network, fields, angles, multigraph, angle):
"""Generate a dual graph. Helper for ``gdf_to_nx``."""
Expand Down Expand Up @@ -150,6 +153,7 @@ def gdf_to_nx(
angles=True,
angle="angle",
oneway_column=None,
integer_labels=False,
):
"""
Convert a LineString GeoDataFrame to a ``networkx.MultiGraph`` or other
Expand Down Expand Up @@ -188,6 +192,10 @@ def gdf_to_nx(
path traversal by specifying the boolean column in the GeoDataFrame. Note,
that the reverse conversion ``nx_to_gdf(gdf_to_nx(gdf, directed=True,
oneway_column="oneway"))`` will contain additional duplicated geometries.
integer_labels : bool, default False
Convert node labels to integers. By default, node labels are tuples with (x, y)
coordinates. Set to True to encode them as integers. Note that the x, and y
coordinates are always preserved as node attributes.
Returns
-------
Expand Down Expand Up @@ -273,6 +281,9 @@ def gdf_to_nx(
f"Approach '{approach}' is not supported. Use 'primal' or 'dual'."
)

if integer_labels:
net = nx.convert_node_labels_to_integers(net)

Check warning on line 285 in momepy/utils.py

View check run for this annotation

Codecov / codecov/patch

momepy/utils.py#L285

Added line #L285 was not covered by tests

return net


Expand Down

0 comments on commit e8df8ec

Please sign in to comment.