Re: [OSM-dev] Downloading OSM data
Hi, Sorry for the late response. Thank you all for your valuable suggestions. I used the urllib module of python to send the request to XAPI url giving bounding box coordinates and read the response. When user runs the script, it prompts the user to enter bbox coordinates and check whether those entered coordinates in lat/long limits and build the URL like below. http://www.informationfreeway.org/api/0.6/map?bbox=*x1,y1,x2,y2* This is working fine. But is is downloading all the data for the given bbox coordinates. If I want to download only selected elements then I need to append filter predicates also to the URL. It would be helpful for me if anyone suggests how to do this by giving GUI for the script instead of prompting user to enter his selection in the command prompt. If any automated tools available with user interface also fine for me. Thanks Phanindra On Fri, Nov 8, 2013 at 8:53 AM, amrit karmacharya wrote: > there is an existing library https://launchpad.net/osmxapi > > > On Fri, Nov 8, 2013 at 7:37 AM, Pierre Béland wrote: > >> Hi Phanindra, >> >> This is a late answer but I took time to test the solution using the >> urllib2 module to send a request to a website and extract data. I give you >> an example with the Overpass API. >> >> Using Overpass is a very interesting solution to extract for a bbox and >> pass the result to Python. It is possible to output in json and then >> convert easily to Python dictionary objects. The python script example >> below uses the urllib2 module to send a request and read the result. >> >> The url contains the instructions sent to the Overpass API. In this >> example, The nodes that have a name Tag are extracted for the given bbox. >> >> In the dictionary, elements contains the list of elements extracted from >> OSM. The string function .decode('utf8') let's decode and print correctly >> the UTF8 characters. >> >> Pierre >> >> Python script >> >> --- >> import urllib2,urllib,json >> # space replaced with + sign >> url=' >> http://overpass.osm.rambler.ru/cgi/interpreter?data=[out:json];(node[name](45.37301118463942,-72.80742645263672,45.416286468478475,-72.71095275878906););out+body >> ;' >> >> try: >> print "try request" >> overpass_response = urllib2.urlopen(url) >> print "info" >> print overpass_response.info() >> #overpass_response = urllib2.urlopen(url_o) >> except urllib2.HTTPError as e: >> # list of error codes at http://docs.python.org/2/howto/urllib2.html >> print('The server couldn\'t fulfill the request.') >> print('Error code: ', e.code, responses[e.code]) >> print urllib2.info() >> except urllib2.URLError as e: >> print('We failed to reach a server.') >> print('Reason: ', e.reason) >> else: >> # everything is fine >> #overpass_response = open(overpass_request) >> #print "apres open" >> overpass_txt=overpass_response.read().decode('utf8') >> overpass_response.close() >> overpass_json = json.loads(overpass_txt) >> >> print "dictionnary elements - we access and print each element of the >> list" >> elements=overpass_json["elements"] >> nb=0 >> for element in elements: >> nb+=1 >> print "\n",nb,"\t",element >> print "\t"+element["type"]+", id="+str(element["id"])+", >> lat="+str(element["lat"])+", lon="+str(element["lon"]) >> if ("name" in element["tags"]): >> print "\tname="+element["tags"]["name"] >> >> >> -- >> *De :* Phanindra Kuchipudi >> *À :* dev@openstreetmap.org >> *Envoyé le :* Lundi 4 novembre 2013 0h26 >> *Objet :* [OSM-dev] Downloading OSM data >> >> Hi, >> >> I want to write a python script to download OSM data based on a given >> bounding box (implementing XAPI). >> Can anyone help me how to develop this script, and also can you give >> information on any other scripts available for this downloading >> functionality? >> >> Thanks, >> Phani >> >> ___ >> dev mailing list >> dev@openstreetmap.org >> https://lists.openstreetmap.org/listinfo/dev >> >> >> >> ___ >> dev mailing list >> dev@openstreetmap.org >> https://lists.openstreetmap.org/listinfo/dev >> >> > ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev
Re: [OSM-dev] Downloading OSM data
there is an existing library https://launchpad.net/osmxapi On Fri, Nov 8, 2013 at 7:37 AM, Pierre Béland wrote: > Hi Phanindra, > > This is a late answer but I took time to test the solution using the > urllib2 module to send a request to a website and extract data. I give you > an example with the Overpass API. > > Using Overpass is a very interesting solution to extract for a bbox and > pass the result to Python. It is possible to output in json and then > convert easily to Python dictionary objects. The python script example > below uses the urllib2 module to send a request and read the result. > > The url contains the instructions sent to the Overpass API. In this > example, The nodes that have a name Tag are extracted for the given bbox. > > In the dictionary, elements contains the list of elements extracted from > OSM. The string function .decode('utf8') let's decode and print correctly > the UTF8 characters. > > Pierre > > Python script > > --- > import urllib2,urllib,json > # space replaced with + sign > url=' > http://overpass.osm.rambler.ru/cgi/interpreter?data=[out:json];(node[name](45.37301118463942,-72.80742645263672,45.416286468478475,-72.71095275878906););out+body > ;' > > try: > print "try request" > overpass_response = urllib2.urlopen(url) > print "info" > print overpass_response.info() > #overpass_response = urllib2.urlopen(url_o) > except urllib2.HTTPError as e: > # list of error codes at http://docs.python.org/2/howto/urllib2.html > print('The server couldn\'t fulfill the request.') > print('Error code: ', e.code, responses[e.code]) > print urllib2.info() > except urllib2.URLError as e: > print('We failed to reach a server.') > print('Reason: ', e.reason) > else: > # everything is fine > #overpass_response = open(overpass_request) > #print "apres open" > overpass_txt=overpass_response.read().decode('utf8') > overpass_response.close() > overpass_json = json.loads(overpass_txt) > > print "dictionnary elements - we access and print each element of the > list" > elements=overpass_json["elements"] > nb=0 > for element in elements: > nb+=1 > print "\n",nb,"\t",element > print "\t"+element["type"]+", id="+str(element["id"])+", > lat="+str(element["lat"])+", lon="+str(element["lon"]) > if ("name" in element["tags"]): > print "\tname="+element["tags"]["name"] > > > -- > *De :* Phanindra Kuchipudi > *À :* dev@openstreetmap.org > *Envoyé le :* Lundi 4 novembre 2013 0h26 > *Objet :* [OSM-dev] Downloading OSM data > > Hi, > > I want to write a python script to download OSM data based on a given > bounding box (implementing XAPI). > Can anyone help me how to develop this script, and also can you give > information on any other scripts available for this downloading > functionality? > > Thanks, > Phani > > ___ > dev mailing list > dev@openstreetmap.org > https://lists.openstreetmap.org/listinfo/dev > > > > ___ > dev mailing list > dev@openstreetmap.org > https://lists.openstreetmap.org/listinfo/dev > > ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev
Re: [OSM-dev] Downloading OSM data
Hi Phanindra, This is a late answer but I took time to test the solution using the urllib2 module to send a request to a website and extract data. I give you an example with the Overpass API. Using Overpass is a very interesting solution to extract for a bbox and pass the result to Python. It is possible to output in json and then convert easily to Python dictionary objects. The python script example below uses the urllib2 module to send a request and read the result. The url contains the instructions sent to the Overpass API. In this example, The nodes that have a name Tag are extracted for the given bbox. In the dictionary, elements contains the list of elements extracted from OSM. The string function .decode('utf8') let's decode and print correctly the UTF8 characters. Pierre Python script --- import urllib2,urllib,json # space replaced with + sign url='http://overpass.osm.rambler.ru/cgi/interpreter?data=[out:json];(node[name](45.37301118463942,-72.80742645263672,45.416286468478475,-72.71095275878906););out+body;' try: print "try request" overpass_response = urllib2.urlopen(url) print "info" print overpass_response.info() #overpass_response = urllib2.urlopen(url_o) except urllib2.HTTPError as e: # list of error codes at http://docs.python.org/2/howto/urllib2.html print('The server couldn\'t fulfill the request.') print('Error code: ', e.code, responses[e.code]) print urllib2.info() except urllib2.URLError as e: print('We failed to reach a server.') print('Reason: ', e.reason) else: # everything is fine #overpass_response = open(overpass_request) #print "apres open" overpass_txt=overpass_response.read().decode('utf8') overpass_response.close() overpass_json = json.loads(overpass_txt) print "dictionnary elements - we access and print each element of the list" elements=overpass_json["elements"] nb=0 for element in elements: nb+=1 print "\n",nb,"\t",element print "\t"+element["type"]+", id="+str(element["id"])+", lat="+str(element["lat"])+", lon="+str(element["lon"]) if ("name" in element["tags"]): print "\tname="+element["tags"]["name"] De : Phanindra Kuchipudi À : dev@openstreetmap.org Envoyé le : Lundi 4 novembre 2013 0h26 Objet : [OSM-dev] Downloading OSM data Hi, I want to write a python script to download OSM data based on a given bounding box (implementing XAPI). Can anyone help me how to develop this script, and also can you give information on any other scripts available for this downloading functionality? Thanks, Phani ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev
Re: [OSM-dev] Downloading OSM data
On Mon, Nov 4, 2013 at 12:26 AM, Phanindra Kuchipudi wrote: > Hi, > > I want to write a python script to download OSM data based on a given > bounding box (implementing XAPI). > Can anyone help me how to develop this script, and also can you give > information on any other scripts available for this downloading > functionality? There are several ways to get up-to-date OpenStreetMap data. Please tell us approximately what is your bounding box / area of interest, and how often do you expect to request an update? Your answers will suggest which tools we point you towards. ___ dev mailing list dev@openstreetmap.org https://lists.openstreetmap.org/listinfo/dev