Geo @ ObjectGraph

Earth and Environmental Science Blog

Hey there! Thanks for dropping by my blog! Take a look around
and grab the RSS feed to stay updated. See you around!

PostGIS – Install and Setup

Install

  • PostgreSQL
  • PostGIS
  • pgAdmin
  • Install GEOS, PROJ, and GDAL

Note: The most helpful installation & setup tips – see ReadMe.rdf in the install package

Download URLs

Environment

  • MacOSX


Setup Path

1
export PATH="/usr/local/pgsql/bin:$PATH"

Setup Spatial Database

Assume “mygis” is your db name.

1
createdb -Upostgres mygis

Run commands from ReadMe.rdf

1
2
3
4
5
sudo su - postgres -c '/usr/local/pgsql/bin/createlang plpgsql mygis'
 
sudo su - postgres -c '/usr/local/pgsql/bin/psql -d mygis -f /usr/local/pgsql/share/contrib/postgis-1.5/postgis.sql'
 
sudo su - postgres -c '/usr/local/pgsql/bin/psql -d mygis -f /usr/local/pgsql/share/contrib/postgis-1.5/spatial_ref_sys.sql'

Login then select mygis database

psql -Upostgres mygis

Create a test table

CREATE TABLE testgeog(gid serial PRIMARY KEY, the_geog geography(POINT,4326) );

More Examples:

CREATE TABLE global_points (
 
id SERIAL PRIMARY KEY,
 
name VARCHAR(64),
 
location GEOGRAPHY(POINT,4326)
 
);
 
INSERT INTO global_points (name, location) VALUES ('Town', ST_GeographyFromText('SRID=4326;POINT(-110 30)') );
 
INSERT INTO global_points (name, location) VALUES ('Forest', ST_GeographyFromText('SRID=4326;POINT(-109 29)') );
 
INSERT INTO global_points (name, location) VALUES ('London', ST_GeographyFromText('SRID=4326;POINT(0 49)') );
 
CREATE INDEX global_points_gix ON global_points USING GIST ( location );

Load Shape File

shp2pgsql zip_usa.shp zip_usa | psql -d mygis -Upostgres mygis
 
psql -Upostgres mygis
SELECT * FROM zip_usa LIMIT 10;
 
SELECT zip, state, ST_AsText(the_geom) FROM zip_usa LIMIT 10;

Update SRID

SELECT UpdateGeometrySRID('zip_usa','the_geom',4326);

Now, try to export data as KML

SELECT ST_AsKML(the_geom) FROM zip_usa LIMIT 10;

Start / Stop manually

sudo launchctl unload -w /Library/LaunchDaemons/org.postgresql.postgres.plist
 
sudo launchctl load -w /Library/LaunchDaemons/org.postgresql.postgres.plist

 

You can leave a response, or trackback from your own site.

3 Responses to “PostGIS – Install and Setup”

  1. gene says:

    Kingchaos offers all versions of Postgresql PostGIS for Mac
    http://www.kyngchaos.com/software/postgres

  2. paul says:

    Hey do you know of an application that works like ArcServer but is free or easy to use/learn. I am not much of a programmer, so something that has little programming would be great. Do you know of anything?

Leave a Reply