gpt4 book ai didi

python - 从 python 中的 osmapi 调用打印出节点信息

转载 作者:太空宇宙 更新时间:2023-11-03 16:59:15 24 4
gpt4 key购买 nike

这是到目前为止我的代码,我想使用从 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()

但是,当我运行这个时,我得到以下内容

<Response [200]>
<Response [200]>
<Response [200]>
................
................
<Response [200]>

但是我想要获得的是如下结果:

< 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 " / >

任何人都可以帮助打印此信息,特别是获取标签变量。在我注释掉打印语句的任何地方,变量都工作正常。

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

最佳答案

您需要内容,node_info只是Response对象,您需要调用.content或.text来查看返回的内容:

打印node_info.content

关于python - 从 python 中的 osmapi 调用打印出节点信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35136966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com