Here is a snippet of my code so far
import osmapi
import geopy
from geopy.geocoders import Nominatim
import requests
import xmltodict
geolocator = Nominatim()
location = geolocator.reverse("{}, {}".format(lat, lon))
dict = location.raw
osmid = dict.get('osm_id', 'default_value_if_null_here')
osmtype = dict.get('osm_type', 'default_value_if_null_here')
if(osmtype == 'node'):
node_info = requests.get("http://api.openstreetmap.org/api/0.6/node/"+ osmid)
d = xmltodict.parse(node_info.content)
amenity_tags = [tag for tag in d['osm']['node']['tag'] if tag['@k'] == 'amenity']
if len(amenity_tags) != 0:
print amenity_tags
I basically want to check if a location is corresponding to a node on openstreetmap and if so, check if it is an amenity and what type of amenity. A Sample output is as follows:
[OrderedDict([(u'@k', u'amenity'), (u'@v', u'cafe')])]
[OrderedDict([(u'@k', u'amenity'), (u'@v', u'fast_food')])]
[OrderedDict([(u'@k', u'amenity'), (u'@v', u'bicycle_parking')])]
[OrderedDict([(u'@k', u'amenity'), (u'@v', u'atm')])]
[OrderedDict([(u'@k', u'amenity'), (u'@v', u'restaurant')])]
[OrderedDict([(u'@k', u'amenity'), (u'@v', u'restaurant')])]
[OrderedDict([(u'@k', u'amenity'), (u'@v', u'theatre')])]
My question is how would I split up this ordered dictionary. The outcome I am hoping for is to have a variable 'amenity_type' = cafe, restaurant, theatre etc... I really hope I have explained what my question is well enough. I am new to python so any help would be appreciated, thanks!