Hi Matt,
Dunno what OS you use, but this is my cheat-sheet for getting started with postgis on Ubuntu. It's absolutely fantastic as a way to store and manipulate vector data.
Hope it's useful,
Roger
------------------------------------------
- Postgres
--> copy postgres source to /usr/local and unpack.
--> take a look at the build options:
$ ./configure --help | more
<snip>
--with-perl build Perl modules (PL/Perl)
--with-python build Python modules (PL/Python)
--> so just add the perl and python support then
$ ./configure --with-perl --with-python
$ sudo make
$ sudo make install
------------------------------------------
- Postgis
--> cp postgis source to /usr/local and unpack
--> mv unpacked Postgis INTO PostgreSQL
$ sudo mv postgis-1.3.3/ postgresql-8.3.5/contrib/
$ cd postgresql-8.3.5/contrib/postgis-1.3.3
-->take a look at build options
--with-pgsql[=ARG] build for a specific pgsql version
[ARG=path to pg_config]
--with-geos[=ARG] enable spatial predicates and operators using GEOS
[ARG=path to geos-config]
--with-proj[=DIR] enable reprojection support
--with-proj-libdir=PATH path to PROJ4 libdir
--> taking a guess on the "with-proj" location:
$ ./configure --with-pgsql=/usr/local/pgsql/bin/pg_config
--with-geos=/usr/local/bin/geos-config --with-proj
--> Needed flex
$ sudo apt-get install flex
--> with correct paths to proj stuff
$ sudo ./configure --with-pgsql=/usr/local/pgsql/bin/pg_config
--with-geos=/usr/local/bin/geos-config --with-proj=/usr/local
--with-proj-libdir=/usr/local/lib
SUMMARY
HOST_OS: linux-gnu
PGSQL: /usr/local/pgsql/bin/pg_config
GEOS: /usr/local/bin/geos-config (with C-API)
(ldflags: -L/usr/local/lib)
PROJ: prefix=/usr/local libdir=/usr/local/lib
ICONV: 1
PORTNAME: linux
PREFIX: /usr/local/pgsql
EPREFIX: ${prefix}
DOC: /usr/local/pgsql/doc/contrib
DATA: ${datarootdir}
MAN: ${datarootdir}/man
BIN: /usr/local/pgsql/bin
EXT: /usr/local/pgsql/lib (\$$libdir)
$ sudo make
$ sudo make install
--> ok, its installed, but certainly not configured.
-----------------------------------------------
--> create a new location for database to live in:
mkdir postgis
chmod -R 777 postgis/
--> add path to postgres bin to PATH
which initdb
which createdb
--> initialize postgresql instance and start daemon:
/usr/local/pgsql/bin/initdb -D /home/randre/gis_data/postgis/
/usr/local/pgsql/bin/pg_ctl -D /home/randre/gis_data/postgis -l
postgis.log start
--> create new database:
createdb --encoding UTF8 unep
createlang plpgsql unep
psql -f /usr/local/postgresql-8.3.5/contrib/postgis-1.3.3/lwpostgis.sql
-d unep
psql -f /usr/local/postgresql-8.3.5/contrib/postgis-1.3.3/spatial_ref_sys.sql
-d unep
--> convert a shapefile into an SQL load file and load into database:
shp2pgsql -s 4326 -D unep_coastlines coastlines unep > coastlines.sql
vi coastlines.sql
psql -d unep -f coastlines.sql
--> dump some features from PostGIS into a shapefile
pgsql2shp -h localhost -f china_mask.shp unep "select
ST_Difference(canvas.the_geom, china.the_geom) FROM canvas, china
WHERE china.name='China';"
--------------------------------
Comments0