Make your first map

make your first map with your OpenStreetMap tile server
OpenStreetMap provides Free geodata and Free Software tools to use that data. A previous article demonstrates building an OpenStreetMap tile server. This article demonstrates populating it with OpenStreetMap geodata and having your server create a nice picture of a map for you.

It's a big world and the data provided by OpenStreetMap reflects that. While the world isn't getting any larger, the data provided by OpenStreetMap is getting larger. From 2004 to 2009 the data set doubled in size approximately every six months. In March 2009 there were approximately 330 million objects in the database.

map of North America with shaded area related to article
To duplicate every function of OpenStreetMap for the entire globe is a substantial undertaking and requires substantial infrastructure investment. This article covers an interesting but limited set of functions and can be accomplished without building a data centre. The goal is to use a 2006 era PC to create a tile server for a selected area of the planet. To build a tile server for the complete database requires a substantial server.

I've chosen an area in North America that includes Montreal on the east, Washington DC on the south, Minneapolis on the West and Lake Superior on the north. I'm going to have to remember

--bbox -94,38,-71.5,50

your mileage will vary.

If it happens that you are interested in an area that is also a single political boundary, you may find that somebody has already made a database extract for you. Check for one that you like in the list of sources of extracts.

Updates

Changes to Mapnik have rendered portions of this tutorial outdated. Be sure to check the README files.

Import data

We put many of the software tools in place in an earlier article. Now we need to load the OpenStreetMap data so that we can use it. There are several approaches that you might take. You might just load all of the OpenStreetMap data at once. That will not be covered in this article as it requires a substantial server. The goals of this article are more modest. We'll look at using Osmosis to import a reduced planet file to OpenStreetMap.

Install dependencies for Osmosis.

sudo apt-get install sun-java6-jdk
This should return without errors.

Get latest osmosis and install it.

wget http://gweb.bretth.com/osmosis-latest.tar.gz
tar xvfz osmosis-latest.tar.gz
cd osmosis-0.30

Your version number may vary.

Apply bounding box to planet file.

This reduces the size of the planet file to only the area we will import.
./bin/osmosis --read-xml /home/username/planet-090311.osm.gz --bounding-box left=-94 bottom=38 right=-71.5 top=50 --write-xml /home/username/GreatLakes.osm.gz
This will take some time.

-or-

Import a complete extract. Extracts exist for countries and sates in the USA. This one is from CloudMade.com If your interest lies in a single jurisdiction, one of these extracts may be just right for you.

Import the data

Okay, we've acquired the data and trimmed it to a reasonable size. Now we import it to the local OpenStreetMap PostGIS database. The length of time required will increase with larger datasets and slower computer and less RAM. Count on this running over night. For kicks use the time command to find the duration of this activity.
time ./osm2pgsql --slim -d gis GreatLakes.osm.gz
And this will take a while as well. But you can watch the out progress similar to below.

Using projection SRS 900913 (Spherical Mercator)
Setting up table: planet_osm_point
Setting up table: planet_osm_line
Setting up table: planet_osm_polygon
Setting up table: planet_osm_roads

Reading in file: ../planet-090311.osm
Processing: Node(319877k) Way(11648k) Relation(0k)

Test it! - Make your first map

This is what the tile server is all about, turning data in to images. Okay, let's not get ahead of ourselves here. There are a lot of moving pieces and they all have to be working to get what we expect. When things go wrong, we can get things that are just subtly wrong, or they can be completely Bozo. So one piece at a time.

Test the coastlines

You'll need to edit ~/mapnik/set-mapnik-env to let it know that your database is called "gis" not "osm" as shown here.

# This is the name of the database where the OSM data is stored.
export MAPNIK_DBNAME='osm'

Change it to gis. You should not need to make any other changes in ~/mapnik/set-mapnik-env.

Make a testing copy of one of the default files.
cd ~/mapnik
cp generate_tiles.py z0_generate_tiles.py

Edit your copy ~/mapnik/z0_generate_tiles.py

    #-------------------------------------------------------------------------
    #
    # Change the following for different bounding boxes and zoom levels
    #
    # Start with an overview
    # World
    bbox = (-180.0,-90.0, 180.0,90.0)

    render_tiles(bbox, mapfile, tile_dir, 0, 5, "World")

Change the 5 to a zero for now. Disable the render_tiles lines that follow this section by adding a # at the beginning of each line. You want a quick test render at first. Save it.

Set up and execute the render with these three commands. Do not omit the leading periods on lines two and three.
source set-mapnik-env
./customize-mapnik-map >$MAPNIK_MAP_FILE
./z0_generate_tiles.py

The last line above should generate the five following lines.

render_tiles( (-180.0, -90.0, 180.0, 90.0) /home/username/mapnik/osm.xml /home/username/mapnik/tiles/ 0 0 World )
World [ 0 - 0 ]:  0 0 0 p: (-180.0, -85.051128779806589) (180.0, 85.051128779806604) 
World [ 0 - 0 ]:  0 0 1 p: (-180.0, -89.990752516489039) (180.0, -85.051128779806589) 
World [ 0 - 0 ]:  0 1 0 p: (180.0, -85.051128779806589) (540.0, 85.051128779806604)  
World [ 0 - 0 ]:  0 1 1 p: (180.0, -89.990752516489039) (540.0, -85.051128779806589) 

And more importantly, the script will have created your first four map tiles in the ~/mapnik/tiles directory tree. Go have a look now at ~/mapnik/tiles/0/0/0.png It should be a little tiny map of the World. Like this.

If so, pat yourself on the back. Your tile server has just created tiles to serve.
You'll probably stop reading here and run off to do more rendering. I understand. Come back and finish the article later. You are giddy with your new mappy-server-ish-ness. And who would deny you that joy? Not I, good neo-cartographer, not I.

What if it didn't work?

No little World map? Not to worry. Did you get a tile at all? Perhaps an all blue tile of about 1209 bytes? Double check the World Boundaries section in http://weait.com/content/build-your-own-openstreetmap-server . The files from three sources should all end up in the ~/mapnik/world_boundaries directory. Not in ~/mapnik. When you are ready to try again, delete the tiles/0/0/0.png first. The script won't replace a tile that exists.

