|Version 10 (modified by jeffmeyer, 13 months ago)|
How to Get Started with PostGIS 2.0 on Ubuntu 12.04 (precise)
UNDER CONSTRUCTION AS OF 5/5/12 2000 PT.
This page is targeted at new users and will be written as simply as possible, with plenty of confirmation information.
Install PostGIS 2.0
Installation requirements can be found at PostGIS Support Matrix
Key libraries to focus on: GEOS, GDAL. Issues related to these two libraries will dictate the method you choose to use to install PostGIS 2.0.
Package-Based Installation using the existing Sharpie Oneiric PPA (Personal Package Archive)
The good news: following these steps *will* install PostGIS 2.0 successfully. Thanks, Sharpie!!! : )
sudo apt-get install python-software-properties sudo apt-add-repository ppa:sharpie/for-science sudo apt-add-repository ppa:sharpie/postgis-nightly sudo apt-get update sudo apt-get install postgresql-9.1-postgis
The bad news: it still installs older versions of libGDAL and libGEOS than are recommended in the Support Matrix.
The packages above install will install libGDAL 1.7, instead of the recommended 1.9.
First tricky thing: the existing Precise PPA for libGDAL 1.9 has been built to depend on libGEOS 3.3.2, and libGEOS 3.3.3 is listed as the preferred library in the Support Matrix.
Second tricky thing: the way apt works, if you install everything from apt, you will still not be able to take advantage of these newer libraries. The only way to do that will be to install everything from source, which will make updating versions a little trickier down the road. This is your fork in the road: work with what you can get in the packaged install listed above, or move forward using the steps below.
So, let's see if we can get all of the supporting libraries to the recommended versions.
Hack-ish Installation using a combination of packages and sources
1/4 Install PostgreSQL and other foundations
Several components are needed, which can either be built from source or installed from pre-built packages, as shown below.
Install prerequisite packages using:
sudo apt-get install build-essential postgresql-9.1 postgresql-server-dev-9.1 libxml2-dev proj libjson0-dev xsltproc docbook-xsl docbook-mathml gettext
2/4 Build libGDAL1.9
sudo apt-add-repository ppa:olivier-berten/geo sudo apt-get update sudo apt-get install libgdal-dev
Verify you have the latest version of libGDAL:
$ gdal-config --version 1.9.0
Looks good... what's up with libGEOS?
$ geos-config --version 3.3.2
Crud... not quite 3.3.3. On to the next step.
3/4 Build GEOS 3.3.x
These are the instructions for building geos 3.3.3, based on instructions found elsewhere on trac.osgeo.org with some additions determined through trial and error:
sudo apt-get install g++ ruby ruby1.8-dev swig swig2.0 ''--- added to other instructions, not installed by default in 12.04 & required for this make wget http://download.osgeo.org/geos/geos-3.3.3.tar.bz2 tar xvfj geos-3.3.3.tar.bz2 cd geos-3.3.3 ./configure make sudo make install cd ..
To confirm this works, do the following:
$ geos-config --version 3.3.3
4/4 Build PostGIS
wget http://postgis.refractions.net/download/postgis-2.0.0.tar.gz tar xfvz postgis-2.0.0.tar.gz cd postgis-2.0.0 ./configure --with-gui <--- not sure if the with-gui is required
The end of the configure processing should leave you with something that looks like this:
If this works, you should be ready to ready to finish your installation:
make sudo make install sudo ldconfig sudo make comments-install
Lastly, enable the command-line tools to work from your shell:
sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/raster2pgsql
Spatially-enable a database
With PostgreSQL 9.1, there are two methods to add PostGIS functionality to a database: using extensions, or using enabler scripts.
PostGIS Extension for PostgreSQL
Spatially enabling a database using extensions is a new feature of PostgreSQL 9.1.
Connect to your database using pgAdmin or psql, and run the following commands. To add postgis with raster support:
CREATE EXTENSION postgis;
To add topology support, a second extension can be created on the database:
CREATE EXTENSION postgis_topology;
Enabler Scripts / Template
Enabler scripts can be used to either build a template, or directly spatially enable a database. This method is older than the extension method, but is required if the raster support is not built.
The following example creates a template, which can be re-used for creating multiple spatially-enabled databases. Or if you just want to make one spatially enabled database, you can modify the commands for your needs.
sudo -u postgres createdb template_postgis sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis.sql sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/spatial_ref_sys.sql sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis_comments.sql
with raster support:
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/rtpostgis.sql sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/raster_comments.sql
with topology support:
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology.sql sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology_comments.sql