DevOps

Installing PostGIS 1.5 on PostgreSQL 8.4 on Ubuntu

I had a bit of trouble installing the latest PostGIS 1.5 under PostgreSQL 8.4. Here are my instructions. These work on Ubuntu 8.04, 9.04, 9.10, 10.04, and 10.10.

UPDATE

This post has been updated to include the awesome instructions from Leo regarding using the postgis-unstable ppa. Thanks Leo!

1. Install PostGIS from PPA

System -> Administration -> Software Sources

Click on the "Other Software" tab.

Click on "+Add"

Enter: "ppa:ubuntugis/ubuntugis-unstable"

More info: https://launchpad.net/~ubuntugis/+archive/ubuntugis-unstable

Now install the package "postgresql-8.4-postgis"

2. Setup your database

createdb my_db
createlang plpgsql my_db
psql -d my_db -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql
psql -d my_db -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql
psql -d my_db -f /usr/share/postgresql/8.4/contrib/postgis_comments.sql

Now you should be able to make a geometry table.

3. Setup your geometry table

At this point I'm showing how to make an example table. Your usage of the PostGIS library will probably differ.

create sequence points_id_seq;
create table points ( id integer primary key default nextval('points_id_seq') );
select AddGeometryColumn('points', 'location', 4326, 'POINT', 2);
create index points_location_idx on points using GIST ( location );

// Create a point
insert into points(location) values (ST_GeomFromText('POINT(-76.615657 39.327052)'));

// Returns the point
select * from points where ST_Distance(location, ST_GeomFromText('POINT(-76 39)')) < 1;

// Does not return the point
select * from points where ST_Distance(location, ST_GeomFromText('POINT(-76 39)')) < .1;
You've successfully subscribed to SmartLogic Blog
Great! Next, complete checkout for full access to SmartLogic Blog
Welcome back! You've successfully signed in.
Unable to sign you in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.