OpenStreetMap Forum

The Free Wiki World Map

You are not logged in.

#1 2009-02-24 21:46:22

xintao
Member
Registered: 2009-02-19
Posts: 46

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/tr … 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.

Offline

#2 2009-02-24 22:26:21

emj
Member
From: .se (59.3N17.99E) 0735969076
Registered: 2006-06-18
Posts: 949

Re: Get the OSM XML data Programatically

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?

Last edited by emj (2009-02-24 22:27:18)

Offline

#3 2009-02-24 22:55:06

xintao
Member
Registered: 2009-02-19
Posts: 46

Re: Get the OSM XML data Programatically

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

Last edited by xintao (2009-02-24 22:56:37)

Offline

#4 2009-02-24 23:04:18

xintao
Member
Registered: 2009-02-19
Posts: 46

Re: Get the OSM XML data Programatically

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

Last edited by xintao (2009-02-24 23:05:55)

Offline

#5 2009-02-24 23:18:51

PHerison
Member
From: Rhein-Main
Registered: 2008-04-04
Posts: 1,460

Re: Get the OSM XML data Programatically

xintao wrote:

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.

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.

xintao wrote:

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.

You mean something like the Data-Layer (click on blue "+" on the right side of the map):
http://www.openstreetmap.org/?lat=50.05 … rs=B000FTT

Last edited by PHerison (2009-02-24 23:19:54)

Offline

#6 2009-02-24 23:21:35

Lambertus
Administrator
From: Apeldoorn (NL)
Registered: 2007-03-17
Posts: 3,269
Website

Re: Get the OSM XML data Programatically

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.


Mapping tools: Garmin GPSmap 60CSx, Giant Terrago 2002

Offline

#7 2009-02-24 23:34:38

emj
Member
From: .se (59.3N17.99E) 0735969076
Registered: 2006-06-18
Posts: 949

Re: Get the OSM XML data Programatically

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.

Offline

#8 2009-02-25 16:37:59

xintao
Member
Registered: 2009-02-19
Posts: 46

Re: Get the OSM XML data Programatically

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/ma … 543,48.145, where the bbox is the extent of Sweden?

Thank you very much.

Yours sincerely,
Xintao

Offline

#9 2009-02-25 17:07:06

Lambertus
Administrator
From: Apeldoorn (NL)
Registered: 2007-03-17
Posts: 3,269
Website

Re: Get the OSM XML data Programatically

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.


Mapping tools: Garmin GPSmap 60CSx, Giant Terrago 2002

Offline

#10 2009-02-25 19:15:35

emj
Member
From: .se (59.3N17.99E) 0735969076
Registered: 2006-06-18
Posts: 949

Re: Get the OSM XML data Programatically

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.. :-) I.e. they are in germany, the UK and Sweden.

Last edited by emj (2009-02-25 19:16:24)

Offline

#11 2009-02-26 16:08:24

xintao
Member
Registered: 2009-02-19
Posts: 46

Re: Get the OSM XML data Programatically

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

Offline

#12 2009-02-26 20:36:14

xintao
Member
Registered: 2009-02-19
Posts: 46

Re: Get the OSM XML data Programatically

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

Last edited by xintao (2009-02-26 20:36:42)

Offline

#13 2009-02-27 00:08:10

emj
Member
From: .se (59.3N17.99E) 0735969076
Registered: 2006-06-18
Posts: 949

Re: Get the OSM XML data Programatically

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.

Last edited by emj (2009-02-27 00:14:05)

Offline

Board footer

Powered by FluxBB