Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get lon-lat coordinates from node id(OSMnx)?

I am new to this osmnx python lib. I want to know angle deviation between points. So, I tried to know lon-lan coordinates from OSM points ID. But I cannot do it. Anyone to tell me how to get coordinates from OSM points ID?

like image 480
Namkyu Kang Avatar asked Jun 30 '17 05:06

Namkyu Kang


1 Answers

If I understand correctly, you're asking how to use OSMnx to retrieve the lat-long coordinates of a set of OSM node IDs in some graph. First create your graph. As it is a networkx multidigraph, you can use any of the built-in networkx methods to access your node attributes. Alternatively, as stated in its documentation, you can use OSMnx to dump your nodes to a geopandas GeoDataFrame and work with it pandas-style:

import osmnx as ox
G = ox.graph_from_place('Piedmont, California, USA', network_type='drive')
nodes = ox.graph_to_gdfs(G, edges=False)
nodes[['x', 'y']]

The resulting nodes GeoDataFrame is indexed by OSM ID and contains x and y values representing the nodes' longitude and latitude. See also this question/answer.

like image 128
gboeing Avatar answered Oct 01 '22 23:10

gboeing