Did you get a warning or error when you rendered tiles? Use #osm or comments below to discuss. I'll put more debugging into the article as we go.

Test your area of interest

What? It did work? And you are still reading this? Fantastic. Glad to have you back after your celebration. Now is a good time to check your area of interest for map data beyond the outlines of the continents.

Make a copy of generate_image.py for your area of interest.
cp generate_image.py my_generate_image.py

Edit my_generate_image.py . It contains a block of comments in the middle, with some default rendering instructions.

#---------------------------------------------------
#  Change this to the bounding box you want
#
ll = (-6.5, 49.5, 2.1, 59)
#---------------------------------------------------

z = 10
imgx = 500 * z
imgy = 1000 * z

Change the bounding box ll = to your bounding box for your area of interest. Change the constants from 500 and 1000 to 50 each.

imgx = 50 * z
imgy = 50 * z

Save it.

Set up and execute the render with these three commands. Do not omit the leading periods on lines two and three.
source set-mapnik-env
./customize-mapnik-map >$MAPNIK_MAP_FILE
./my_generate_image.py

This should return without errors and create a new file, ~/mapnik/image.png Go have a look. I'll be right here listening for your exclamations of delight. Here the one from my example.
first area map to check data upload

How was that? Easy, right?

Update your data

Who am I kidding? You won't read this far today. You're off rendering the planet to zoom = infinity[1]. Updates will go in the next article.

Credits and References

Map image cc-by-sa OpenStreetMap and contributors
http://wiki.openstreetmap.org/
The great gang at #osm and the talk mailing list.
Thanks to bretth, cmarqu_ and firefishy
Thanks to Steve Coast.
Thanks dbaker for copy editing and clarifying suggestions.

[1] Try to resist the temptation to render to the planet to scale 1:1. You'll have trouble finding a printer large enough, and if you print it, where would you put it?

AttachmentSize
z0_generate_tiles.py4.1 KB
my_generate_image.py1.41 KB

I followed your steps except

I followed your steps except download the latest planet file. I downloaded an osm file from cloudmade for my country. everything works ok up until the rendering part
where I get this error:
UserWarning: PSQL error:
FATAL: database "osm" does not exist in layer 'leisure'

Oops, database "osm" does not exist.

Hi Anonymous,

I seem to have missed a step for you, Anonymous. I apologize. I'll add this to the article as well.

You'll need to edit ~/mapnik/set-mapnik-env to let it know that your database is called "gis" not "osm". As shown here.

# This is the name of the database where the OSM data is stored.
export MAPNIK_DBNAME='gis'

With that done you should be ready to go.

mine still failed

Mine still failed even though I got the database name correct but I managed to fix it.

Two things are of interest to note here:

1. The username character was screwed up for me inside the set-mapnik-env. Instead of my username being surrounded by happy quotes, it was surrounded by angry (`) quotes; its on the tilde key but I don't know the name. I had to change that to quotes for it to work.

2. I got the exact same error:

FATAL: database "gis" does not exist in layer 'leisure' and I found out a fix. Simply edit your pg_hba.conf file: (for me intrepid):
sudo gedit /etc/postgresql/8.3/main/pg_hba.conf

and change (if you are indeed using this on local host only I presume):
#local all all ident sameuser
to:
local all all trust

and change:
host all all 127.0.0.1/32 md5
to:
host all all 127.0.0.1/32 trust

Don't forget to restart:
sudo /etc/init.d/postgresql-8.3 restart

And by damn it worked!

Reason I decided to post:
This was the only tutorial that worked ;-)

Glad you were able to

Glad you were able to struggle through. I'm uncertain if you've opened the local postgres permissions too much by your changes in pg_hba.conf.

About the "angry quotes". That's just about as good a name for them as any. I've heard them called "backticks" as well.

In set-mapnik-env, the backticks are deliberately different from the regular single quotes and regular double quotes used elsewhere in set-mapnik-env. They are not an error in set-mapnik-env. set-mapnik-env uses backticks around the bash command whoami to use the current username of the user who invoked the set-mapnik-env when accessing the gis database.

From the Bash Beginner's Guide

Command substitution allows the output of a command to replace the command itself. Command substitution occurs when a command is enclosed like this:

$(command)

or like this using backticks:

`command`

Bash performs the expansion by executing COMMAND and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting.

franky ~> echo `date`
Thu Feb 6 10:06:20 CET 2003

When the old-style backquoted form of substitution is used, backslash retains its literal meaning except when followed by "$", "`", or "\". The first backticks not preceded by a backslash terminates the command substitution. When using the "$(COMMAND)" form, all characters between the parentheses make up the command; none are treated specially.

Command substitutions may be nested. To nest when using the backquoted form, escape the inner backticks with backslashes.

If the substitution appears within double quotes, word splitting and file name expansion are not performed on the results.

make you first map error

I was trying building our own server ,
when I run this command , i got out of memory error,an idea?

./bin/osmosis --read-xml /home/administrator/Downloads/planet-090408.osm.bz2 --bounding-box left=-94 bottom=38 right=-71.5 top=50 --write-xml /home/administrator/GreatLakes.osm.gz
24/04/2009 2:12:52 PM com.bretth.osmosis.core.Osmosis run
INFO: Osmosis Version 0.30
24/04/2009 2:12:52 PM com.bretth.osmosis.core.Osmosis run
INFO: Preparing pipeline.
24/04/2009 2:12:52 PM com.bretth.osmosis.core.Osmosis run
INFO: Launching pipeline execution.
24/04/2009 2:12:52 PM com.bretth.osmosis.core.Osmosis run
INFO: Pipeline executing, waiting for completion.
24/04/2009 3:30:09 PM com.bretth.osmosis.core.pipeline.common.ActiveTaskManager waitForCompletion
SEVERE: Thread for task 1-read-xml failed
java.lang.OutOfMemoryError: Java heap space
at com.bretth.osmosis.core.filter.common.ListIdTracker.extendIdList(ListIdTracker.java:66)
at com.bretth.osmosis.core.filter.common.ListIdTracker.set(ListIdTracker.java:117)
at com.bretth.osmosis.core.filter.v0_5.AreaFilter.process(AreaFilter.java:120)
at com.bretth.osmosis.core.container.v0_5.NodeContainer.process(NodeContainer.java:58)
at com.bretth.osmosis.core.filter.v0_5.AreaFilter.process(AreaFilter.java:82)
at com.bretth.osmosis.core.xml.v0_5.impl.NodeElementProcessor.end(NodeElementProcessor.java:103)
at com.bretth.osmosis.core.xml.v0_5.impl.OsmHandler.endElement(OsmHandler.java:109)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1774)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2930)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
at com.bretth.osmosis.core.xml.v0_5.XmlReader.run(XmlReader.java:109)
at java.lang.Thread.run(Thread.java:619)
24/04/2009 3:30:09 PM com.bretth.osmosis.core.Osmosis main
SEVERE: Execution aborted.
com.bretth.osmosis.core.OsmosisRuntimeException: One or more tasks failed.
at com.bretth.osmosis.core.pipeline.common.Pipeline.waitForCompletion(Pipeline.java:146)
at com.bretth.osmosis.core.Osmosis.run(Osmosis.java:85)
at com.bretth.osmosis.core.Osmosis.main(Osmosis.java:30)

