简体   繁体   English

无法通过Python使用Overpass API打印查询

[英]Failing to print query using Overpass API with Python

This is my code so far, I am using the flickrapi to obtain images with lat and lon, then using the overpass api in flickr to find info about the nodes at this location. 到目前为止,这是我的代码,我正在使用flickrapi获取带有lat和lon的图像,然后在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()

The flickr api aspect is working perfectly, if I try to print any of the variables it all works. 如果我尝试打印任何变量,则flickr api方面运行良好,并且一切正常。 Also min_lat and min_lon all work when printed. min_lat和min_lon都可以在打印时使用。

However although there are no errors, my query is returning no results.Lat and min_lat print once and only once and then the program continues running but does nothing else and prints nothing else 但是,尽管没有错误,但我的查询没有返回任何结果。lat和min_lat仅打印一次,然后程序继续运行,但不执行任何操作并且不执行其他任何操作

Has anyone any suggestions as to why this may be? 有谁对这可能是为什么的任何建议? Any help would be greatly appreciated as I am a newbie! 由于我是新手,任何帮助将不胜感激!

The problem is that you are querying huge datasets, this will make the query take a lot of time. 问题在于您正在查询庞大的数据集,这将使查询花费大量时间。

For example, I queried just one image from flickr, and your script produced this query: 例如,我仅从flickr中查询了一张图像,您的脚本生成了以下查询:

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

There are 51162 results. 51162个结果。 You are querying every available node in a 2890 square kilometers box, see here for an illustration: http://bl.ocks.org/d/3d4865b71194101b9473 您正在2890平方千米的框中查询每个可用节点,请参见此处的插图: http : //bl.ocks.org/d/3d4865b71194101b9473

To get a better understanding of how changes (even "little" ones like +/- 0.25) to longitude and latitude affect the outcome I suggest that you take a look at this post over at GIS Stackexchange: https://gis.stackexchange.com/a/8655/12310 为了更好地了解经度和纬度的变化(甚至是+/- 0.25之类的“小”变化)如何影响结果,我建议您在GIS Stackexchange上查看以下文章: https://gis.stackexchange。 com / a / 8655/12310

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

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