Paul’s Blog

A blog without a good name

Building Osm2pgsql for Testing

Recently I needed to run a bunch of osm2pgsql tests in a virtual machine, so optimized the process. You would not normally do development in a VM, but it’s useful for testing. It’s particularly useful for me because my old Ubuntu server uses a development version of PostGIS which doesn’t work with the testsuite.

I was using VirtualBox to run the VMs, and started with a base Ubuntu 14.04 server install on a virtual drive of at least 30GB. The flat-nodes tests require a lot of space.

Starting with the base, I updated the OS with

1
sudo apt-get update && sudo apt-get dist-upgrade && sudo shutdown -r now

This gave me a VM I could clone and use for other projects. Starting from a cloned VM, I installed the dependencies. Copying and pasting into VirtualBox can be a pain, so a bit of clever shell expansion minimizes the text I need to type

1
2
3
sudo apt-get install libtool g++ protobuf-c-compiler postgresql-9.3-postgis-2.1 \
  lib{boost{,-system,-filesystem,-thread},xml2,geos++,pq,bz2,proj,protobuf-c0,lua5.2}-dev \
  python-psycopg2

The osm2pgsql testsuite requires a custom tablespace for some of the tests, as well as normal PostgreSQL setup.

1
2
3
4
sudo -u postgres createuser -s $USER
sudo mkdir -p /tmp/psql-tablespace
sudo chown postgres.postgres /tmp/psql-tablespace
psql -c "CREATE TABLESPACE tablespacetest LOCATION '/tmp/psql-tablespace'" -d postgres

To get osm2pgsql, I was cloning my own git repo instead of the normal one, but if you wanted to get the source, build the latest version, and run the testsuite, I did it with

1
2
3
4
5
6
git clone https://github.com/openstreetmap/osm2pgsql.git
cd osm2pgsql
./autogen.sh
./configure
make –j4
make check