0

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!

RyanKilkelly
  • 279
  • 1
  • 4
  • 15
  • How exactly are you running the python script? In an IDE, from console, any other way? – chrki Jan 31 '16 at 16:22
  • Can you strip all the flickr stuff out and make a simple call to the overpass API with a lat-long and get a result? As it stands we can't run it without a flickr API key and all that might not be relevant. – Spacedman Jan 31 '16 at 16:24
  • @chrki I'm running it on pycharm IDE and I am also using python 2.7 – RyanKilkelly Jan 31 '16 at 16:26
  • So is your program hanging at the overpass API call? Does overpass do rate-limiting, and you've hit a limit? Or is it trying to download megabytes of data and just taking ages? – Spacedman Jan 31 '16 at 16:30
  • @Spacedman I just ran it with manually inputted lat and lon such as the following query = ("node(50.745,7.17,50.75,7.18);out;") and it has ran as I want it to! So it must be something to do with either the way the lat and lon are inputted or maybe even the type of the lat and lon. If I ran it before it was just hanging at the API cal but giving no errors – RyanKilkelly Jan 31 '16 at 16:38
  • print query *before* the API call hangs and see what it is... – Spacedman Jan 31 '16 at 16:45

1 Answers1

1

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

Community
  • 1
  • 1
chrki
  • 6,143
  • 6
  • 35
  • 55