CREATING NEW SPATIAL DATABASES
------------------------------
-PostGIS support must be enabled for each database that requires its usage.
-This is done by feeding the ``postgis.sql`` (the enabler script) file to the
-target database.
-
-The enabler script requires the PL/pgSQL procedural language in order to
-operate correctly, you can use the ``createlang`` program from the PostgreSQL
-installation.
-
-(The PostgreSQL Programmer's Guide has details if you want to do this
-manually for some reason.)
-
-So, as postgres run::
-
- createlang plpgsql <yourdatabase>
- psql -f postgis/postgis.sql -d <your_database>
-
-Your database should now be spatially enabled.
-
-
-ADDING RASTER SUPPORT TO A SPATIAL DATABASE
--------------------------------------------
-
-To enable raster support you must first load the ``postgis.sql`` file.
-You can then load the ``rtpostgis.sql`` file.
-
- psql -f postgis/rtpostgis.sql -d <your_database>
+PostGIS support must be enabled for each database that requires its usage.
+Enabling spatial functionality requires a PostgreSQL super-user.
+ CREATE EXTENSION postgis;
+
UPGRADING EXISTING SPATIAL DATABASES
------------------------------------
-Upgrading existing spatial databases can be tricky as it requires replacement
-or introduction of new PostGIS object definitions.
-
-Unfortunately not all definitions can be easily replaced in a live database, so
-sometimes your best bet is a dump/reload process.
-
-PostGIS provides a SOFT UPGRADE procedure for minor or bugfix releases, and an
-HARD UPGRADE procedure for major releases.
-
-SOFT UPGRADE
-~~~~~~~~~~~~
-
-Soft upgrade consists of sourcing the ``postgis_upgrade_*.sql`` script in your
-spatial database:
-
- * ``postgis_upgrade_13_to_15.sql``, upgrade a 1.3.x database to 1.5
- * ``postgis_upgrade_15_to_15.sql``, upgrade a 1.4.x database to 1.5
- * ``postgis_upgrade_16_minor.sql``, upgrade a 1.5.x database to the latest
- minor release
-
-If a soft upgrade is not possible the script will abort and no harm will be
-done. You can then move on to the HARD UPGRADE process. Always try a soft
-upgrade first; they are much simpler.
-
-HARD UPGRADE
-~~~~~~~~~~~~
-
-Hard upgrade is a PostgreSQL dump/restore procedure combined with a filter to
-selectively update PostGIS functions and objects to point to a new library
-version.
-
-Hard upgrades are required when object definitions have changed, aggregates
-have changed or been added, and when the underlying PostgreSQL database itself
-has undergone a major update.
-
-For this purpose, PostGIS provides a utility script to restore a dump in
-"custom" format. The hard upgrade procedure is as follows::
-
- # [1] Create a "custom-format" dump of the database you want
- # to upgrade (let's call it "olddb")
- $ pg_dump -Fc -f olddb.dump olddb
-
- # [2] Do a fresh install of PostGIS in a new database
- # (let's call it "newdb").
- # Refer to CREATING NEW SPATIAL DATABASES for instructions
-
- # [3] Restore the dump into your new database.
- $ perl utils/postgis_restore.pl -v olddb.dump \
- 2> restore.log | psql newdb 2> errors.log
-
-The ``spatial_ref_sys`` entries found in your dump will be restored, but they
-will not override existing ones in ``spatial_ref_sys``. This is to ensure that
-fixes in the official set will be properly propagated to restored databases.
-If for any reason you really want your own overrides of standard entries just
-don't load the ``spatial_ref_sys.sql`` file when creating the new database.
-
-If your database is really old or you know you've been using long deprecated
-functions in your views and functions, you might need to load ``legacy.sql``
-before restoring the dump for all your functions and views etc. to properly
-come back. Only do this if *really* needed. Consider upgrading your views and
-functions before dumping instead, if possible. The deprecated functions can be
-later removed by loading ``uninstall_legacy.sql``.
+Upgrade PostGIS using the "ALTER EXTENSION" facility.
+ ALTER EXTENSION postgis UPDATE TO '2.2.0';
+
USAGE
-----
VALUES ( 2, 'LINESTRING(1 1 1,5 5 5,7 7 5)', '3D Line' );
INSERT INTO geom_test ( gid, geom, name )
VALUES ( 3, 'MULTIPOINT(3 4,8 9)', '2D Aggregate Point' );
- SELECT * from geom_test WHERE geom && 'BOX3D(2 2 0,3 3 0)'::box3d;
+ SELECT * from geom_test WHERE ST_Intersects(geom, ST_MakeEnvelope(2,2,3,3));
The following SQL creates proper OpenGIS entries in the ``SPATIAL_REF_SYS``
and ``GEOMETRY_COLUMNS`` tables, and ensures that all geometries are created
with an SRID::
- INSERT INTO SPATIAL_REF_SYS
- ( SRID, AUTH_NAME, AUTH_SRID, SRTEXT ) VALUES
- ( 1, 'EPSG', 4269,
- 'GEOGCS["NAD83",
- DATUM[
- "North_American_Datum_1983",
- SPHEROID[
- "GRS 1980",
- 6378137,
- 298.257222101
- ]
- ],
- PRIMEM["Greenwich",0],
- UNIT["degree",0.0174532925199433]]'
- );
-
CREATE TABLE geotest (
id INT4,
- name VARCHAR(32)
+ name VARCHAR(32),
+ geopoint GEOMETRY(POINT, 4326)
);
- SELECT AddGeometryColumn('db', 'geotest', 'geopoint', 1, 'POINT', 2);
-
INSERT INTO geotest (id, name, geopoint)
- VALUES (1, 'Olympia', ST_GeomFromText('POINT(-122.90 46.97)', 1));
+ VALUES (1, 'Olympia', ST_GeomFromText('POINT(-122.90 46.97)', 4326));
INSERT INTO geotest (id, name, geopoint)
- VALUES (2, 'Renton', ST_GeomFromText('POINT(-122.22 47.50)', 1));
+ VALUES (2, 'Renton', ST_GeomFromText('POINT(-122.22 47.50)', 4326));
SELECT name, AsText(geopoint) FROM geotest;