wiki:UsersWikiPostgisOnUbuntu

How To Install PostGIS on Ubuntu (draft)

Installation

From Packages (aka, the easy way):

PostGIS and Postgresql are available as packages for Ubuntu 6.10 and greater. To install, use either:

apt-get install postgresql-8.3-postgis postgis

Try to download the DEB package here:

http://trac.osgeo.org/postgis/attachment/wiki/UsersWikiPostgisOnUbuntu/postgis_1.4.1-1_i386.deb Install it by double click, first you have to install PostgreSQL.

OR

Use adept or synaptic and select packages:

postgresql-8.3-postgis

postgis

NOTE: The "Universe" repository must be enabled.

NOTE: postgresql-8.4 is current as of 12/2009. You should, of course, use the current version.

From Source (aka, the hard way):

  1. Install Postgresql, Libgeos, Proj. packages. Easiest way is to use Synaptic (be sure to include Universe in your respositories). Also be sure to install the "-dev" packages (postgresql-server-dev-8.4). E.g.:

$ sudo apt-get install postgresql-server-8.4-dev libool gcc flex bison libxml2-dev

  1. Download postgis-1.x.x.tar.gz wherever you want (e.g., /home/myname/src)
  1. Extract it:

$ tar xvfz postgis-1.x.x.tar.gz

  1. Now cd to the postgis-1.x.x directory.
  1. Now configure:

$ ./configure

  1. Check to see that you have no errors. You may need to install other packages.
  1. Compile it:

$ make

  1. As superuser, install it:

$ sudo make install

  1. You may need to make sure the libraries are visible to PostgreSQL

$ sudo ldconfig

That should do it.

Optional packages to build documentation

$ sudo apt-get install imagemagick dblatex xsltproc docbook-xsl

$ make docs


Using PostGIS

  1. Create a database. You must be the postgres superuser to do this: = From the shell:

$ createdb mytestdb

TIP: if you get permission errors, try:

$ sudo su postgres $ createdb mytestdb

REMEMBER: type 'exit' when you're done with these postgres commands to return to your normal user.

  1. Set up the postgis libs:

$ createlang plpgsql mytestdb

2a. If you installed from packages:

$ psql -d mytestdb -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql

if there were no errors (if the last line of output is COMMIT), then

$ psql -d mytestdb -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql

NOTE: Fedora 7 installed from package path is /usr/share/pgsql/contrib/

2b. If you installed from source:

Pre postgresql 8.4 versions:

$ psql -d mytestdb -f /usr/share/postgresql/8.0/contrib/postgis-1.1.1/lwpostgis.sql

$ psql -d mytestdb -f /usr/share/postgresql/8.0/contrib/postgis-1.1.1/spatial_ref_sys.sql

In postgresql 8.4 lwpostgis.sql was moved and renamed, but spatial_ref_sys.sql remains the same though, so:

$ psql -d mytestdb -f /usr/share/postgresql/8.4/contrib/postgis-1.5.1/postgis/postgis.sql

$ psql -d mytestdb -f /usr/share/postgresql/8.4/contrib/postgis-1.5.1/spatial_ref_sys.sql

  1. Make sure that your DB user has GRANT ALL on the "geometry_columns" table and GRANT SELECT on "spatial_ref_sys".

Now import a shp file:

$ shp2pgsql -D myshape.shp mytable mytestdb | psql mytestdb

This will take the input file "myshape.shp" and create a new table, "mytable" in the database "mytestdb."

To see if your shape file is there:

$ psql mytestdb mytestdb=# SELECT * from mytable;

Last modified 8 years ago Last modified on Jun 4, 2010 4:23:57 PM

Attachments (1)

Download all attachments as: .zip