Bing Maps has a very good coverage with roadmaps and aerial imagery. However, there are regions where our data providers have gaps. Crowed-sourcing of geospatial data might be an option to fill these gaps and one of the most active communities is around OpenStreetMap. The OpenStreetMap data is available under the Create Common Attribution-Share Alike 2.0 License which means that as long as you provide the correct attribution to the source you should be fine to integrate the data with Bing Maps.
While it is theoretically possible to link directly to the OpenStreetMap tile servers, users who have a high load are requested to run their own tile servers. This also allows you to take control over availability and scalability of the tile servers.
- PostgreSQL / PostGIS
A simple way to install PostgreSQL and PostGIS is the free Postgres Plus Standard Server 8.x from EnterpriseDB.
- OpenStreetMap data as .osm XML-file. You can download the whole world or extracts for certain countries or regions here. You can also export smaller regions directly from OpenStreetMap:
- osm2pgsql – an OpenStreetMap data to PostgreSQL converter and loader
- Python 2.5 – Mapnik doesn’t run with newer Python version
- If we are working with Windows we’ll need a file-compression-tool that can handle tar and tar.bz2 archives. I use 7-Zip.
- A SVN client. I use Slik SVN.
- A Bing Maps Developer Account
- The Bing Maps Silverlight Control
- Visual Studio 2008 Service Pack 1 or higher
- The Silverlight 3 Tools for Visual Studio 2008 SP1
- A bit of your time 🙂
- Installing PostgreSQL / PostGIS is very simple – particularly if you use the installer from EnterpriseDB.
- Once we have installed the PostgreSQL / PostGIS we can use the graphical user interface pgAdmin III to create a new login role and database.
- Let’s start with a new login role:
We provide a role name and a password…
- Next we create a new database – let’s call it “gis” – using the PostGIS-template.
That’s already all we have to do here.
- After downloading osm2pgsql extract it into a new folder and add it to the path in the environmental variables:
- Now we open a command prompt and change into the directory where we have extracted osm2pgsql. In order to load the data we execute the following command:
osm2pgsql -m -s -d gis -U jkebeck -W c:usersjkebeckdownloadsOpenStreetMapmadagascar.osm.bz2
You can get help on osm2pgsql by typing osm2pgsql –h in the command prompt. The parameters we used are:
-m | Store data in spherical mercator
-s | Store temporary data in the database. This greatly reduces the RAM usage but is
-d | The name of the PostgreSQL database to connect to
-U | Postgresql user name
-W | Force password prompt
madagascar.osm.bz2 is the name of the OpenStreetMap data file that we want to load.
- First we download and install Python 2.5. Note: Mapnik doesn’t run with newer versions of Python.
- Next we download Mapnik and extract it into the root-directory of our C-drive.
- Now we add the lib-path to our environment variables:
- Next we create a new environment variable PYTHONPATH and add C:mapnik_0_7_0python2.5site-packages as value.
- To test if the installation was successful we open a command prompt and change to the Python-directory, e.g. C:Python25. We type the command
from mapnik import *
If we don’t receive an error message this is already a good sign. Let’s make a final test by opening the folder C:mapnik_0_7_0demopython in the Windows Explorer and double-clicking rundemo.py. If this creates a couple of demo.*-files we’re done with this step.
- Mapnik uses external data for coastlines at lower zoom levels. The files we have to download are
- Download and install a SVN-client. I use Slik SVN
- Export the Mapnik stuff from the OSM subversion repository. Open a command prompt and execute the command
- Now move the downloaded content into your Mapnik-directory.
- The osm.xml file is built up out of the core osm.xml file and XML include files in the inc/ directory. The inc/ directory holds 3 .template files, which are used as inputs for the generate_xml.py script. To generate our own XML-file with the connection to PostgreSQL / PostGIS we open a command prompt, navigate to the Mapnik-directory and execute the command
generate_xml.py osm.xml osm-local.xml –host localhost –user jkebeck –dbname gis –symbols ./symbols/ –world_boundaries ./world_boundaries/ –port 5432 –password *Not4All*
- We might run into issues where some columns are not found, e.g. shop:
In that case we have to remove all occurrences of this column in the files osm.xml and layer-amenity-points.xml.inc. Once this is sorted run the command again.
- We are almost ready to render the tiles. Let’s open the Python-script generate_tiles.py in a text editor and edit the parameters for the bounding box at the bottom of the file:
- In order to render the tiles we can now set a few environment variables and execute the Python-script generate_tiles.py.
# Change the following for different bounding boxes and zoom levels
# Antanarivo, Madagascar
minZoom = 6
maxZoom = 17
bbox = (47.382, -19.042, 47.638, -18.735)
render_tiles(bbox, mapfile, tile_dir, minZoom, maxZoom)