OSMNx:使用OSM ID获取节点的坐标 [英] OSMNx : get coordinates of nodes using OSM id

查看:1204
本文介绍了OSMNx:使用OSM ID获取节点的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Python库OSMNx在城市旅行的多个步骤之间绘制了一条最佳路线.最终变量是 OSM ID列表.

I used the Python library OSMNx to draw an optimal route between several steps of a city trip. The final variable is a list of OSM ids.

现在,我正在尝试将此路由另存为shp或json文件.问题是我需要每个节点的纬度/经度,但是我没有找到OSMNx函数来做到这一点.

Now, I'm trying to save this route as a shp or json files. The problem is that I need for that the latitude/longitude of each node, but I didn't found an OSMNx function to do that.

我尝试了get_route_edge_attributes(但是坐标不是此函数的有效属性).有什么方法可以获取具有此单个ID的OSM节点的坐标?

I tried get_route_edge_attributes (but coordinates are not a valid attribute for this function). There is any way to get coordinates of an OSM node with this single id ?

谢谢.

推荐答案

,您具有Graph中每个节点和边的所有属性.您可以使用以下方法获取节点属性:

you have all the attribute of each node and edge in the Graph. you can get node attributes using:

G.node[38862848]
#out: {'highway': nan,
# 'lat': 45.3210533,
# 'lon': -122.9790558,
# 'osmid': '38862848',
# 'ref': nan,
# 'x': 501641.47862882155,
# 'y': 5018616.5723966481}

G.node[38862848]['lat']
# out: 45.3210533

并使用G[u][v]获取边缘属性:

G[5035130880][4963510289]
# out: 
#{0: {'bridge': 'yes',
#  'geometry': <shapely.geometry.linestring.LineString at 0x7f90ad7d5860>,
#  'highway': 'secondary',
#  'length': 671.332597496,
#  'name': 'Northwest 185th Avenue',
#  'oneway': False,
#  'osmid': [124454683, 24446714, 124454682]}}

所有属性也都在图形的GeoDataFrame中. 如果您有节点列表,那么获取所有节点的几何图形的最简单方法是:

All attributes are also in GeoDataFrame's of the graph. If you have list of nodes, the easiest way to get the geometry of all nodes is:

import osmnx as ox
import networkx as nx

gdf_nodes, gdf_edges = ox.graph_to_gdfs()
path = nx.shortest_path(G, G.nodes()[0], G.nodes()[1])
gdf_nodes.loc[path]
#out: 
#        highway    lat lon    osmid    ref x   y   geometry    traffic_signals
#5035130880 NaN 45.5637 -122.868    5035130880  NaN 510334  5.04558e+06 POINT (510334.0390091945 5045583.999886028) 0
#4963510289 NaN 45.5698 -122.868    4963510289  NaN 510329  5.04625e+06 POINT (510329.3114555664 5046254.728223645) 0
# ... 

输出是一个GeoDataFrame.

the output is a GeoDataFrame.

这篇关于OSMNx:使用OSM ID获取节点的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