Running my own OpenStreetMap server

UK map generated on my OSM server

UK map generated on my OSM server

After using OpenStreetMap in a fairly limited way for the past year or so, essentially just to upload data/tracks from wandering around Ethiopia, I thought I’d have a closer look, especially as a possible replacement for Google Maps which I was using a lot whilst at the OU.

Firstly I looked at how I could use OSM and the OpenLayers API as an alternative for the map in my Online Users Map – which certainly looks feasible. So I’m now thinking about making this an option in the block settings, as shouldn’t be too much work to provide the option.

I also set up my own open street map server (instructions for installing on Ubuntu Lucid Lynx). Although quite a long process everything worked well first time with no errors. I didn’t download the entire 8Gb+ OSM dataset to generate my tiles, rather I just selected a much smaller area of detailed data (using extracts from GeoFabrik and CloudMade). This avoided the potential ’30 hours or longer’ process of importing the world into my database – the whole dataset for Ethiopia took less than 30 seconds to import.

The only part where I ran into a problem was at the very end when I wanted to generate all the tiles. When I ran ./generate_tiles.py I kept getting an error telling me that osm-local.xml didn’t exist. Fortunately this was quite an easy fix, I just needed to edit ~/bin/mapnik/generate_tiles.py to point to ~/bin/mapnik/osm.xml instead, then all ran fine (generating 55Mb+ of png images).

I could then create an alias in my Apache to point to my generated tiles and create a slippy map using OpenLayer and the tiles generated on my desktop.

I still have a lot to learn about all this, especially with what can be done with Mapnik for generating tiles (and the python script necessary to achieve it) and using OpenLayers as a replacement for Google Maps API – but all going well so far :-)

18 Comments

  1. bryan says:

    Did you setup mod_tile also?

  2. Alex says:

    No, I didn’t set up mod_tile. I just generated all the images into a directory and mapped this onto an alias in my apache config – nothing very sophisticated :-)

  3. bryan says:

    I didn’t realize that would work. Is that as straight forward as it sounds? If so, you are my new best friend.

  4. Alex says:

    Basically, yes I think it is that simple!When you copy the generated images over, just be sure to preserve the file structure and it works just as if serving up a static website. You’d need to manually update the files (overwrite them all) if you regenerated the images – or set up a script to copy them over regularly – but as a one-off should work fine :-)

  5. Kent says:

    Alex, I tried to setup an OSM setver using the same instrucitons you did. Everythig seemed to work fine except the generate_image.py resulted in an image that doesn’t render. No errors were thrown… do you have any ideas what I might have done wrong?

  6. Alex says:

    When you say if doesn’t render – do you mean it’s just a grey image – or does an error message appear when you try to display the image?

  7. Kent says:

    image.png file is created but when I try to view it in IE it shows the red X. The image is there and I do File/Open in IE to load it. The file size is 19 MB.

  8. Alex says:

    The image size seems far far too big to me. There should be a lot of images of much smaller filesize. I suspect that rather than creating lots of individual images, something is wrong with the script making it append each image to the end of the last one – hence why you get such a large file and that it won’t open.

  9. Ivip says:

    Alex do you think is possible to use OpenStreetMap with Mapnik and tiles passed to OpenLayers all on one own server?

  10. Alex says:

    Yes – certainly possible to run everything on your own server (tiles & openlayers). I tested this on my local machine (with internet disconnected) and all worked well.

  11. Andrea says:

    Hi, I didn’t understand if now you can edit your osm database with JOSM or not. I read that JOSM access by design to the OpenStreetMap API Server. If i want to edit directly my OSM Database with JOSM i think that i have two chances:

    - Edit the OSM Database with JOSM, re-import tham with osmosis and create tiles
    - Create an Api Server with i can edit my JOSM Database Directly

    It’s right?

    There is an How To for creating an Api Server?

    Best Regards

  12. Alex says:

    Hi Andrea,
    Sorry I’m not sure if you can use JOSM to edit your own version of OSM if you installed an API server. I would assume that it is possible, but not sure how you would go about it. Otherwise yes, another option is to edit OSM database and then re-import.
    Alex

  13. Andrea says:

    Did you use JOSM to edit your OSM files? I need to draw the route of a car on a lot of roads that already exist in the my osm file (Italian country osm files). For your experience is it possibile with JOSM?

  14. Alex says:

    I use JOSM to edit the main OSM database yes. Usually I open my files from my GPS tracks and then edit the OSM database.
    Alex

  15. tiru says:

    Hello,

    I read about openstreetmap on how to build own server. However, I am completely confused about the different pieces in the puzzle. Hope you can help me in this area. I want to create a server so that third party web sites can display maps in their website by making API calls to set points and popup window info just like google map apis using geocodes. In order to achieve this on my own hardware what components I need. I see example to generate .png locally using mapnik but that won;t help third party people, because they need zoom in zoomout feature. BTW, no route calculation no address search. Just showing a custom icon on a map using geocodes. Nothing more nothing less.
    I am sure I need OSM data extract for the country(s) and create postgres DB. What other components are need to enable API access to my own server and render maps on third party sites? . Like maps.yahoo.com or maps.google.com do some sliding/zoomin/zoomout etc..

    Any reply is greatly appreciated.

    Thanks,

  16. Alex says:

    Hi Tiru,
    It’s been a little while since I’ve looked at any of this stuff, so there may be updated (better) tools now than I used for creating my server. However, essentially what you want to do is create a tile-server. So install the open street map server first (on your local machine), then download the OSM data for the countries/areas you want to display on your map. Then generate all the tiles (images) for your data set – this creates a static directory structure of images which you can upload to your web server (you can specify the zoom details you want to include in this tile generation, but if you’re trying to cover a large geographical area and/or lots of zoom levels it will create many 1000′s of images).
    You can then use the OpenLayers API and point to your new tile server and all the images will be loaded from the images you have created.
    That’s the basics as far as I understand it – I think it can get much more complex though if you want to specify the ‘style’ of the map tile rendered and/or if you want automatic updating of the tile images from updates made to the OSM dataset.
    At first best to test out with a very small data set as it can all take a long time to process.
    Hope that helps,Cheers, Alex

  17. tiru says:

    Thank you Mr.Alex. Thank you. Just curious, what is mapnik purpose?

  18. Alex says:

    Mapnik is basically the toolkit which will generate the map images from the dataset,
    Cheers, Alex

Leave a Reply

*