| 1 | = How to install PostGIS 2.0 on Ubuntu 12.04 (''precise'') = |
| 2 | UNDER CONSTRUCTION AS OF 5/5/12 2000 PT. |
| 3 | |
| 4 | This page is targeted at new users and will be written as simply as possible. |
| 5 | |
| 6 | == Source or Packaged? == |
| 7 | The page is in development. Methods posted below are accurate as of last page update. |
| 8 | |
| 9 | == Prerequisites == |
| 10 | Prerequisites can be found at [wiki:UsersWikiPostgreSQLPostGIS PostGIS Support Matrix] |
| 11 | |
| 12 | 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. |
| 13 | |
| 14 | === Installation using the existing Sharpie Oneiric PPA (Personal Package Archive) === |
| 15 | |
| 16 | The good news: following these steps *will* install PostGIS 2.0 successfully. |
| 17 | |
| 18 | {{{ |
| 19 | sudo apt-get install python-software-properties |
| 20 | sudo apt-add-repository ppa:sharpie/for-science |
| 21 | sudo apt-add-repository ppa:sharpie/postgis-nightly |
| 22 | sudo apt-get update |
| 23 | sudo apt-get install postgresql-9.1-postgis |
| 24 | }}} |
| 25 | |
| 26 | The bad news: it still installs an older version of libGDAL - 1.7 - which is listed as "not recommended" in the [wiki:UsersWikiPostgreSQLPostGIS Support Matrix]. |
| 27 | libGDAL 1.9 is recommended. |
| 28 | |
| 29 | Tricky 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 | |
| 33 | PostGIS 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 | |
| 35 | These are the instructions for building geos 3.3.3, but they did not work for me in 12.04: |
| 36 | {{{ |
| 37 | wget http://download.osgeo.org/geos/geos-3.3.3.tar.bz2 |
| 38 | tar xvfj geos-3.3.3.tar.bz2 |
| 39 | cd geos-3.3.3 |
| 40 | ./configure |
| 41 | make --- this failed |
| 42 | sudo make install |
| 43 | cd .. |
| 44 | }}} |
| 45 | |
| 46 | {{{make failure: |
| 47 | make[4]: Entering directory `/home/jeffme/geos-3.3.3/src/algorithm/locate' |
| 48 | source='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 |
| 51 | libtool: 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 |
| 53 | make[4]: *** [IndexedPointInAreaLocator.lo] Error 1 |
| 54 | make[4]: Leaving directory `/home/jeffme/geos-3.3.3/src/algorithm/locate' |
| 55 | make[3]: *** [all-recursive] Error 1 |
| 56 | make[3]: Leaving directory `/home/jeffme/geos-3.3.3/src/algorithm/locate' |
| 57 | make[2]: *** [all-recursive] Error 1 |
| 58 | make[2]: Leaving directory `/home/jeffme/geos-3.3.3/src/algorithm' |
| 59 | make[1]: *** [all-recursive] Error 1 |
| 60 | make[1]: Leaving directory `/home/jeffme/geos-3.3.3/src' |
| 61 | make: *** [all-recursive] Error 1 |
| 62 | }}} |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | Several components are needed, which can either be built from source or installed from pre-built packages, as shown below. |
| 72 | |
| 73 | Install prerequisite packages using: |
| 74 | {{{ |
| 75 | sudo 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 | |
| 78 | Optional package for raster support (this is required if you want to build the PostgreSQL extensions): |
| 79 | {{{ |
| 80 | sudo apt-get install libgdal-dev |
| 81 | }}} |
| 82 | |
| 83 | |
| 84 | |
| 85 | == Build PostGIS == |
| 86 | {{{ |
| 87 | wget http://postgis.refractions.net/download/postgis-2.0.0.tar.gz |
| 88 | tar xfvz postgis-2.0.0.tar.gz |
| 89 | cd postgis-2.0.0 |
| 90 | }}} |
| 91 | |
| 92 | PostGIS 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 |
| 95 | make |
| 96 | sudo make install |
| 97 | sudo ldconfig |
| 98 | sudo make comments-install |
| 99 | }}} |
| 100 | |
| 101 | Lastly, enable the command-line tools to work from your shell: |
| 102 | {{{ |
| 103 | sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql |
| 104 | sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp |
| 105 | sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/raster2pgsql |
| 106 | }}} |
| 107 | |
| 108 | == Spatially enabling a database == |
| 109 | With 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 === |
| 112 | Spatially enabling a database using extensions is a new feature of PostgreSQL 9.1. |
| 113 | |
| 114 | Connect to your database using pgAdmin or psql, and run the following commands. To add postgis with raster support: |
| 115 | {{{ |
| 116 | CREATE EXTENSION postgis; |
| 117 | }}} |
| 118 | |
| 119 | To add topology support, a second extension can be created on the database: |
| 120 | {{{ |
| 121 | CREATE EXTENSION postgis_topology; |
| 122 | }}} |
| 123 | |
| 124 | === Enabler Scripts / Template === |
| 125 | |
| 126 | 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. |
| 127 | |
| 128 | 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. |
| 129 | |
| 130 | PostGIS: |
| 131 | {{{ |
| 132 | sudo -u postgres createdb template_postgis |
| 133 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis.sql |
| 134 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/spatial_ref_sys.sql |
| 135 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis_comments.sql |
| 136 | }}} |
| 137 | |
| 138 | with raster support: |
| 139 | {{{ |
| 140 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/rtpostgis.sql |
| 141 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/raster_comments.sql |
| 142 | }}} |
| 143 | |
| 144 | with topology support: |
| 145 | {{{ |
| 146 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology.sql |
| 147 | sudo -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] |