Creating a Java Application

Hi everybody,

i’m new here and very interested in the osm project and i need some advice:
i have to write a java application using osm. it’s supposed to extract the coordinates from an *.osm file (e.g. a city) and display the roads
in a window. it should also have a simple routing function, e.g. a car (displayed as a dot) is going from one point to another on the streets.
i don’t want any java code, i just would like to hear some ideas how this could be realized. please keep it simple, because i’m not quite familiar with osm xD

The .osm format is pretty easy if you just want to display roads, you just need to read the section on how the WAY and NODE works. Just skip areas, coastlines and relations they are a bit cumbersome.

So you will easily be able to parse a file, get all “nodes”, and one “way” and then draw a Line Vector from the nodes in that way. You only need to draw ways that have the tag k=“highway”. With that you should have a pretty nice application working.

You can get a pretty small example area from:,59.3,18.0,59.31

Routing I know nothing about.

Was that too simple?

I am interested in doing much the same thing- real time offline rendering of OSM maps. I have lots of Java experience, but no experience with OSM.
Is it possible to do real time rendering using osmarender? What sort of strategy would I need to take in order to render less detail as the map is zoomed out (thus increasing speed)? And, even if I change the detail level, will osmarender be fast enough (single user)?

Osmarender is painfully slow, which is something mapnik has over it as it’s lightning quick. Reducing detail in osmarender just involves opening the rule sheet and deleting each rule you don’t want. Really simple…even I can do it. Sorry if I misunderstand the question though, but that’s my quick answer.

Osmarender is a great thing sadly, but what Ben says is very true it’s slow as molasses molasses(which can be fast, but that’s not important). Well to get it to render faster you are going to have to remove some data from the .osm files, simplifying vectors (ways) by removing some nodes from them. This can for example be done with a Douglas-Peucker polyline reduction, there is code in OSM implementing this.

I’m not sure you can ever make XSLT, that’s the thing Osmarender uses, fast.

Great information, thanks for responding so quickly. It looks like I’ll need to write my own rendering code to do this right. That’s what I figured, but I didn’t want to re-invent the wheel if there was already a fast cross platform way to accomplish it.

Have a look at Mapnik or Kosmos for fast rendering. Kosmos being my favorite when it comes to offline rendering of small areas.

yes, I have looked at both, but neither can be bundled inside a standalone java application. For a web app, I could use them.

I’ve been pondering this myself. The Renderer wiki page should list such applications, but I’m not convinced that’s a full list.

There’s Mkgmap, which is pure java aparently. It’s a renderer, although it’s specifically for creating garmin image sets.

I like the configureability of Kosmos, and idea of sharing rendering rules on a wiki page is quite nifty. Just a shame it’s written in .NET really. If it was in java, I think it would attract more community interest. Also it could be bundled into JOSM plugin, meaning you could render your current JOSM view with the click of a button. JKosmos anyone?

Speaking of JOSM, there’s code in there which, used to be called the Mappaint plugin (before it got assimilated into JOSM core). This is kind of a renderer . It’s not exactly a nice polished map, because the output is desgined to be clicked on and edited, rather than viewed as a map, but it’s configureable (elemstyles.xml) and I guess its pure java drawing to the graphics object in realtime. You can see by zooming around, that it must be doing this pretty fast, though less fast if you’re loading a lot of data in.

Perhaps with a bit of java development we could start to blur the lines between editor graphics → rendered map image → slippy map tile images so that rather than figuring out many seperate tools, you can start to do these things with a click of the mouse within JOSM.

I know a fair bit of java, so really I need to stop pondering and start coding.

I read your post as if you wanted to do it all yourself… :slight_smile: Hmm… Need to work on my reading comprehension.

I agree with Harry; have you looked at JOSM? It has OKish rendering, and has already solved all those problems with projections and all that. And it’s a software that can probably use another hand.

IMHO, the best would be to be able to download the slippy map pngs and render blue routes over that…

I’ve tinkered with that- I actually wrote a little java app that downloaded all the tiles within a bounding box. After a while, I started to get worried about slamming the server, so I stopped at zoom 8. It’s certainly easier to implement- since there is already a Swing component for viewing OSM maps on Then, I could just draw routing information or POI on the map using java2d.

Does the OSM community have a problem with the tiles being downloaded in the way I described? I didn’t want to chew up all your bandwidth if you were paying by the Gb or something.

Well… I think we have free Bandwidth from VR.UCL at the moment, but if someone decides to slam the servers…

Be moderate, I’m mean you probably won’t need to download more than a GB… (I remember fretting over downloading 50KB) :slight_smile:

if you want to do the slippy map download here are some posts from the maiinglist.

hmm, if we currently have about 1000th of all possible tiles taking 120GB, then I wonder what percentage in size those tiles are, since I imagine the first 0.1% of tiles which are done are where most people live, and vice versa. So tiles that will just be solid yellow in the sahara, or solid green from the Amazon will be a fraction of the file size, and huge in number. (Does Frederick’s estimation already count for this?)

That leaves me thinking; I wonder, at some point do you think if there is just a huge area of thousands/millions of ‘yellow’ squares in a clump, isn’t there a more efficient way of storing this than each tile?. Not only are they the same for all zooms, bar tile size, but also the same as all the neighbouring tiles.

Plus: this Z18 seems odd. I thought there were 17…?

Btw there is a limit of how much you can download:

Ben: I don’t think they do that optimization yet, but I might be wrong. You can always look at the mapnik rendering code if you want… ;-

Hi Everybody,

New guy here. I am looking for an cross-platform, open source application that will render maps from the planet.osm file and compute routes. Kind of like Microsoft Streets and Trips, but free (as in freedom).

My take away from this thread is that this application does not exist. The closet thing is Kosmos which is written in .NET, is not GPL’d and seems to have a hard architectural limit due to its use of memory (apparently it was written to be a renderer to run beside JOSM).

An alternative starting point would be to use some of the internal code of JOSM.

Am I reading this right? BTW – I found another application called RoadNav that gave me high hopes, but just didn’t cut it…

Hi Dave, it’s out there you just have to believe. (e.g. in Aliens or Pyroute (also on pyroute on the wiki) :slight_smile: I haven’t tested any of the routing applications, I can’t remember their names but there are a couple of options. Please do some research and tell us what works for you…

There are several problems with offline and derived use, mostly there is no good implementation of a killer app… I think once we have someone who have built a good model, you are going to see a lot of other copy cats coming. Just handling the 1GB OSM map data that is Sweden is hard to do atm, and that’s without displaying it.

Maybe there is a really easy way to do it, I just haven’t seen it yet. But you gotta believe that it works, and just do it.

Thanks for the lead on pyroute, I’ll check it out. I shall report back on the state of the tools out there…please stay tuned.

The source is available under some kind of BSD style thing, but there is no VC access.

I’d write something nice in Vala, but I’m not good enough yet.

bump I like this thread. :slight_smile: