【问题标题】:Failing to print query using Overpass API with Python使用 Overpass API 和 Python 打印查询失败
【发布时间】:2016-01-31 16:20:00
【问题描述】:

到目前为止,这是我的代码,我正在使用 flickrapi 获取具有纬度和经度的图像,然后使用 flickr 中的 overpass api 来查找有关此位置节点的信息。

import flickrapi
import overpy

api_key = "xxxxxxxxxxxxxxxxxxx"
secret_api_key = "xxxxxxxx"
flickr = flickrapi.FlickrAPI(api_key, secret_api_key)

def obtainImages():

    photo_list = flickr.photos.search(api_key=api_key, accuracy = 15, has_geo=1, per_page = 100, extras = 'tags, url_s')

    for photo in photo_list[0]:

        id = str(photo.attrib['id'])
        url = str(photo.attrib['url_s'])
        title = (photo.attrib['title']).encode('utf-8')

        photo_location = flickr.photos_geo_getLocation(photo_id=photo.attrib['id'])
        lat = float(photo_location[0][0].attrib['latitude'])
        lon = float(photo_location[0][0].attrib['longitude'])

        max_lat = lat + 0.25
        min_lat = lat - 0.25
        max_lon = lon + 0.25
        min_lon = lon - 0.25


        print lat
        print min_lat
        api = overpy.Overpass()
        query = "node(%s, %s, %s, %s);out;" % ( min_lat, min_lon, max_lat, max_lon )
        result = api.query(query)
        print query
        print len(result.nodes)

obtainImages()

flickr api 方面运行良好,如果我尝试打印任何变量,它都可以正常工作。打印时 min_lat 和 min_lon 也都有效。

然而,虽然没有错误,但我的查询没有返回任何结果。Lat 和 min_lat 打印一次,并且只打印一次,然后程序继续运行,但什么也不做,也不打印任何其他内容

有人对这可能的原因有任何建议吗?任何帮助将不胜感激,因为我是新手!

【问题讨论】:

  • 你究竟是如何运行 python 脚本的?在 IDE 中,从控制台,还有其他方式吗?
  • 你能去掉所有 flickr 的东西,然后用 lat-long 简单地调用 overpass API 并得到结果吗?就目前而言,我们无法在没有 flickr API 密钥的情况下运行它,而且所有这些都可能不相关。
  • @chrki 我在 pycharm IDE 上运行它,我也在使用 python 2.7
  • 那么你的程序是否挂在了立交桥 API 调用上?立交桥做限速,你已经达到了限制?还是它试图下载数兆字节的数据并且只需要很长时间?
  • @Spacedman 我只是使用手动输入的 lat 和 lon 运行它,例如以下查询 = ("node(50.745,7.17,50.75,7.18);out;") 它已经按照我的意愿运行它到!因此,它必须与输入 lat 和 lon 的方式有关,甚至可能与 lat 和 lon 的类型有关。如果我在它只是挂在 API cal 上但没有给出错误之前运行它

标签: python nodes openstreetmap overpass-api


【解决方案1】:

问题是您正在查询 巨大 数据集,这会使查询花费大量时间。

例如,我只从 flickr 查询了一张图片,而您的脚本产生了以下查询:

node(20.820875, -87.027648, 21.320875, -86.527648);out;

51162 个结果。您正在查询 2890 平方公里框中的每个可用节点,请参阅此处以获取说明:http://bl.ocks.org/d/3d4865b71194101b9473

为了更好地了解经度和纬度的变化(即使是 +/- 0.25 之类的“小”变化)如何影响结果,我建议您在 GIS Stackexchange 上查看这篇文章:https://gis.stackexchange.com/a/8655/12310

【讨论】:

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