| 1 | = How to install PostGIS 2.0 on Ubuntu 12.10 (''quantal'') from source = |
| 2 | |
| 3 | == Prerequisites == |
| 4 | Several components are needed, which can either be built from source or installed from pre-built packages, as shown below. |
| 5 | |
| 6 | Install prerequisite packages using: |
| 7 | {{{ |
| 8 | sudo apt-get install build-essential postgresql-9.1 postgresql-server-dev-9.1 libgeos-c1 libxml2-dev libproj-dev libjson0-dev xsltproc docbook-xsl docbook-mathml |
| 9 | }}} |
| 10 | |
| 11 | Optional package for raster support (this is required if you want to build the PostgreSQL extensions): |
| 12 | {{{ |
| 13 | sudo apt-get install libgdal1-dev |
| 14 | }}} |
| 15 | |
| 16 | == Build PostGIS == |
| 17 | {{{ |
| 18 | wget http://download.osgeo.org/postgis/source/postgis-2.0.1.tar.gz |
| 19 | tar xfvz postgis-2.0.1.tar.gz |
| 20 | cd postgis-2.0.1 |
| 21 | }}} |
| 22 | |
| 23 | 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. |
| 24 | {{{ |
| 25 | ./configure |
| 26 | make |
| 27 | sudo make install |
| 28 | sudo ldconfig |
| 29 | sudo make comments-install |
| 30 | }}} |
| 31 | |
| 32 | Lastly, enable the command-line tools to work from your shell: |
| 33 | {{{ |
| 34 | sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql |
| 35 | sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp |
| 36 | sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/raster2pgsql |
| 37 | }}} |
| 38 | |
| 39 | == Spatially enabling a database == |
| 40 | With PostgreSQL 9.1, there are two methods to add PostGIS functionality to a database: using extensions, or using enabler scripts. |
| 41 | |
| 42 | === PostGIS Extension for PostgreSQL === |
| 43 | Spatially enabling a database using extensions is a new feature of PostgreSQL 9.1. |
| 44 | |
| 45 | Connect to your database using pgAdmin or psql, and run the following commands. To add postgis with raster support: |
| 46 | {{{ |
| 47 | CREATE EXTENSION postgis; |
| 48 | }}} |
| 49 | |
| 50 | To add topology support, a second extension can be created on the database: |
| 51 | {{{ |
| 52 | CREATE EXTENSION postgis_topology; |
| 53 | }}} |
| 54 | |
| 55 | === Enabler Scripts / Template === |
| 56 | |
| 57 | 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. |
| 58 | |
| 59 | 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. |
| 60 | |
| 61 | PostGIS: |
| 62 | {{{ |
| 63 | sudo -u postgres createdb template_postgis |
| 64 | sudo -u postgres psql -d template_postgis -c "UPDATE pg_database SET datistemplate=true WHERE datname='template_postgis'" |
| 65 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis.sql |
| 66 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/spatial_ref_sys.sql |
| 67 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis_comments.sql |
| 68 | }}} |
| 69 | |
| 70 | with raster support: |
| 71 | {{{ |
| 72 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/rtpostgis.sql |
| 73 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/raster_comments.sql |
| 74 | }}} |
| 75 | |
| 76 | with topology support: |
| 77 | {{{ |
| 78 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology.sql |
| 79 | sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology_comments.sql |
| 80 | }}} |
| 81 | |
| 82 | == See also == |
| 83 | * https://help.ubuntu.com/community/PostgreSQL |