简体   繁体   English

将 OSM 节点转换为纬度/经度

[英]Convert OSM Node to lat/lon

So to briefly describe what I'm doing - I have a CSV of ~65,000 driving routes with start postcodes and end postcodes and I want to get for each route a list of lat/lon coordinates along the route.所以简单描述一下我在做什么 - 我有一个包含开始邮政编码和结束邮政编码的约 65,000 条驾驶路线的 CSV,我想为每条路线获取沿路线的纬度/经度坐标列表。

So my first step was to go to OSRM project API and take out the nodes along a route using the following code所以我的第一步是转到 OSRM 项目 API 并使用以下代码沿路线取出节点

route = requests.get(f'http://router.project-osrm.org/route/v1/driving/{StartLL};{EndLL}?alternatives=false&annotations=nodes')
routejson = route.json()
route_nodes = routejson['routes'][0]['legs'][0]['annotation']['nodes']

Next I now want to take those nodes and convert them to lat/lon coordinates but I've found an API to do this from openstreetmaps, but it will take forever looping through 66,000 records each with a couple of hundred/thousand nodes.接下来,我现在想获取这些节点并将它们转换为纬度/经度坐标,但我已经找到了一个 API 来从 openstreetmaps 中执行此操作,但是它将永远循环遍历 66,000 条记录,每个记录都有几百/千个节点。

for node in route_nodes:
    response_xml = requests.get(f'https://api.openstreetmap.org/api/0.6/node/{node}')
    response_xml_as_string = response_xml.content
    responseXml = ET.fromstring(response_xml_as_string)
    for child in responseXml.iter('node'):
        RouteNodeLL.append((float(child.attrib['lat']), float(child.attrib['lon'])))

I know there's a .osm.pbf file I can download but I have no idea how to extract the nodes out of it.我知道有一个 .osm.pbf 文件可以下载,但我不知道如何从中提取节点。

Is there a way I could do this?有没有办法做到这一点? even if it means completely reworking the logic/idea?即使这意味着完全重新设计逻辑/想法?

I know there's a .osm.pbf file I can download but I have no idea how to extract the nodes out of it.我知道有一个 .osm.pbf 文件可以下载,但我不知道如何从中提取节点。

Take a look at osmium-tool and how to extract objects by ID .看看osmium-tool以及如何通过 ID 提取对象

Quoting from the manual:引用手册:

The following command will get the nodes 17 and 18, the way 42, and the relation 3 out of the file:以下命令将从文件中获取节点 17 和 18、路 42 和关系 3:

 osmium getid input.osm.pbf n17 n18 w42 r3 -o output.osm.pbf

In order to get the osm.pbf file for your region take a look at the OSM wiki, specifically at country and area extracts .为了获得您所在地区的 osm.pbf 文件,请查看 OSM wiki,特别是country and area extracts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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