thursday tip day using openstreetmap data in postgis
I was quite excited to find that you can use openstreetmap data in your own GIS environment by loading it into PostgreSQL. To me, this makes it much more useful, as I can now begin to use it as an alternative to costly data from the Ordnance Survey. The procedure took some time (mainly due to trial and error), but the following worked for me in Ubuntu:
-
Install osm2pgsql by downloading it from here using subversion
-
The readme.txt file that accompanies it suggests installing a selection of libraries too, which you should be able to install using apt, with the exception of geos
-
Check to see if you have an existing copy of libgeos and download and install from source from here
-
To ensure that libgeos is reachable, find out where it is installed using which geos-config and edit /etc/ld.conf as root to include the path to it (run ldconfig as root afterwards)
-
Install osm2pgsql by running _make _from the source directory that you downloaded in step 1
-
As your postgresql user, create a new database called “gis”
-
Download the latest planet dump (for UK users, try here for the UK extract)
-
As the postgresql user go to the osm2pgsql source directory from step 1 and run ./osm2pgsql -d gis /path/to/planet/dump.osm.bz2
-
In psql create a spatial index on each of the tables in the gis database using: create index index_name on table.name using gist (geom_column); where you need to find the table names and the name of the geometry column in each case (it’s probably “way”)
-
Some gis will need a primary key and an oid column for each table too.
Note 1: This is a work in progress. I am now trying to figure out how to use this data in both my desktop and web-based GIS. So far I have been able to make a connection to the data using pgarc in Arcmap, but it seems to fail because it wants an ansi encoded database rather than utf8. I can’t make a connection with ziggis at all at the moment. I can make a connection using ogr in mapguide opensource, but it fails when I try and visualise the data, and I couldn’t get the postgis connector to work when I tried it. I have, however, recently found some more information about this so I will keep trying…
Note 2: I couldn’t get the standard osm2pgsql package for ubuntu to work at all, only the source package worked. I think this is to do with the geos library…