简体   繁体   中英

How to convert GeoJSON to NetworkX graph

I have a GeoJSON file that records a city's roads geocodes and their attributes. Sample looks like this

{"type":"FeatureCollection", "features": [
{"type":"Feature","geometry":
{"type":"LineString","coordinates":[[lat1, long1],[lat2, long2],[lat3, long3]]},
"properties":{"ROUTE_TYPE":,"TOTAL_LANE":,"AADT":}}}}

In this case, how can I convert such JSON to a networkX graph? Ideally a DiGraph (I do notice that direction information is not indicted in the JSON at all. I am fine with assuming all links are bidirectional.)

This question is similar to the following question on GIS stackexchange: Retrieving OpenStreetMap data with Python using GeoJSON geometry as boundary and its answer .

The main ingredients you need are the following:

  1. geopandas to parse the geojson into a GeoDataFrame with read_file
  2. OSMnx to transform the GeoDataFrame into a networkx.MultiDiGraph using osmnx.utils_graph.graph_from_gdfs

Alternatively, you could use ignore_geometry=True in the first step and use nx.from_pandas_edgelist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM