wiki:RenderingOsmDataUbuntu

Version 4 (modified by dmorissette, 13 years ago) ( diff )

--

Rendering OSM data with MapServer on Ubuntu 10.10

This page provides step by step instructions to setup a Ubuntu 10.10 LTS server from scratch to render OSM data with MapServer 6.x.

The following instructions assume that we start with a brand new Ubuntu 10.10 server with Apache installed but none of the MapServer related packages installed.

The setup will include:

Create work directory

  • All the steps that follow assume that the data and mapfiles will be installed in a directory called "osm-demo" in your home directory
  • Commands:
      mkdir ~/osm-demo
      cd ~/osm-demo/
    

Install UbuntuGIS MapServer and PostGIS packages

  • Relevant docs: http://trac.osgeo.org/ubuntugis/wiki/UbuntuGISRepository
  • At the time of this writing, the current version of MapServer is 6.0.1
  • Commands:
      sudo apt-get install python-software-properties
      sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
      sudo apt-get update
      sudo apt-get install cgi-mapserver mapserver-bin
    
      sudo apt-get install postgresql
      sudo apt-get install postgis postgresql-8.4-postgis
    
  • Install other non-GIS packages that will be required later on:
      sudo apt-get install mercurial subversion
      sudo apt-get install zip unzip
    

Download OSM data

  • You can download data for your region of interest from http://download.geofabrik.de/osm/. The rest of these instructions assume that we work with the data for the state of Alabama.
  • Commands:
      cd ~/osm-demo/
      wget http://download.geofabrik.de/osm/north-america/us/alabama.osm.pbf
    

Install imposm, using virtualenv

  • Relevant docs: http://imposm.org/docs/imposm/latest/install.html
  • Commands:
      cd ~/osm-demo/
      sudo apt-get install build-essential python-dev protobuf-compiler \
                          libprotobuf-dev libtokyocabinet-dev python-psycopg2 \
                          libgeos-c1
    
      sudo apt-get install python-virtualenv
      virtualenv venv
    
  • Install shapely speedups:
      sudo apt-get install libgeos-dev
      venv/bin/pip install https://github.com/olt/shapely_speedups/tarball/master
    
  • IMPORTANT: We will use a custom branch of imposm created by tbonfort that creates additional generalized tables for use with mapserver-utils:
      hg clone https://bitbucket.org/tbonfort/imposm-tbonfort
      vi imposm-tbonfort/imposm/defaultmapping.py
    ... change proj to epsg:900913 (it is set to epsg:4326 bu default)
    
  • If we wanted to use the release version of imposm instead then we'd have run the following command, BUT WE DO NOT WANT THAT... this command included here only for reference:
      # Do not run this command unless you plan to use the release version of imposm
      #venv/bin/pip install imposm
    
  • TODO: Verify if released version of imposm includes all required tables and views, and when it does update these instructions to avoid using the custom branch.

Create database

  • Relevant docs: http://imposm.org/docs/imposm/latest/tutorial.html
  • Commands:
      ~/osm-demo/venv2/bin/python imposm-tbonfort/imposm/psqldb.py > create-db.sh
      vi ./create-db.sh # cross check if all path are set
    ... edit the following lines:
    -------------------8<--------------
    psql -d osm -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql             # <- CHANGE THIS PATH
    psql -d osm -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql     # <- CHANGE THIS PATH
    ------------------->8--------------
    
      sudo su postgres
      sh ./create-db.sh
      /etc/init.d/postgresql-8.4 restart
      exit
    
  • Note: If we were using the released version of imposm then the first command would have been:
      venv/bin/imposm-psqldb > create-db.sh
    

Load data using imposm

  • Relevant docs: http://imposm.org/docs/imposm/latest/tutorial.html
  • Commands:
      cd ~/osm-demo/
      ~/osm-demo/venv/bin/python imposm-tbonfort/imposm/app.py --read alabama.osm.pbf
      ~/osm-demo/venv/bin/python imposm-tbonfort/imposm/app.py  --write --database osm --host localhost --user osm
      ~/osm-demo/venv/bin/python imposm-tbonfort/imposm/app.py  --optimize -d osm
    
  • Note: multiple .osm.pbf files can be loaded in separate commands using the --merge-cache argument.

Install mapserver-utils mapfile generator

  • Website: http://code.google.com/p/mapserver-utils/
  • Check out the 'imposm-branch' from SVN:
      cd ~/osm-demo/
      svn checkout http://mapserver-utils.googlecode.com/svn/branches/imposm-branch/ mapserver-utils-svn-imposm
      cd mapserver-utils-svn-imposm
    
  • Update mapserver-utils's osm-base.map and Makefile as follows:
    -------------------8<------------------------
    Index: osmbase.map
    ===================================================================
    --- osmbase.map	(revision 83)
    +++ osmbase.map	(working copy)
    @@ -7,6 +7,7 @@
     SIZE 800 800
     EXTENT 47586 1621243 1197769 2679357
     EXTENT 16805492 -4049385 16857351 -3975830
    +EXTENT -20000000 -20000000 20000000 20000000
     UNITS OSM_UNITS 
     IMAGECOLOR _ocean_clr0
     WEB
    @@ -16,6 +17,8 @@
           "labelcache_map_edge_buffer" "-10"
           "wms_title" "osm france"
        END
    +   IMAGEPATH "/tmp/ms_tmp/"
    +   IMAGEURL "/ms_tmp/"
     END
     
     DEBUG _debug
    Index: Makefile
    ===================================================================
    --- Makefile	(revision 83)
    +++ Makefile	(working copy)
    @@ -1,11 +1,12 @@
    -CPP=cpp
    +CPP=cpp-4.4
     
     OSM_PREFIX=osm_new_
     OSM_SRID=4326
    -OSM_UNITS=dd
    +OSM_SRID=900913
    +OSM_UNITS=meters
     OSM_WMS_SRS="EPSG:900913 EPSG:4326 EPSG:3857 EPSG:2154 EPSG:310642901 EPSG:4171 EPSG:310024802 EPSG:310915814 EPSG:310486805 EPSG:310702807 EPSG:310700806 EPSG:310547809 EPSG:310706808 EPSG:310642810 EPSG:310642801 EPSG:310642812 EPSG:310032811 EPSG:310642813 EPSG:2986"
    -DEBUG=1
    -LAYERDEBUG=1
    +DEBUG=2
    +LAYERDEBUG=2
     
     template=osmbase.map
    
    -------------------->8-----------------------
    
  • Execute the mapserver-utils makefile to generate the mapfile. Note that the first time you run 'make' several large files will be downloaded (country boundaries, etc.). This will happen only the first time.
      cd ~/osm-demo/mapserver-utils-svn-imposm
      make
    
  • Create MapServer temp dirs (required by mapserv CGI for testing with openlayers template)
      mkdir /tmp/ms_tmp
      chmod 777 /tmp/ms_tmp
    
  • Access your map online using MapServer's built-in template=openlayers mode:
    http://yourserver.tld/cgi-bin/mapserv?map=/path/to/osm-demo/mapserver-utils-svn-imposm/osm.map&mode=browse&template=openlayers&layers=all
    
Note: See TracWiki for help on using the wiki.