Error at Rendering

Hi,
I am following this article step by step
But when I try this command I get this error
user@PC1:~/mapnik$ source set-mapnik-env
bash: #!/bin/sh: No such file or directory,
please help

and also one more question what do u mean by:
"
Do not omit the leading "periods" on lines two and three.
source set-mapnik-env
./customize-mapnik-map >$MAPNIK_MAP_FILE
./z0_generate_tiles.py
"

thanks and great tutorial

bash: #!/bin/sh: No such

bash: #!/bin/sh: No such file or directory sounds like your system doesn't link /bin/sh to /bin/bash. Which distribution of Linux are you using? And which shell?

You might fix this with a symbolic link

ln -s /bin/sh /bin/bash

what do u mean by ...

Lines two and three of that next group of steps each begin with [dot][slash]. Don't omit the [dot] or the [slash] at the beginning of line. They tell bash to look for those command beginning in the present working directory.

Good luck. Come back and let us know if that does it for you?

bash: #!/bin/sh: No such

I use Ubuntu 8.10, , now i updated it to interpid ubuntu...

user@PC1:~$ ln -s /bin/sh /bin/bash
ln: creating symbolic link `/bin/bash': File exists

I tried this:
userr@PC1:~/mapnik$ source set-mapnik-env
bash: #!/bin/bash: No such file or directory
userr@PC1:~/mapnik$ sudo source set-mapnik-env
[sudo] password for user:
sudo: source: command not found

what can done to solve it?

thanks

bash: #!/bin/sh: No such

do u think that I missed step of the instruction here:
http://trac.mapnik.org/wiki/UbuntuInstallation

I followed ur instructions at : http://weait.com/content/build-your-own-openstreetmap-server

thanks

Try each of these to see

Try each of these to see where bash, and sh are installed.
which bash
which sh

good luck

Pink PNG Image

Worked through your excellent tutorial and everything went fine -- except I get a strange pink image when I generate tiles or images. For the tiles, I think I can see the world map as it is opening but then just a pink checkered image. For the generate image I get my map, but again a pink checkered background. Have checked the internet (some type of png corruption) but to no avail. Any idea's? Again thanks for the GREAT tutorial.

Oh, the old "pink Image"

Oh, the old "pink Image" trick? That's obviously a result of, umm. Nope, I have no idea.

You say For the tiles, I think I can see the world map as it is opening but then just a pink checkered image. Could you try viewing the image with a different image viewer? Perhaps open the png-file with firefox? Other ideas, and I'm just fumbling around in the dark here, make sure that you have all of your packages up to date?

Please consider putting one or more of these pink tiles somewhere on the net and linking to them so we can see what you are seeing. And be sure to update on this as you progress with troubleshooting.

More info about pink tile

Thanks for the reply. Here is some more info.
1. Here is a link showing the images: http://sites.google.com/site/jmjira/Home
2. The pink map and tile is rendered on a Mac G5, PPC processor, Ubuntu LTS. Subsequently I downloaded and installed mapnik on my Intel MacBook to see if I would get pink tiles. The result is the first image.
3. I suspected that the problem might be in the way the world_boundaries shape files were rendering, so I copied the shape files from my MacBook to my G5. Thought this might solve the problem. Back to the drawing board. I thought maybe it might be a png library problem, so I reinstalled every library that seemed like it had to do with PNG's. I have checked the folder structure on each machine and they are the same. About the only other thing that I can think of is that I did not install Imagemagick on the G5 (the machine that is rendering pink tiles) at the very start of the install - this is because I had previously installed mapnik - before reading your tutorial. Anyway I got a Conversion error, and found out that I needed to install Imagemagick. I did and that got rid of the Conversion error, but not the pink tiles.

I really hate to re-install mapnik and the whole shebang because installing Mapnik on the PPC G5 / Ubuntu was really a big pain. Not as bad as on Mac OS X though.

If anyone has any ideas, just point me in the right direction.

Thanks.

Tile Rendering Problems

I have been following your tutorials carefully, and except for a few problems (of my own) and one I can't still figure out (pink tiles on Mac G5 Circa 2006) everything has worked well. I encourage those who are interested to follow along. Anyway I have a few more questions.
1.) At the start of this exercise we downloaded LAMP and was wondering how this fits into the grand plan. Am I missing something?
2.) I have been experimenting around with generate_tiles.py to get my tiles rendered. I am having difficulty with understanding the script, specifically toward the end. Now I understand that I should change the bounding box per my parameters. But, what are all the references to Europe and city's like Muenchen? Could you give me an example of what my generate_tiles.py script should look like if I want to render zoom levels 12-18 with a bbox = (-82.141, 41.665, -81.31, 41.116) i.e. Cleveland, Ohio. ? The approach I'd like to take is at this link: http://wiki.openstreetmap.org/wiki/Creating_your_own_tiles:
"Creating tiles using Mapnik and generate_tiles.py
This is the method used by, for example, the OSM cycle map. Its main advantage is that nothing needs to run on the webserver - it just needs a directory of image files. So, for example, you can install all the software on your home PC, and transfer the tiles to your webhost when you're finished.
* Download the planet file from planet.openstreetmap.org
* Import into a PostGIS database using osm2pgsql
* Set up mapnik and test using osm.xml and the generate_image.py
* When everything works, use generate_tiles.py to create 1000s of tiles in a special hierarchy of folders
* Copy/move tiles into your webserver's document root.
* Change the OpenLayers instance to use your own tileserver instead of the main one "

Any help you could give me along these lines would be welcomed.

Kind Regards,
Joseph M Jira

New bounding boxes for generate_tiles.py

Dear Joseph,

Thank you for following along. The pink tiles are still a mystery to me. I'm not going to pursue that as I'm not a Mac-person and have no way to test against your setup. I would expect Ubuntu LTS to be very similar from PPC to i386 but you seem to have found a snag. I'd try re-installing mapnik from svn now that you have imagemagick installed but I'm no PPC expert.

I'll answer the bounding box question in a new blog entry.

custom maps

Hi richard,
1. if I set the bounding box to australia in this line: bbox = (-180.0,-90.0, 180.0,90.0) to (101.1,-6.9,165.5,-45.9)
the images generated by mapnik are only for australia?
2. I have a custom images as australia maps (it's only 6 levels not like OSM ) that we paid for , do u have any idea how to use them with OSM?

level 1 to level 6:
Level 1 = 24 images
a1_1_1.gif
a1_2_1.gif


a4_6_1.gif

Level 2 = 586 images
a1_4_2.gif


a21_30_2.gif

Level 6 = 2190 images
a686_1809_6.gif


a1172_1503_6.gif

thanks

Australia bounding box

Hi Anonymous,

Yes. The image below was generated by generate_image.py with your bbox, z=4 and 200 px/z. So your bounding box works in generate_image.py for Australia. My local system doesn't have any of the au data, so it shows only coastline.

Other maps. Importing the information from your custom maps to OpenStreetMap might not be permitted by the license of your custom maps. Using the OSM maps and your custom data together may be permitted depending on your intended use, but that is a question for your lawyer and / or the OpenStreetMap legal discussion mailing list.

That said, you may be able to use the custom map images together with OpenStreetMap images by using OpenLayers. You may have to reproject OSM data to match the existing custom map, if you don't have access to the custom data. You will have more or less work to do here depending on the details.

Australia bounding box (101.1,-6.9,165.5,-45.9)

I love your tutorials. If I

I love your tutorials.

If I want to build map for a single country from the files from cloudmade.com do I need just the country .osm file?
Can I follow your tutorial without a change or do I need to set the bounding box of that country?
How do I know the bounding box of the country?

It'll be cool to have a tutorial how to setup mod_tile in front of mapnik.

Thanks

Thanks for reading and

Thanks for reading and commenting.

If your area of interest is matched by an extract file then you won't need a bounding box.

You can estimate the bounding box of a country or other place with the OpenStreetMap slippy map. Navigate to your area of interest. Choose the export tab. Choose Manually select a different area. Drag a rectangular box over your area of interest, and the bounding box attributes will appear in the text boxes when you release the mouse-drag.

You can find the bounding box of an OSM extract in the .osm file.

<?xml version='1.0' encoding='UTF-8'?>
<osm version="0.6" generator="Osmosis 0.31">
 <bound box="49.44722,5.73073,50.18100,6.53065" origin="http://www.openstreetmap.org/api/0.6"/>

I'd like to do a write up on mod_tile. Keep an eye on this location...

Failure to Render World Map

Thanks for this great tutorial !!

I'm having a problem rendering the test map although I've successfully used this tutorial on my computer at work - both machines are running OS X 10.5.8 and the OSM stack has been setup in the same way.

The output of running the commands is shown below, it's more than 5 lines but I did build mapnik in debug mode if that's the difference. After the output about cleaning up the font faces the process appears to hang and eventually python crashes.

Any clues on how to debug this problem would be much appreciated.

Cheers
Adam

I removed your many**1000

I removed your many**1000 lines of debugging text.

Sorry that you are having trouble on one of your two systems Adam. The OS X aspect is a mystery to me.

Are both setups using the same versions of python, mapnik, and the OSM stack? Did you pull an intermediate version from svn perhaps?

Since you mentioned font faces, are you adding more fonts, or just using the python defaults?

Perhaps an OS X user will have some tips as well?

Geometry2d problem

sorry for my english i'm a student
hi i'm newbie on this subject i recently follow your steps but occurred an issue maybe because i took another way (downloaded from cloudemade different source of data, is from mexico)
i did this steps

source set-mapnik-env
./customize-mapnik-map >$MAPNIK_MAP_FILE
./my_generate_image.py

but in the last one appear this problem

Traceback (most recent call last):
File "./my_generate_image.py", line 16, in
from mapnik import *
AttributeError: 'module' object has no attribute 'Geometry2d'

i change some values from my_generate_image.py file to match with the bounding box that i want

what can i do?

thanks

./z0_generate_tiles.py traceback

hi
when i run z0_generate_tiles.py from command line i get the following output ? what i am doing wrong and how to rectify it ?? please help

render_tiles( (11.4, 48.07, 11.699999999999999, 48.219999999999999) /home/fulhaq/osm/osm-mapnik/osm.xml /home/fulhaq/osm/osm-mapnik/tiles/ 1 12 Muenchen )
Traceback (most recent call last):
File "./z0_generate_tiles.py", line 197, in
render_tiles(bbox, mapfile, tile_dir, 1, 12 , "Muenchen")
File "./z0_generate_tiles.py", line 126, in render_tiles
renderer = RenderThread(tile_dir, mapfile, queue, printLock, maxZoom)
File "./z0_generate_tiles.py", line 59, in __init__
mapnik.load_map(self.m, mapfile, True)
UserWarning: Failed to find font face 'DejaVu Sans Book' in TextSymbolizer in style 'stations'

Sounds like you didn't edit

Sounds like you didn't edit z0_generate_tiles.py to disable the other bounding boxes.

Did you get this as the start of the output?

render_tiles( (-180.0, -90.0, 180.0, 90.0) /home/username/mapnik/osm.xml /home/username/mapnik/tiles/ 0 0 World )
World [ 0 - 0 ]:  0 0 0 p: (-180.0, -85.051128779806589) (180.0, 85.051128779806604) 
World [ 0 - 0 ]:  0 0 1 p: (-180.0, -89.990752516489039) (180.0, -85.051128779806589) 
World [ 0 - 0 ]:  0 1 0 p: (180.0, -85.051128779806589) (540.0, 85.051128779806604)  
World [ 0 - 0 ]:  0 1 1 p: (180.0, -89.990752516489039) (540.0, -85.051128779806589) 

Traceback (most recent call last)

Hi
when i run z0_generate_tiles.py from command line i get the following output ? what i am doing wrong and how to rectify it ?? please help

Traceback (most recent call last):
File "./z0_generate_tiles.py", line 195, in
render_tiles(bbox, mapfile, tile_dir, 0, 0, "World")
File "./z0_generate_tiles.py", line 126, in render_tiles
renderer = RenderThread(tile_dir, mapfile, queue, printLock, maxZoom)
File "./z0_generate_tiles.py", line 59, in __init__
mapnik.load_map(self.m, mapfile, True)
UserWarning: PSQL error:
错误: 字段 "military" 不存在
LINE 2: ...lect way,aeroway,amenity,landuse,leisure,man_made,military,"...
^
Full sql was: 'select * from
(select way,aeroway,amenity,landuse,leisure,man_made,military,"natural",power,tourism,name
from planet_osm_polygon
where landuse is not null
or leisure is not null
or aeroway in ('apron','aerodrome')
or man_made='pier'
or amenity in ('parking','university','college','school','hospital','grave_yard')
or military in ('barracks','danger_area')
or "natural" in ('field','beach','glacier','heath','mud','wood')
or power in ('station','sub_station')
or tourism in ('attraction','camp_site','caravan_site','picnic_site','zoo')
order by z_order,way_area desc
) as leisure
WHERE "way" && SetSRID('BOX3D(-20037508 -19929239,20037508 19929239)'::box3d, 4326) limit 0'
(encountered during parsing of layer 'leisure')

How can I fix it ? I need you ,thank you.

./z0_generate_tiles.py" can't find osm-local.xml

Could not load map file '/home/my_username/svn.openstreetmap.org/applications/rendering/mapnik/osm-local.xml': File does not exist

/z0_generate_tiles.py.

UserWarning: Could not create datasource. No plugin found for type 'postgis' (encountered during parsing of layer 'leisure')

please help

I hit the same error - did

I hit the same error - did you figure out how to deal with it?
Cheers, Graham

I have got passed this

I have got passed this problem now and the program is generating maps. I made a number of changes, the key one being:

Reinstall Mapnik (based upon http://ubuntuforums.org/showthread.php?t=601201). This explicitly identifies the postgresql location; the steps I took to perform the reinstall were:

$ scons/scons.py -c install
$ scons/scons.py PGSQL_LIBS=/usr/lib/postgresql/8.3/lib PGSQL_INCLUDES=/usr/include/postgresql/
$ sudo scons/scons.py install PGSQL_LIBS=/usr/lib/postgresql/8.3/lib PGSQL_INCLUDES=/usr/include/postgresql/
$ ldconfig

I think the above step probbaly solved my problem, but in the course of addressing this I also did the following things as well:
I edited /home/username/mapnik/set-mapnik-env file and provided my postgis password for MAPNIK_DBPASS
I edited the /etc/postgresql/8.3/main/pg_hba.conf file as suggested by (http://www.bostongis.com/?content_name=postgis_tut01 among others).

Other resources:
http://old.nabble.com/compile-problems-td21247131.html
This page suggests the following:

> I suspect you need to adjust the following line render_config.h
> // Mapnik input plugins (will need to adjust for 32 bit libs)
> #define MAPNIK_PLUGINS "/usr/local/lib64/mapnik/input"

I could not find any file called render_config.h or any mention of MAPNIK_PLUGINS so did not take this step

> To get postgresql to be detected you often need to use:
> $ scons PGSQL_INCLUDES=/usr/include/postgresql ...
(this step is covered by the reinstall above)
Similar advise is provided by http://lists.openstreetmap.org/pipermail/dev/2008-November/012677.html

Good luck, Graham

No tiles for level 8 n above....

Hi....
I ve successfully gone through all this setup process, generating tiles and then using them for my web application.....
But the problem i am facing is this while accessing the tiles in my app, everything works fine till level 0-7...but when i try to zoom in further, I get pink tiles, whereas the tiles for higher levels do exist in their corresponding folders......
definition for my OSM layer in my app is
var localLayer = new OpenLayers.Layer.OSM("My Local OSM","/${z}/${x}/${y}.png",{numZoomLevels:19});

mapnik on Ubuntu 9.04 64bit

On a 64bit Ubuntu libmapnik is installed into /usr/local/lib64.
But this directory is not configured anywhere in /etc/ld.so.conf.d.

So, after installing mapnik with: sudo python scons/scons.py install you must do:

sudo echo /usr/local/lib64 > /etc/ld.so.conf.d/lib64
sudo ldconfig

OSM data and world_shapes do not match

Hi

Thanks for the great description. I managed to make it work despite some missing table
entries which were added to the database by hand.

But when I generate tiles and images the osm data (for example roads and names) do not match
the word_shape/coastlines - they are offset by several kilometers.

Has anyone seen this problem?

I use the denmark data from http://download.geofabrik.de/osm/europe/
and the shapefiles from the sources described in the walk-through.

Cheers

Morten

Hello Morten, that sounds

Hello Morten,
that sounds like your "projection" is wrong. Did you insert 900913.sql into your postgis-dtabase? look at and lern your osm2pgsql's "-E", "-m" and/or "-M" parameters.
Kind Regards,
-Ingo

www interface

Hi,
Thanks for you work putting together this tutorial, it was very helpful. Are there any good how-to's on creating a www interface - i know i'm supposed to use mod_tile and openlayers but despite wasting 3 days on the subject and googling half of the entire internet i failed to find a relevant advice on this subject.

please help me
Adam

Can't Zoom In

i'm having a similar problem to anonymous above, I can't render any closer than zoom 5. Mapnik thinks about it for a bit, makes a few empty directories and stops.

I've checked the postgres logs and there's nothing erroneous going on, it's just failing silently. Any ideas? (I'll post back if I work it out.)

Did your setup go from

Did your setup go from working to broken, or is this your first effort to get it running?

I've had mysterious rendering problems clear up by updating mapnik and osm to the latest svn. Give those a try.

This is a first-time setup.

This is a first-time setup. I've tried checking out updates for Mapnik twice now, but it won't render any further in than zoom level 5. D: It creates the right directory structure, but the files aren't rendered.

Silly Mistake

I can't believe I did this, but I actually had my bounding box definition messed up.

For future reference, the format is left, top, right, bottom. I had my latitudes backward and didn't realise. :O

Rendering Tiles on Windows

First I must say this is an excellent guide to creating our own tiles. My concern, however, is that there are no instructions for Windows users, and not just on your site. The entire community seems to have forgotten that many of us would love to use OSM data and Mapnik and such, but are confined to Windows due to corporate policies (or in my particular case US government restrictions). Is there any chance that you (or someone reading this with a similarly high level of experience) could do an additional article discussing the important differences when doing this on Windows? Specifically the bits that involve bash scripts (such as set-mapnik-env), since those clearly won't work as-is on a Windows box (my solution was to script it all in Python for the sake of convenience, though there's probably a better way).

Hopefully you can provide some assistance with this, though if you don't have easy access to a Windows box, that's fine too. Regardless, this article is fantastic, keep up the good work!

Thank you for taking the

Thank you for taking the time to comment, TomB and for your kind words.

Have a look at the wiki page on editors and you'll find that most OSM editing tools are cross platform and will work for Linux, BSD, OS/X and even Windows users.

I believe that the only guidance that I have provided for Windows users is in the Build Your Own OSM Server article where I offer a first step of Install Ubuntu Server. I don't think that is what you were looking for though. It is unlikely that I will write guidance for Windows users that is more specific than I have already written.

I understand that some workplaces must restrict the software that they will allow on their premises as they only have limited support available. There are several OSM consulting firms that can provide you with OSM tiles or other services so that you can use OSM data without having to use the tools that the firm does not understand. Feel free to contact me with your email and your OSM requirements. I'll be happy to introduce you to some firms with the OSM experience to solve your problems.

I do know that others have asked about running the OSM server stack on proprietary operating systems. I'm not aware of their results.

error when run ./z0_generate_tiles.py

I'm getting this error:
~/mapnik$ ./z0_generate_tiles.py
Traceback (most recent call last):
File "./z0_generate_tiles.py", line 6, in
import mapnik
File "/usr/lib/python2.6/dist-packages/mapnik/__init__.py", line 52, in
from _mapnik import *
ImportError: libmapnik.so.0.6: cannot open shared object file: No such file or directory

Now I tried "sudo echo /usr/local/lib64 > /etc/ld.so.conf.d/lib64" from the comment above (I'm running 9.10, x64) and I get a permission denied, it never asks for a password.

Any ideas? Now I never set a bounding box as I'm using a cloudmade.com extract.

Where is your

Where is your libmapnik.so.0.6 ?

Did you compile mapnik? Without errors?

Did you ldconfig after?

libmapnik.so.0.6

Mapnik - as far as I can tell compiled without errors.
My libmapnik.so.0.6 is in the /usr/local/lib64, and since I couldnt run the recommendation (echo >) I recreated that directory in /etc/ld.so.conf.d/lib64 and copied all the stuff there. I have run ldconfig after that too.

I had same issue, got it

I had same issue, got it working when I just logged out and in again (hint from http://trac.mapnik.org/wiki/InstallationTroubleshooting)

I tried that, didn't seem to

I tried that, didn't seem to work. Perhaps after Christmas I'll give it another go. I may just use the 32bit version in a virtual machine to see if I can get it running.

Has anyone used the GISVM virtual machine to do this? gisvm.com has some info, it's a vmware image of ubuntu packaged with some GIS tools.

Openstreetmap on Gentoo

I managed to install Openstreetmap on Gentoo (status: December 2009) and I could generate some interesting tiles of Poschiavo, which is a little valley in the mountains where I live. My server is an AMD k6-700 MHZ with 600 MB of RAM, so not a real power horse but quite an old scrap iron thing. Of course, I did not import the whole planet, but only a dump of Switzerland.

I wrote down some steps that differ from the very good tutorials here, because the installation is performed on Gentoo instead of Ubuntu: of course, this is working now as for December 2009, but an emerge --sync in the future might solve some of these problematic steps (maybe someone more knowledgeable than me will read this tutorial and fix some ebuilds :-).

Step: Subversion and Java
-------------------------
These one were easy and you probably figured out faster than me:
emerge -av subversion
emerge -av sun-jdk

Step: Installing Postgresql with Postigs
----------------------------------------

osm2pgsql does not work with Postgresql 8.1 which is marked stable in Gentoo. The reason is that
Postgresql 8.1.11 does not know about the command 'DROP TABLE IF EXISTS' which is used in oms2pgsql. Defining a stored procedure that does the same and modifying the source code of osm2pgsql did not work for me.

Therefore I chose another way, which goes as follows: you should add at the end of /root/.bashrc the following alias:
alias aemerge='ACCEPT_KEYWORDS="~x86" emerge '

source /root/.bashrc will load this setting for the first time. The setting is kept after, as .bashrc is read at every login.
From now on, you can use "aemerge" to emerge unstable packages instead of "emerge".

Then, you can install an unstable Postgresql with
aemerge -av postgresql
This will install a Postgresql 8.2.14 which is fine for our purposes.

Install also Postgis:
aemerge -av postgis
Postgis-1.4.0 was then installed.

Configure the database postgis extensions not by using emerge --config as suggested at the end of emerge, but use the instructions provided in this tutorial. Remember to follow the instructions as normal user and not as superuser (a part of the inital step of setting up the database).

As noted in the previous comment, lwpostgresql.sql does not exist in postgis anymore, it was renamed in postgis.sql, you should therefore use
psql -d gis -f /usr/share/postgresql/contrib/postgis.sql

Step: Installing mapnik
-----------------------

For mapnik I had problems, it did not compile from source as described in the tutorial, it was failing when compiling the postgis plugin for linking reasons against the library libpq.la, though the library was present on the proposed path.

I did the following trick:

USE="postgresql" aemerge -av mapnik
emerged and installed a mapnik with all dependencies, which however was not able to recognize the postgis extensions on the 'gis' database.

In fact, when running ./z0_generate_tiles.py, mapnik was failing with:
"
Could not create datasource. No plugin found for type 'postgis' (encountered during parsing of layer 'leisure') when connecting to the imported database.
"
This error message is listed as comment in the next tutorial as well.

Then I did the following:
I unmerged the unstable libpq library (libpq is a library used by postgresql used as connection layer.
emerge --unmerge libpq
I unmerged mapnik without its dependencies with
emerge --unmerge mapnik

I installed the stable libpq library with:
emerge -av libpq

Then I installed mapnik from source with the following steps

mkdir src
cd src
svn co http://svn.mapnik.org/trunk/ mapnik
cd mapnik
scons/scons.py -c install
scons/scons.py PGSQL_LIBS=/usr/lib/postgresql/ PGSQL_INCLUDES=/usr/include/postgresql/
sudo scons/scons.py install PGSQL_LIBS=/usr/lib/postgresql/ PGSQL_INCLUDES=/usr/include/postgresql/
ldconfig

Therefore: postgresql is compiled against an unstable version of libpq, while mapnik needs a stable one to compile.
Of course, postgresql will survive the restart with /etc/init.d/postgresql restart :-)

Have fun with your maps!

Empty Tile

Hi,
can anyone help please. I'am getting always Empty Tiles.
After downloading OSM data and inserting it into the database gis (./osm2pgsql --slim ..), I followed the steps and execute the commands
(source set-mapnik-env
./customize-mapnik-map >$MAPNIK_MAP_FILE
./z0_generate_tiles.py)

The values for the Bounding Box for Great Britian are from the osm file.

In the STDERR i always get this messages:
Great Britian : 10 651 508 Empty Tile
Great Britian : 10 651 507 Empty Tile
....
Great Britian : 15 20903 17133 Empty Tile
Great Britian : 15 20903 17134 Empty Tile

Any ideas?

Thanks
Ayhan

Not rendering street data

Hello,

I've been following the tutorials very closely, I've downloaded the planet file, carved out the area of interest (in this case following your example).

I'm using the same bounding box as the tutorial for the osm carving and tile extraction (-94,38,-71.5,50).

I carved my GreatLakes.osm.gz file out of a complete planet file (planet-100106.osm) using osmosis.

This is the output from the database insertion:
root@osm:~/src/osm2pgsql# time ./osm2pgsql --slim -U osm -d gis ~/GreatLakes.osm.gz -S ./default.style
osm2pgsql SVN version 0.69-19556

Using projection SRS 900913 (Spherical Mercator)
Setting up table: planet_osm_point
NOTICE: table "planet_osm_point_tmp" does not exist, skipping
Setting up table: planet_osm_line
NOTICE: table "planet_osm_line_tmp" does not exist, skipping
Setting up table: planet_osm_polygon
NOTICE: table "planet_osm_polygon_tmp" does not exist, skipping
Setting up table: planet_osm_roads
NOTICE: table "planet_osm_roads_tmp" does not exist, skipping
Mid: pgsql, scale=100, cache=800MB, maxblocks=102401*8192
Setting up table: planet_osm_nodes
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "planet_osm_nodes_pkey" for table "planet_osm_nodes"
Setting up table: planet_osm_ways
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "planet_osm_ways_pkey" for table "planet_osm_ways"
Setting up table: planet_osm_rels
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "planet_osm_rels_pkey" for table "planet_osm_rels"

Reading in file: /root/GreatLakes.osm.gz
Processing: Node(71232k) Way(5406k) Relation(21k)
Node stats: total(71232998), max(606274608)
Way stats: total(5406371), max(47656335)
Relation stats: total(21641), max(378268)

Going over pending ways
processing way (469k)

Going over pending relations

node cache: stored: 63547003(89.21%), storage efficiency: 60.60%, hit rate: 89.10%
Stopping table: planet_osm_nodes
Stopping table: planet_osm_ways
Stopping table: planet_osm_rels
Stopped table: planet_osm_nodes
Committing transaction for planet_osm_point
Building index on table: planet_osm_ways
Building index on table: planet_osm_rels
Sorting data and creating indexes for planet_osm_point
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_line
Sorting data and creating indexes for planet_osm_polygon
Committing transaction for planet_osm_roads
Sorting data and creating indexes for planet_osm_line
Sorting data and creating indexes for planet_osm_roads
Stopped table: planet_osm_rels
Completed planet_osm_point
Completed planet_osm_roads
Completed planet_osm_polygon
Completed planet_osm_line
Stopped table: planet_osm_ways
real 76m30.620s
user 27m12.570s
sys 1m21.110s
root@osm:~/src/osm2pgsql#

z0_generate_tiles.py creates a map of the world (as expected).
When I try to render the image using: ./my_generate_image.py I get the correct area on the map (I can see the coastline data), but I'm not seeing any openstreetmap data.

I have a feeling that this may be a projection issue - when I installed postgis, I installed the /usr/share/postgresql/8.4/contrib/spatial_ref_sys.sql file. I missed the loading 900913.sql file (would this make a difference?).
I am running on Karmic.

Thanks for your assistance.

Getting errors on importing data

Hello,

first of all, thank you very much for the great tutorial. Unfortunately I'm stuck with a problem for over a week and three different installation-pc's by now.
Everything works fine just until the
time ./osm2pgsql --slim -d gis GreatLakes.osm.gz
command. No matter which machine I tried I always got the same error:

*****:/usr/share/osm2pgsql$ time ./osm2pgsql --slim -d gis ~/germany.osm.bz2
osm2pgsql SVN version 0.69-19015
Using projection SRS 900913 (Spherical Mercator)
Setting up table: planet_osm_point
HINWEIS: Tabelle »planet_osm_point« existiert nicht, wird übersprungen
HINWEIS: Tabelle »planet_osm_point_tmp« existiert nicht, wird übersprungen

In English: "Hint: table >>planet_osm_point<< doesn't exist, skipping"
This happens to several more tables and their _tmp equivalent, like "line", "polygon", "roads", "nodes", "ways" and "rels".

Could you please help me to get beyond this point?
Thank you very much for your help!
Daniel

Problem importing data

I have the following problem?

arran@server2:~$ time osm2pgsql --slim -d gis uk-091219.osm
osm2pgsql SVN version 0.69-19627

Using projection SRS 900913 (Spherical Mercator)
Setting up table: planet_osm_point
NOTICE: table "planet_osm_point" does not exist, skipping
NOTICE: table "planet_osm_point_tmp" does not exist, skipping
Setting up table: planet_osm_line
NOTICE: table "planet_osm_line" does not exist, skipping
NOTICE: table "planet_osm_line_tmp" does not exist, skipping
Setting up table: planet_osm_polygon
NOTICE: table "planet_osm_polygon" does not exist, skipping
NOTICE: table "planet_osm_polygon_tmp" does not exist, skipping
Setting up table: planet_osm_roads
NOTICE: table "planet_osm_roads" does not exist, skipping
NOTICE: table "planet_osm_roads_tmp" does not exist, skipping
Mid: pgsql, scale=100, cache=800MB, maxblocks=102401*8192
Setting up table: planet_osm_nodes
NOTICE: table "planet_osm_nodes" does not exist, skipping
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "planet_osm_nodes_pkey" for table "planet_osm_nodes"
Setting up table: planet_osm_ways
NOTICE: table "planet_osm_ways" does not exist, skipping
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "planet_osm_ways_pkey" for table "planet_osm_ways"
Setting up table: planet_osm_rels
NOTICE: table "planet_osm_rels" does not exist, skipping
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "planet_osm_rels_pkey" for table "planet_osm_rels"

Reading in file: uk-091219.osm

I've been scratching my head for days!

Arran

For Karmic, this Mapnik install instructions worked

These instructions worked for me to install mapnik from source on Ubuntu Karmic: http://trac.mapnik.org/wiki/UbuntuInstallation#InstallMapnikfromsource

Because I run a 64bit OS, I needed to add the path /usr/local/lib64 to /etc/ld.so.conf.d/libc.conf to make it work.

Park but no roads

I've followed this tutorial many time successfully, but this time I'm having a strange problem I haven't seen before. The only difference in setup this time is that I'm running Debian instead of Ubuntu. I imported some osm data as usual and with no problems, but when I try to render an image I get the coastlines and I get one big park rendered from the OSM data, but none of the roads or other objects from the database. I'm at a loss because I don't understand why just one object would be rendered from the database but nothing else.

I tried again with tiles, but they won't render at all, unlike the image. The error is:

Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner
self.run()
File "/usr/lib/python2.5/threading.py", line 446, in run
self.__target(*self.__args, **self.__kwargs)
File "./gotile.py", line 109, in loop
self.render_tile(tile_uri, x, y, z)
File "./gotile.py", line 85, in render_tile
self.m.resize(render_size, render_size)
AttributeError: 'Map' object has no attribute 'resize'

Any advice?

Hi anonymous, I'm not sure.

Hi anonymous,

I'm not sure. There are instructions for debian on the Mapnik site. Have you had a look there?

rendering osm file from postgis using mapnik on windows

Dear sir/ madam

I am student, from Stuttgart university of applied sciences. I tried to set post gis server and using osm2pgsql tool i am able to create geodatabase.
now i have problem rendering with mapnik on windows. I tried all the sources from web wikipedia, and some other blogs.
even i mailed my problem to mapnik directly.

I would appericiate if you please help me in rendering

the commands i used are following.

1. Downloaded and installed the SVN-client.
2. Exported the Mapnik stuff from the OSM subversion repository. using command prompt and command i used

svn export http://svn.openstreetmap.org/applications/rendering/mapnik

3.To generate my own XML-file with the connection to PostgreSQL / PostGIS used command prompt, navigated to the Mapnik-directory and executed the command

generate_xml.py osm.xml osm-local.xml --host localhost --user abc --dbname gis --symbols ./symbols/ --world_boundaries ./world_boundaries/ --port 5432 --password *

but here i am getting errors in command prompt

Trackback (most recent call last):
file "C:\mapnik\generate_xml.py", line 194, in
serialize(template_xml,options)
file "C:\mapnik\generate_xml.py", line 70, in serialize
mapnik.load_map(m,xml,true)
RuntimeError: c:/mapnik/worl_boundaries/builtup_area does not exist (encountered during parsing of layer 'builtup')

I am not getting how to remove these errors, than how to render with mapnik to visulize these tiles.

Look forward to your response.

Hello Shakti, thank you for

Hello Shakti, thank you for writing.

I see a typo in your post. c:/mapnik/worl_boundaries/builtup_area does not exist should be c:/mapnik/world_boundaries/builtup_area does not exist in your xml file. I presume that this was just a problem in transcribing your comment.

More likely is that you had a problem while installing the world boundary shape files. have another look at the section:

Install prepared world boundary data

Confirm that the last two wget and the last two unzip commands execute correctly.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <q> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <h1> <h2> <h3> <h4> <pre> <sup> <sub> <blockquote>
  • Lines and paragraphs break automatically.

More information about formatting options