0

I am new to OSM API, I want to get the coordinates using OSM id. In this question here I didn't get how to create the graph G as I am a beginner. I am using python to get the response from OSM API. for example, when we access this link with the proper id: https://api.openstreetmap.org/api/0.6/node/1989098258, we get an xml response containing all we want ! Could you give me a good example of how to use node API please ?

marOne
  • 129
  • 2
  • 13

1 Answers1

0

I found how to get an information about a given OSM node. First install osmapi package using pip3:

pip3 install osmapi

then for example a node id=1989098258 we do

import osmapi as osm
api = osm.OsmApi() # this instantiate the OsmApi class,
# it has many function, we will use NodeGet function.
# For more detail about it check the doc
# http://osmapi.metaodi.ch/#osmapi.OsmApi.OsmApi.NodeGet
node = api.NodeGet(1989098258)
node # will return a dict object

object node returns:

{'id': 1989098258,
 'visible': True,
 'version': 2,
 'changeset': 16442326,
 'timestamp': datetime.datetime(2013, 6, 6, 10, 11, 58),
 'user': 'wambacher',
 'uid': 201359,
 'lat': 24.3655948,
 'lon': 88.6279164,
 'tag': {}}

then to get longitude and latitude of node do:

node["lon"] # get longitude
node["lat"] # get latitude
marOne
  • 129
  • 2
  • 13
  • 2
    Notice that the OSM API is for editing the map, not for general data processing. Read the terms of use here: https://wiki.openstreetmap.org/wiki/API#Terms_of_use . You may want to look at the Overpass API, or at using downloaded database extracts. – Ture Pålsson Mar 15 '19 at 18:18
  • Thanks for your comment, I am getting node id from xml file, I parse it and I get `lon` and `lat` from each node. Why would I download a database ? – marOne Mar 15 '19 at 18:25
  • 1
    When you do api.NodeGet, you are sending requests to the OSM editing servers. You should avoid doing that, unless you are actually editing the map. – Ture Pålsson Mar 15 '19 at 18:34
  • Ah ok didn't pay attention thanks, do you know any other alternative to read OSM data ? – marOne Mar 15 '19 at 18:39
  • 2
    If you intent do perform a large number of queries against this API then better download an extract and perform your queries locally. As already suggested by @TurePålsson. – scai Mar 18 '19 at 12:18
  • Thank you for your comment @scai. I m not doing a large number of queries, it was just for test purpose. – marOne Mar 19 '19 at 01:34