在python中从osmapi调用输出节点信息

2024-03-29 14:10:44 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我目前为止的代码,我想使用从flickr图像中获取的细节,并找出地理位置是否连接到一个节点。然后我想使用osmapi来获取节点信息。在

import flickrapi
import osmapi
import overpy
import geopy
from geopy.geocoders import Nominatim
import requests

api_key = "xxxxxxxxxxxxxxxxxxxxx"
secret_api_key = "xxxxxxx"
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'])
        tags = (photo.attrib['tags']).encode('utf-8')
        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'])

        geolocator = Nominatim()
        location = geolocator.reverse("{}, {}".format(lat, lon))
        #print(location.raw)
        dict = location.raw
        osmid = dict.get('osm_id', 'default_value_if_null_here')
        osmtype = dict.get('osm_type', 'default_value_if_null_here')
        #print osmid
        #print osmtype

        if(osmtype == 'node'):
            node_info = requests.get("http://api.openstreetmap.org/api/0.6/node/"+ osmid)
            print node_info

obtainImages()

但是,当我运行这个程序时,我得到以下信息

^{pr2}$

然而,我想得到的结果如下:

< node id =" 592637238 " lat =" 47.1675211 " lon =" 9.5089882 "
       version ="2" changeset =" 6628391 "
       user =" phinret " uid =" 135921 "
       timestamp =" 2010 -12 -11 T19:20:16Z " >
   < tag k=" amenity " v=" bar " / >
   < tag k=" name " v=" Black Pearl " / >

有谁能帮忙把这些信息打印出来,特别是得到标签变量吗。在我注释掉print语句的任何地方,变量都可以正常工作。在

提前感谢您的帮助,我真的很感激,因为我是python新手


Tags: keyimportapi信息idnodeurltags