【问题标题】:How can I get a list of (lat, lon) pairs for a way in a single call to the OSM API?如何在一次调用 OSM API 时获取 (lat, lon) 对的列表?
【发布时间】:2014-10-07 10:58:21
【问题描述】:

鉴于 OSM 中 Way 的 ID,我想获取 (lat, lon) 对的列表。

如果我通过标准 API 请求方式,我会得到一个节点 ID 列表:

$ curl 'http://www.openstreetmap.org/api/0.6/way/158602261'
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" ...>
 <way id="158602261" visible="true" ...>
  <nd ref="295505187"/>
  <nd ref="1736599935"/>
  <nd ref="295505112"/>
  ...
</osm>

然后我可以对这些节点中的每一个进行后续查询:

$ curl 'http://www.openstreetmap.org/api/0.6/node/295505187'
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" ...>
  <node id="295505187" visible="true" ... lat="37.7702484" lon="-122.5107188"/>
</osm>

但这将需要许多 API 请求,路径中的每个节点一个。

是否可以使用更少的 API 调用来获取纬度/经度列表?最好只打一个电话。

【问题讨论】:

    标签: openstreetmap overpass-api


    【解决方案1】:

    我不确定这是否可以使用普通的 OSM API 来完成,但可以使用 Overpass API 的递归向下语句来完成:

    $ curl 'http://overpass.osm.rambler.ru/cgi/interpreter?data=%5Bout:json%5D;(way(158602261);%3E;);out;'
    {
      "version": 0.6,
      "generator": "Overpass API",
      ...
      "elements": [
    
    {
      "type": "node",
      "id": 30677708,
      "lat": 37.7712040,
      "lon": -122.5108280
    },
    {
      "type": "node",
      "id": 30677709,
      "lat": 37.7730278,
      "lon": -122.4715596
    },
    ...
    {
      "type": "way",
      "id": 158602261,
      "nodes": [
        295505187,
        1736599935,
        295505112,
        295505186,
        ...
      ]
    }
      ]
    }
    

    【讨论】:

      【解决方案2】:

      只需将 /full 附加到 URL,例如http://www.openstreetmap.org/api/0.6/way/158602261/full.

      【讨论】:

        【解决方案3】:

        由于您明确要求提供单向 ID 的纬度/经度对列表,您可以使用 Overpass API CSV 输出模式。

        [out:csv(::lat,::lon;false)];
        way(158602261);>;out;
        

        (标题行被“false”抑制)

        结果:

        37.7712040  -122.5108280
        37.7730278  -122.4715596
        37.7733457  -122.4652858
        37.7746245  -122.4547306
        37.7664503  -122.4531098
        ...
        

        立交桥涡轮链接:http://overpass-turbo.eu/s/6NG

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多