wiki:RenderingOsmDataUbuntu

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

More details on mod-gecache config

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
  • Install dependencies and create python virtual env:
      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 by default)
    
  • Install impost inside our python venv:
      cd imposm-tbonfort/
      ~/osm-demo/venv/bin/python setup.py install
    
  • 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:
      venv/bin/imposm-psqldb > create-db.sh
      vi ./create-db.sh # cross check if all path are set properly
    ... edit the following lines:
    -------------------8<--------------
    psql -d osm -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql             # <- CHECK THIS PATH
    psql -d osm -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql     # <- CHECK THIS PATH
    ------------------->8--------------
    
      sudo su postgres
      sh ./create-db.sh
      /etc/init.d/postgresql-8.4 restart
      exit
    

Load data using imposm

  • Relevant docs: http://imposm.org/docs/imposm/latest/tutorial.html
  • Commands:
      cd ~/osm-demo/
      ~/osm-demo/venv/bin/imposm --read alabama.osm.pbf
      ~/osm-demo/venv/bin/imposm --write --database osm --host localhost --user osm
      (... if prompted for db password, the default is 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 osmbase.map and Makefile as follows:
      vi osm-base.map
    -------------------8<------------------------
      WEB
    ...
        IMAGEPATH "/tmp/ms_tmp/"
        IMAGEURL "/ms_tmp/"
     END
    ...
    -------------------->8-----------------------
    
      vi Makefile
    -------------------8<------------------------
    OSM_SRID=900913
    OSM_UNITS=meters
    OSM_EXTENT=-20000000 -20000000 20000000 20000000
    ...
    STYLE=google
    -------------------->8-----------------------
    
  • Create MapServer temp dirs (required by mapserv CGI for testing with openlayers template)
      mkdir /tmp/ms_tmp
      chmod 777 /tmp/ms_tmp
    
  • 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
    
  • The 'make' command will have generated a osm-google.map based on the parameters in the generate_style.py script.
  • More information about tweaking the map styles is available at http://code.google.com/p/mapserver-utils/wiki/TweakingMapStylesImposm
  • 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-google.map&mode=browse&template=openlayers&layers=all
    

Setup Mod-Geocache

  • Relevant docs: http://mod-geocache.googlecode.com/svn/trunk/INSTALL
  • Required packages:
      sudo apt-get install autoconf
      sudo apt-get install apache2-dev
      sudo apt-get install libcairo2-dev
    
  • Checkout and build source:
      svn checkout http://mod-geocache.googlecode.com/svn/trunk/ mod-geocache-svn-ro
      cd mod-geocache-svn-ro/
      autoconf
      ./configure
      make
    
      sudo make install-module
      sudo apache2ctl restart  
    
  • Create our own geocache-osm.xml based on docs in sample geocache.xml (http://mod-geocache.googlecode.com/svn/trunk/geocache.xml) or in pretty print at http://code.google.com/p/mod-geocache/source/browse/trunk/geocache.xml
      mkdir ~/osm-demo/geocache
      cp ~/osm-demo/mod-geocache-svn-ro/geocache.xml ~/osm-demo/geocache/geocache-osm.xml
      vi ~/osm-demo/geocache/geocache-osm.xml
    ... make required changes to template to make it work with our installation:
    
      <cache name="disk" type="disk">
    ...
           <base>/path/to/osm-demo/geocache/cache</base>
    
    ...
       <source name="osm" type="wms">
          <http>
             <url>http://localhost/cgi-bin/mapserv?</url>
          </http>
    ...
                <MAP>/path/to/osm-demo/mapserver-utils-svn-imposm/osm-google.map</MAP>
    ...
    
       <tileset name="osm">
          <metadata>
             <title>OSM MapServer served map</title>
             <abstract>see http://trac.osgeo.org/mapserver/wiki/RenderingOsmDataUbuntu</abstract>
          </metadata>
          <source>osm</source>
          <cache>disk</cache>
          <format>PNG</format>
          <grid>g</grid>
          <grid>WGS84</grid>
          <metatile>5 5</metatile>
          <expires>10000</expires>
          <auto_expire>86400</auto_expire>
          <metabuffer>10</metabuffer>
       </tileset>
    
  • And restart apache for the changes to take effect:
      sudo apache2ctl restart
    
Note: See TracWiki for help on using the wiki.