momepy.nx_to_gdf¶
-
momepy.
nx_to_gdf
(net, points=True, lines=True, spatial_weights=False, nodeID='nodeID')[source]¶ Convert
networkx.Graph
to LineString GeoDataFrame and Point GeoDataFrame.Automatically detects an
approach
of the graph and assignes edges and nodes to relevant geometry type.See the User Guide page Converting from GeoDataFrame to Graph and back for details.
- Parameters
- netnetworkx.Graph
networkx.Graph
- pointsbool
export point-based gdf representing intersections
- linesbool
export line-based gdf representing streets
- spatial_weightsbool
export libpysal spatial weights for nodes (only for primal graphs)
- nodeIDstr
name of node ID column to be generated
- Returns
- GeoDataFrame
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 primal Graph to points as intersections and lines as street segments:
>>> points, lines = momepy.nx_to_gdf(G) >>> 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 relationship between points/nodes as libpysal W object:
>>> points, lines, W = momepy.nx_to_gdf(G, spatial_weights=True) >>> W <libpysal.weights.weights.W object at 0x7f8d01837210>
Converting dual Graph to lines. Dual Graph does not export edges to GDF:
>>> G = momepy.gdf_to_nx(df, approach="dual") >>> lines = momepy.nx_to_gdf(G) >>> 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