简体   繁体   中英

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.

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. Also min_lat and min_lon all work when printed.

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

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:

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

There are 51162 results. You are querying every available node in a 2890 square kilometers box, see here for an illustration: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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