![]() |
GeoDataFrame extends the functionality of pandas to deal with spatial data. They have special features and functions that are useful in Geographic Information Systems (GIS). In this article, we will see how we can convert MultiDiGraph to GeoDataFrame using OSMnx module. Syntax of osmnx.utils_graph.graph_to_gdfs() FunctionOSMnx utils_graph module (graph_to_gdfs) facilitates the conversion of MultiDiGraph (node/edge) to GeoDataFrames. The OSMnx functionality is as follows:
Getting Sample MultiDiGraphNow let’s get into the implementation. Here we need an input graph, which is of type MultiDiGraph. We can get it by giving the address to osmnx module, graph_from_place. The code is shown below.
<networkx.classes.multidigraph.MultiDiGraph at 0x178933df040> We can get a better idea by plotting it.
Output ![]() plot multidigraph Fetch the nodes
Output
Fetch the edges
Output
Convert MultiDiGraph to GeoDataFrame Using OSMnx utils_graph ModuleNow you have a basic idea about the generated MultiDigraph. It’s time to make use of OSMnx functionality to convert multidigraph to geodataframe. We can extract nodes, edges or both as geodataframe using the graph_to_gdfs functionality. Let’s convert both nodes and edges together. The code as follows:
Output Geodataframe (nodes and edges) In the above example, we fetched both nodes and edges by setting the required params as True (nodes and edges). The below code extracts nodes and its corresponding geometry.
Output Geodataframe – Nodes with geometry As a next step we extract edges as geodataframe, by setting edge parameter as True.
Output ![]() Edges as Geodataframe Let’s check the type of the generated output
Output geopandas.geodataframe.GeoDataFrame We can review the generated geodataframe edges in map using geopandas.
Output ![]() geodataframe in a map |
Reffered: https://www.geeksforgeeks.org
Python |
Related |
---|
![]() |
![]() |
![]() |
|
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |