====== PostGIS ====== PostGIS is a PostgreSQL extension for geo spatial searches and processing. ===== Installation ===== Install PostgreSQL from your normal package management system. Also install the postgis extension, postgis or postgresql-9.1-postgis (the version may vary). Crunchbang 11 waldorf based on Debian 7 "Wheezy" comes with PostgreSQL version 9.1 which is fine. But the PostGIS extension is 1.5 (2.x is current). So we have to look for documentation for PostGIS 1.5, [[http://postgis.net/docs/manual-1.5/ch02.html#id354617 | PostGIS - Create a spatially-enabled database]].
The first step in creating a PostGIS database is to create a simple PostgreSQL database. createdb [yourdatabase] Many of the PostGIS functions are written in the PL/pgSQL procedural language. As such, the next step to create a PostGIS database is to enable the PL/pgSQL language in your new database. This is accomplish by the command createlang plpgsql [yourdatabase] Now load the PostGIS object and function definitions into your database by loading the postgis.sql definitions file (located in [prefix]/share/contrib as specified during the configuration step). psql -d [yourdatabase] -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql For a complete set of EPSG coordinate system definition identifiers, you can also load the spatial_ref_sys.sql definitions file and populate the spatial_ref_sys table. This will permit you to perform ST_Transform() operations on geometries. psql -d [yourdatabase] -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql If you wish to add comments to the PostGIS functions, the final step is to load the postgis_comments.sql into your spatial database. The comments can be viewed by simply typing \dd [function_name] from a psql terminal window. psql -d [yourdatabase] -f /usr/share/postgresql/9.1/contrib/postgis_comments.sql PostGIS - 2.5 Create a spatially-enabled database