Get the OSM XML data Programatically

Hi, all,

We can access the OSM data using this method: link to http://api.openstreetmap.org/api/0.5/trackpoints?bbox=0,51.5,0.25,51.75, and then save the XML data file to local hard disk. Then we can analyze the XML data according to the data format. For exmaple, we can extract the nodes and ways from the XML data for analysis.

Now my question is: given my local server can run ASP (JSP) code, and also I have embed openstreetmap in my web mashup, so I can get the bounds of current Openstreetmap view, just like (0,51.5,0.25,51.75). Based on this, how can I get the corresponding OSM XML data Programatically in my web mashup? That is to say, I want to get the XML map data using ASP or JSP code in webpage.

Any of your adive and reply are highly appreciated and anticipated.

Yours sincerely,

Xintao

P.S. I also post this content to the mailing list, sorr for the cross sending.

ASP is usually MS Basic, JSP is usually Java, quite a big difference.

What do you mean by: OSM XML data Programatically? Do you want to do something similar to what is done with ways in the data browser, e.g. the Finnish Swedish border?

Hi, emj, thanks for you kind reply and help, thank you.

Okay, suppose we are looking through the openstreetmap website http://www.openstreetmap.org. Everytime we zoom in/out or drag the map window, different map contents, including nodes and ways, will display, right? The different map contents are the OSM XML data that I mentioned.

What I want to know is: everytime we change the map window, we can get the corresponding map extent. According to the map extent, how to get the correponding OSM XML data in ASP (or JSP, any tool can do it) web page which has embeded the openstreetmap using code?

I mean that to get the map contents, is to downlaod the OSM XML data file, or just read them into memory.

If I am not clear, please do not heistate to let me know. I can explain it until it is clear. I really want to figure it out.

Thank you so much!

Yours sincerely,

Xintao

Hi, emj, I think I should explain my question in this way:

Would you please open this website: http://www.openrouteservice.org/? Okay, this is a web mashup which embed the openstreetmap using OpenLayers functions. In this website, you can get a route path using the tools left side of the web page.

Okay, everytime the webpage construct the route path, it needs to get the map data based on the current map view, right? So, it needs to access the OSM map data in current map view correspondingly, am I right? Therefore, it needs to download or read the corresponding OSM map data programatically everytime, right?

What I want to know is: how can they do it? What is the specific method?

Thank you.

Yours,
Xintao

Not realy. What you see are PNG-Files (images) which had been generated from the OSM-Data previously. The PNG-Files are created for each zoomlevel. So what you see is not the real-time database content.

You mean something like the Data-Layer (click on blue “+” on the right side of the map):
http://www.openstreetmap.org/?lat=50.05582&lon=8.38766&zoom=17&layers=B000FTT

You’ve got that misunderstood. Webmashups like openrouteservice.org and yournavigation.org store (part of) a copy of the OpenStreetMap database in their own format on their mashup server. The slippy map is coming from the OpenStreetMap servers and the route data is queried from the mashup server but drawn on top of the slippy map.

The web mashups read the OSM map data mostly only once a week when the latest OpenStreetMap database dump becomes available.

If a mashup starts generating a significant load on the OpenStreetMap slippy map tile servers then they are supposed to host their own slippy map tiles.

Lambertus did a similar service yournavigation, which basically it works like this (Lots of things might be different):

  1. web client ask for a route betwwen pos1 and pos2
  2. a server side php script parses
  3. php script invokes gosmore to route between pos1 and pos2
  4. gosmore will choose the ways that are best suited
  5. gosmore will then gather all the nodes that you need to travel through
  6. these will be outputed to the PHP script which converts them for web consumation.
  7. the web client gets these nodes and then draws them with standard openlayers.

The most important part for you is, “gosmore”, it’s an application that will take the openstreetmap data and create a custom database from it which it later uses for creatingroutes. It’s done like this:

  1. download and configure gosmore
  2. download planet.osm
  3. parse planet.osm output database
  4. run gosmore with database.

Thanks emj, Lambertus and PHerison, you have helped a lot! Thank you again.

By the way, the database dump is a very huge database. The total size is up to 9.7 gigabytes! If I want to get the data of Sweden, how can I do it? Should I download the latest planet and relation from http://planet.openstreetmap.org/, and then extract the aear data from it? Or I can use this method: http://api.openstreetmap.org/api/0.5/map?bbox=11.54,48.14,11.543,48.145, where the bbox is the extent of Sweden?

Thank you very much.

Yours sincerely,
Xintao

If you look at the wiki page about the planet dump that I gave you, then you see a list of sites providing extracts/excerpts of the planet file that you can download. If that’s not good enough, then you can use tools like Osmosis to extract your specific bbox from the planet file.

Actually it’s just 6.5GB, that’s not big, and the Swedish extract is about 900MB uncompressed, the Swedish extract takes ~10 minutes to process on my low end laptop from 2004. I’m sure you have some resources for processing geographic data at Gävle College, considering Gävle is the HQ of the Swedish land survey (Lantmäteriet, same as Ordnance Survey in the UK).

By the way all these bounding boxes you post are they actually connected to something? They seem very random… :slight_smile: I.e. they are in germany, the UK and Sweden.

Thanks Lambertus and emj, I have downloaded Osmosis, it is very good. Thank you.

Hi, emj, you are so familiar with Gävle, Sweden. It seems I can learn a lot from you…:-). By the way, the bounding box I post is just the example form OpenStreetMap API demo. You said you have extracted the Sweden map data, so do you have the Sweden bounding polygon, or you just use the bounding box of Sweden? Thank you.

Best regards,
Xintao

Hi, emj, sorry for disturbing you. I use this command line to extract the data for Sweden:

java -jar osmosis.jar --rx planet-090225.osm.gz --bp boundSweden.txt --wx Sweden.osm

The content of boundSweden.txt are shown below:
boundSweden.txt
1
11.559358 55.724143
25.270296 55.724143
25.270296 68.909109
11.559358 68.909109
11.559358 55.724143
END
END

I took more than one hour to finish the work, and the OSM data file is up to 1.3 gegabytes. Did I do something wrong? Thank you!

Best regards,
Xintao

No, not at all Xin! I used the already available extract of sweden… That extract is made with a much more complex polygon and the resulting .osm is just 500MB. Your method is better, remmeber that you can get updates.