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):
- 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
- Download postgis-1.x.x.tar.gz wherever you want (e.g., /home/myname/src)
- Extract it:
$ tar xvfz postgis-1.x.x.tar.gz
- Now cd to the postgis-1.x.x directory.
- Now configure:
$ ./configure
- Check to see that you have no errors. You may need to install other packages.
- Compile it:
$ make
- As superuser, install it:
$ sudo make install
- 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
- 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.
- 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
- 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;
Attachments (1)
- postgis_1.4.1-1_i386.deb (1.5 MB ) - added by 15 years ago.
Download all attachments as: .zip