Changes between Initial Version and Version 1 of UsersWikiPostGIS20Ubuntu1204


Ignore:
Timestamp:
May 5, 2012, 8:11:15 PM (12 years ago)
Author:
jeffmeyer
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiPostGIS20Ubuntu1204

    v1 v1  
     1= How to install PostGIS 2.0 on Ubuntu 12.04 (''precise'') =
     2UNDER CONSTRUCTION AS OF 5/5/12 2000 PT.
     3
     4This page is targeted at new users and will be written as simply as possible.
     5
     6== Source or Packaged? ==
     7The page is in development. Methods posted below are accurate as of last page update.
     8
     9== Prerequisites ==
     10Prerequisites can be found at [wiki:UsersWikiPostgreSQLPostGIS PostGIS Support Matrix]
     11
     12Key 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.
     13
     14=== Installation using the existing Sharpie Oneiric PPA (Personal Package Archive) ===
     15
     16The good news: following these steps *will* install PostGIS 2.0 successfully.
     17
     18{{{
     19sudo apt-get install python-software-properties
     20sudo apt-add-repository ppa:sharpie/for-science
     21sudo apt-add-repository ppa:sharpie/postgis-nightly
     22sudo apt-get update
     23sudo apt-get install postgresql-9.1-postgis
     24}}}
     25
     26The bad news: it still installs an older version of libGDAL - 1.7 - which is listed as "not recommended" in the [wiki:UsersWikiPostgreSQLPostGIS Support Matrix].
     27libGDAL 1.9 is recommended.
     28
     29Tricky thing: 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.
     30
     31=== Build GEOS 3.3.x ===
     32
     33PostGIS 2.0 requires GEOS >= 3.3.2 for topology support, however Ubuntu 11.10 only has GEOS 3.2.2 available in packages, so it needs to be built from source. If you don't need topology, you don't ''need'' to build this component, but it is highly recommended.
     34
     35These are the instructions for building geos 3.3.3, but they did not work for me in 12.04:
     36{{{
     37wget http://download.osgeo.org/geos/geos-3.3.3.tar.bz2
     38tar xvfj geos-3.3.3.tar.bz2
     39cd geos-3.3.3
     40./configure
     41make   --- this failed
     42sudo make install
     43cd ..
     44}}}
     45
     46{{{make failure:
     47make[4]: Entering directory `/home/jeffme/geos-3.3.3/src/algorithm/locate'
     48source='IndexedPointInAreaLocator.cpp' object='IndexedPointInAreaLocator.lo' libtool=yes \
     49        DEPDIR=.deps depmode=none /bin/bash ../../../depcomp \
     50        /bin/bash ../../../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I../../../include -I../../../include/geos -I../../../include    -DGEOS_INLINE  -pedantic -Wall -ansi -Wno-long-long  -ffloat-store  -c -o IndexedPointInAreaLocator.lo IndexedPointInAreaLocator.cpp
     51libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../../../include -I../../../include/geos -I../../../include -DGEOS_INLINE -pedantic -Wall -ansi -Wno-long-long -ffloat-store -c IndexedPointInAreaLocator.cpp  -o .libs/IndexedPointInAreaLocator.o
     52../../../libtool: line 1128: g++: command not found
     53make[4]: *** [IndexedPointInAreaLocator.lo] Error 1
     54make[4]: Leaving directory `/home/jeffme/geos-3.3.3/src/algorithm/locate'
     55make[3]: *** [all-recursive] Error 1
     56make[3]: Leaving directory `/home/jeffme/geos-3.3.3/src/algorithm/locate'
     57make[2]: *** [all-recursive] Error 1
     58make[2]: Leaving directory `/home/jeffme/geos-3.3.3/src/algorithm'
     59make[1]: *** [all-recursive] Error 1
     60make[1]: Leaving directory `/home/jeffme/geos-3.3.3/src'
     61make: *** [all-recursive] Error 1
     62}}}
     63
     64
     65
     66
     67
     68
     69
     70
     71Several components are needed, which can either be built from source or installed from pre-built packages, as shown below.
     72
     73Install prerequisite packages using:
     74{{{
     75sudo apt-get install build-essential postgresql-9.1 postgresql-server-dev-9.1 libxml2-dev proj libjson0-dev xsltproc docbook-xsl docbook-mathml
     76}}}
     77
     78Optional package for raster support (this is required if you want to build the PostgreSQL extensions):
     79{{{
     80sudo apt-get install libgdal-dev
     81}}}
     82
     83
     84
     85== Build PostGIS ==
     86{{{
     87wget http://postgis.refractions.net/download/postgis-2.0.0.tar.gz
     88tar xfvz postgis-2.0.0.tar.gz
     89cd postgis-2.0.0
     90}}}
     91
     92PostGIS 2.0 can be configured to disable topology or raster components, using the configure flags `--without-raster` and/or `--without-topology`. The default is to build both. Note that raster is required for the extension installation method for PostgreSQL.
     93{{{
     94./configure
     95make
     96sudo make install
     97sudo ldconfig
     98sudo make comments-install
     99}}}
     100
     101Lastly, enable the command-line tools to work from your shell:
     102{{{
     103sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql
     104sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp
     105sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/raster2pgsql
     106}}}
     107
     108== Spatially enabling a database ==
     109With PostgreSQL 9.1, there are two methods to add PostGIS functionality to a database: using extensions, or using enabler scripts.
     110
     111=== PostGIS Extension for PostgreSQL ===
     112Spatially enabling a database using extensions is a new feature of PostgreSQL 9.1.
     113
     114Connect to your database using pgAdmin or psql, and run the following commands. To add postgis with raster support:
     115{{{
     116CREATE EXTENSION postgis;
     117}}}
     118
     119To add topology support, a second extension can be created on the database:
     120{{{
     121CREATE EXTENSION postgis_topology;
     122}}}
     123
     124=== Enabler Scripts / Template ===
     125
     126Enabler 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.
     127
     128The 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.
     129
     130PostGIS:
     131{{{
     132sudo -u postgres createdb template_postgis
     133sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis.sql
     134sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/spatial_ref_sys.sql
     135sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis_comments.sql
     136}}}
     137
     138with raster support:
     139{{{
     140sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/rtpostgis.sql
     141sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/raster_comments.sql
     142}}}
     143
     144with topology support:
     145{{{
     146sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology.sql
     147sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology_comments.sql
     148}}}
     149
     150== See also ==
     151 * https://help.ubuntu.com/community/PostgreSQL
     152 * [wiki:UsersWikiPostGIS20Ubuntu1204 Install PostGIS 2.0 on Ubuntu 12.04 Precise Pangolin]