momepy.nx_to_gdf#
- momepy.nx_to_gdf(net, points=True, lines=True, spatial_weights=False, nodeID='nodeID')[source]#
Convert a
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.
- Parameters:
- netnetworkx.Graph
A
networkx.Graphobject.- pointsbool (default is
True) Export point-based gdf representing intersections. When converting continuity-based graph generated using
momepy.coins_to_nx(),pointsrepresent edges with no associated geometry.- linesbool (default is
True) Export line-based gdf representing streets or continuity strokes.
- spatial_weightsbool (default is
False) Set to
Trueto export a libpysal spatial weights for nodes (only for primal graphs).- nodeIDstr
The name of the node ID column to be generated.
- Returns:
- GeoDataFrame
The Selected gdf or tuple of both gdfs or tuple of gdfs and weights.
See also
Examples
>>> 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