0

I am new to python and openstreetmap API and I would really appreciate any help in structuring a call that would return me information such as the following for a node:

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

From my code that I have already written I have the lat and lon of the node at my disposal, along with the osm_id(obtained through nominatim). I don't think the osm_id is the same as the node id but correct me if I am wrong! If anyone can help me in structuring a call that would return this info for a node it would be greatly appreciated thank you!

RyanKilkelly
  • 279
  • 1
  • 4
  • 15
  • 1
    The osm_ids returned in Nominatim are indeed the node / way / relation ids in OSM, depending on the "osm_type" returned. So you may just issue a simple http get to the osm server like `http://api.openstreetmap.org/api/0.6/node/592637238` to retrieve the information. – headuck Jan 30 '16 at 15:54
  • @headluck Would i simply call it as follows : node_info = http://api.openstreetmap.org/api/0.6/node/osm_id, where osm_id is my variable? Sorry for my silly question but I am literally not knowledgeable about this topic. I have imported osmapi. Thanks for your help – RyanKilkelly Jan 30 '16 at 16:03
  • 1
    No, for using http get in python: http://stackoverflow.com/questions/645312/what-is-the-quickest-way-to-http-get-in-python and for parsing xml: http://stackoverflow.com/questions/1912434/how-do-i-parse-xml-in-python – headuck Jan 30 '16 at 16:14

1 Answers1

0

If you're using python, you can use the existing osmapi library, which is a wrapper around the OpenStreetMap API. Check the documentation for all the possibilities.

With this in place, you could simply call its NodeGet function:

import osmapi
api = osmapi.OsmApi()
print api.NodeGet(592637238)

Which then returns a python dictionary:

{u'changeset': 8990559,
 u'id': 592637238,
 u'lat': 47.1674699,
 u'lon': 9.5091057,
 u'tag': {u'amenity': u'bar', u'name': u'Black Pearl'},
 u'timestamp': u'2011-08-11T22:26:07Z',
 u'uid': 135921,
 u'user': u'phinret',
 u'version': 3,
 u'visible': True}

Disclaimer: I'm the maintainer of osmapi.

Odi
  • 6,916
  • 3
  • 34
  • 52