1

I am using OSMnx to get clean intersections from OpenStreetMaps road network. The intersection nodes are currently in (x,y) coordinates, but I want to plot them using lat lon coordinates.

From the example Jupiter notebook, OSMnx Example #14 Clean Intersection Cluster Nodes, I am able to get the street network and call ox.clean_intersections to produce the clean intersections.

import osmnx as ox, matplotlib.pyplot as plt, numpy as np
ox.config(use_cache=True, log_console=True)
%matplotlib inline

# get a street network and plot it with all edge intersections
address = '2700 Shattuck Ave, Berkeley, CA'
G = ox.graph_from_address(address, network_type='drive', distance=750)
G_proj = ox.project_graph(G)

# clean up the intersections and extract their xy coords
intersections = ox.clean_intersections(G_proj, tolerance=15, dead_ends=False)
 points = np.array([point.xy for point in intersections])

I get a Panda Geoseries of the intersections, which looks like this:

0       POINT (564152.437121744 4189596.945341664)
1      POINT (564846.6779513165 4189615.534235776)
2      POINT (564571.2116373706 4189601.780093061)

Since the clean intersections are comprised of the centroids of clusters of merged nodes, they don't correspond to any particular node with an osm_id (which have lat lon coordinates).

How can I convert these (x,y) points to lat lon coordinates?

Lily He
  • 13
  • 5

1 Answers1

2

You projected the graph to meters to clean the intersections with a sensible tolerance parameter. Now you just need to project the cleaned intersection centroids back to lat-long:

import geopandas as gpd
gdf = gpd.GeoDataFrame(geometry=intersections)
gdf.crs = G_proj.graph['crs']
ox.project_gdf(gdf, to_latlong=True)
gboeing
  • 5,691
  • 2
  • 15
  • 41
  • As in [osmnx-examples](https://github.com/gboeing/osmnx-examples/blob/master/notebooks/14-clean-intersection-node-clusters.ipynb) this does "not alter or integrate with the network's topology". Is there a way to build a new cleaned network.. not just get a list of points without edges? – JHuw Dec 10 '18 at 19:51
  • Yes, recent releases of OSMnx have replaced the old `clean_intersections` function with a new powerful `consolidate_intersections` function that rebuilds the cleaned graph. See [the docs](https://osmnx.readthedocs.io/en/stable/osmnx.html#osmnx.simplification.consolidate_intersections) for details. See also this [related answer](https://stackoverflow.com/a/63317800/7321942). – gboeing Aug 08 '20 at 16:38