Installation¶
- Author:
Yves Jacolin
- Contact:
yjacolin at free.fr
Basemaps needs: * data * project configuration
This section explains how to set up both of them.
Data¶
Data comes from an OpenStreetMap database and are stored in a PostgreSQL database.
Database creation¶
$ sudo -u postgres createdb osm
$ sudo -u postgres psql -d osm -c "CREATE EXTENSION postgis;"
$ sudo -u postgres createuser -D -l -R -S -P "www-data"
$ sudo -u postgres psql -d osm -c 'GRANT ALL ON ALL TABLES IN SCHEMA public TO "www-data";'
This will create a new database called osm, add the postgis extension, create a www-data role with right in the public schema.
Imposm Installation¶
OpenStreetMap data are processed by imposm. This is a fast and easy step.
Check the Installation process from http://imposm.org/docs/imposm/latest/install.html or see the steps below:
$ cd # switch to user home
$ mkdir osm_pbf
$ cd osm_pbf
$ sudo apt-get install build-essential python-dev protobuf-compiler \
libprotobuf-dev libtokyocabinet-dev python-psycopg2 libgeos-c1
$ virtualenv venv
$ venv/bin/pip install imposm
We have now a virtual python env with imposm. Each time you need to use it, run source venv/bin/activate (see below the next steps to use it in our use case).
Data Import¶
Source: http://imposm.org/docs/imposm/latest/tutorial.html#writing
$ cd /tmp
$ wget http://download.geofabrik.de/europe/france/poitou-charentes-latest.osm.pbf
$ wget http://download.geofabrik.de/europe/france/centre-latest.osm.pbf #if you need another location
$ pwd
/tmp/
$ ls -1
centre-latest.osm.pbf
poitou-charentes-latest.osm.pbf
$ source venv/bin/activate
$ imposm -m /path/to/basemaps/imposm-mapping.py --read poitou-charentes-latest.osm.pbf
$ imposm -m /path/to/basemaps/imposm-mapping.py --read --merge-cache centre-latest.osm.pbf
$ imposm -m /path/to/basemaps/imposm-mapping.py --write -d osm --connection postgis://www-data:www-data@localhost/osm --proj EPSG:2154
$ imposm -m /path/to/basemaps/imposm-mapping.py --optimize --connection postgis://www-data:www-data@localhost/osm
# Following command is probably not useful
$ sudo -u postgres psql -d osm -c "CREATE VIEW osm_new_waterways_gen1 AS \
SELECT * FROM osm_new_waterways;CREATE VIEW osm_new_waterways_gen0 AS SELECT * FROM osm_new_waterways;"
$ sudo -u postgres psql -d osm -c "GRANT ALL ON ALL TABLES IN SCHEMA public TO \"www-data\";"
Let’s explain this better: First we download 2 pbf files from Geofabrik OpenStreetMap data. PBF is just another format well compressed from Google. pwd and ls -1 commands are just there to show you where we are and what we get.
The source command activates the Python virtual environment in order to use imposm.
The next two commands (read) are similar and preprocesses PBF data. The difference is that the second one merges cached data to push both French region into the database.
Then we write (push) data into the database using the French National projection EPSG code (EPSG:2154). You can use whatever that’s fit your needs.
The last commands optimize the data and give some rights to www-data.
Some data are missing, you can get there:
Get the following layer : https://github.com/datadesk/osm-la-streets/tree/master/la-streets/layers/processed_p and putt hem in basemaps/data/
Get the following layer land_polygon (Projection: Mercator) https://osmdata.openstreetmap.de/download/land-polygons-complete-3857.zip also in basemaps/data/
Get the following layer simplified_land_polygon https://osmdata.openstreetmap.de/download/land-polygons-split-3857.zip also in basemaps/data/
Project configuration¶
The Basemaps project source code is located here: https://github.com/MapServer/basemaps.
Project deployment¶
$ cd /var/www/somewhere/
$ git clone git@github.com:MapServer/basemaps.git
$ cd basemaps
That’s easy enough to not need much explanation.
Custom configuration¶
Create your own custom makefile and give it a name (whatever your want):
$ vim aname.mk (edit the following file with custom variable):
You can add all custom values from the main Makefile, here are some examples:
OSM_SRID = 2154
OSM_DB_CONNECTION = host=localhost dbname=osm user=www-data
password=www-data port=5432
include Makefile
Here we customize the SRID of the data (see above when we imported data into the database) and the database connection.
Build the mapfile¶
$ make -f aname.mk
You should have now a working mapfile.
Apache configuration¶
Create an Apache configuration and enable it.
$ vim osm.conf
With such a content:
<VirtualHost \*:80>
ErrorLog ${APACHE_LOG_DIR}/osm_error.log
CustomLog ${APACHE_LOG_DIR}/osm_access.log combined
ScriptAlias /osm-default /usr/lib/cgi-bin/mapserv
<Location /osm-default>
# Order Deny,Allow
# Deny from all
# Allow from 127.0.1.1 ::1
SetEnv MS_MAPFILE /path/to/basemaps/osm-default.map
</Location>
</VirtualHost>
Finally enable this Apache virtual conf:
$ cp osm.conf /etc/apache/site-available/conf/
$ sudo a2ensite osm
$ sudo /etc/init.d/apache2 graceful
And test the GetCapabilities URL: http://localhost/osm-default?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities