- momepy.nx_to_gdf(net, points=True, lines=True, spatial_weights=False, nodeID='nodeID')#
networkx.Graphto a LineString GeoDataFrame and Point GeoDataFrame.
Automatically detects an
approachof the graph and assigns edges and nodes to relevant geometry type.
See the User Guide page Converting from GeoDataFrame to Graph and back for details.
- pointsbool (default is
Export point-based gdf representing intersections.
- linesbool (default is
Export line-based gdf representing streets.
- spatial_weightsbool (default is
Trueto export a libpysal spatial weights for nodes (only for primal graphs).
The name of the node ID column to be generated.
The Selected gdf or tuple of both gdfs or tuple of gdfs and weights.
>>> import geopandas as gpd >>> df = gpd.read_file(momepy.datasets.get_path('bubenec'), layer='streets') >>> df.head(2) geometry 0 LINESTRING (1603585.640 6464428.774, 1603413.2... 1 LINESTRING (1603268.502 6464060.781, 1603296.8... >>> G = momepy.gdf_to_nx(df)
Converting the primal Graph to points as intersections and lines as street segments:
>>> points, lines = momepy.nx_to_gdf(graph) >>> points.head(2) nodeID geometry 0 1 POINT (1603585.640 6464428.774) 1 2 POINT (1603413.206 6464228.730) >>> lines.head(2) geometry mm_len node_start node_end 0 LINESTRING (1603585.640... 264.103950 1 2 1 LINESTRING (1603561.740... 70.020202 1 9
Storing the relationship between points/nodes as a libpysal W object:
>>> points, lines, W = momepy.nx_to_gdf(graph, spatial_weights=True) >>> W <libpysal.weights.weights.W object at 0x7f8d01837210>
Converting the dual Graph to lines. The dual Graph does not export edges to GDF:
>>> G = momepy.gdf_to_nx(df, approach="dual") >>> lines = momepy.nx_to_gdf(graph) >>> lines.head(2) geometry mm_len 0 LINESTRING (1603585.640 6464428.774, 1603413.2... 264.103950 1 LINESTRING (1603607.303 6464181.853, 1603592.8... 199.746503