PostGIS - Geographic Information Systems Extensions to PostgreSQL
=================================================================

:Version: 3.7.0
:Date: 2026-09-07
:Website: https://postgis.net

This distribution contains a module which implements GIS simple features, ties
the features to R-tree indexing, and provides many spatial functions for
accessing and analyzing geographic data.

Directory structure::

  ./            Build scripts and install directions
  ./deps        Extra dependencies
  ./doc         PostGIS Documentation
  ./extensions  Support for the PostgreSQL Extensions framework
  ./extras      Various pieces that didn't belong to mainstream
                (package management specfiles, sample WKB parser)
  ./fuzzers     Google fuzz tests for liblwgeom
  ./liblwgeom   LWGEOM geometry library
  ./libpgcommon PostGIS library to bridge LWGEOM to PostgreSQL
  ./loader      A program to convert ESRI Shape files into SQL text suitable
                for uploading into a PostGIS/PostgreSQL database and a program
                for converting PostGIS spatial tables into shapefiles
  ./macros      autoconf helper macros
  ./postgis     PostGIS library source code
  ./raster      PostGIS rasters extension source code
  ./regress     Online regression tests
  ./sfcgal      PostGIS sfcgal extension source code and tests
  ./topology    PostGIS topology extension source code
  ./utils       Utility scripts for PostGIS (upgrade, profiling, ...)


REQUIREMENTS
------------

PostGIS is compatible with PostgreSQL 14 and above.
Current release, PostgreSQL, dependency, and packaging support details are
maintained in the PostGIS compatibility browser:

  https://postgis.net/development/compatibility/

You *must* have the full PostgreSQL - including server headers - installed for
this to work.

For apt-based GNU/Linux systems you can run this command to install most of the
below dependencies (except for GTK):

  sudo apt-get install \
    docbook-xsl-ns \
    gettext \
    libgdal-dev \
    libgeos-dev \
    libgmp-dev \
    libjson-c-dev \
    libproj-dev \
    libprotobuf-c-dev \
    libsfcgal-dev \
    libxml2-dev \
    libxml2-utils \
    perl \
    pkg-config \
    protobuf-c-compiler \
    xsltproc

* PROJ (Required, Version 6.1 or higher):

  The PROJ cartographic projection library is required for map projection /
  datum transformation support such as the ST_Transform() function. It is a
  hard build requirement; configure fails if it cannot be found.

    https://proj.org

* GEOS (Required, Version 3.10 or higher)
  - 3.15+ for ST_CoverageEdges
  - 3.14+ for ST_CoverageClean, raster ST_IntersectionFractions
  - 3.12+ for ST_CoverageSimplify and ST_CoverageInvalidEdges
  - 3.11+ for improved ST_ConcaveHull, ST_lineMerge,
    and new functions ST_SimplifyPolygonHull, ST_TriangulatePolygon

  The GEOS library provides support for exact topological tests such as
  ST_Touches(), ST_Contains(), ST_Disjoint() and spatial operations such as
  ST_Intersection(), ST_Union() and ST_Buffer().

    https://libgeos.org

* XML SUPPORT / libxml2 (Required):

  The LibXML2 library is required to use the ST_GeomFromGML() and
  ST_GeomFromKML() functionality. It is a hard build requirement; configure
  fails if it cannot be found.

    http://xmlsoft.org/

* GMP (Required):

  The GMP arbitrary precision arithmetic library is required by PostGIS
  topology support. It is detected via pkg-config and has no fallback, so
  ``pkg-config`` must be available for a default build.

    https://gmplib.org

* iconv/libiconv (Required):

  The iconv conversion library is required by the shp2pgsql loader for encoding
  conversion. On GNU/Linux systems it is typically provided by libc; on other
  platforms you may need a separate libiconv package.

* GNU gettext (Optional)

  GNU gettext is used for loader and documentation translation support. It may
  be disabled with ``--with-gettext=no``.

* JSON-C (Optional)

  JSON-C is used to import GeoJSON via the function ST_GeomFromGeoJson().
  It is enabled by default but optional; if it is not found configure only
  warns and the build continues. Disable with ``--without-json``.

    http://github.com/json-c/json-c/wiki

* GDAL (Required for raster, Version 2.4 or higher 3+ is strongly recommended)

  GDAL (https://gdal.org) is *required* if you want to compile PostGIS
  with raster support. To compile without raster support you
  must ``./configure --without-raster``

* SFCGAL 1.3.1+ (Optional) needed for advanced 3D support
* SFCGAL 2.3+ is required for all postgis_sfcgal extension features.

  https://sfcgal.gitlab.io/sfcgal

* protobuf-c (Optional, Version 1.1.0 or higher, enabled by default)

  The protobuf-c library and compiler are required to enable ST_AsMVT and
  ST_AsGeobuf output. Both the ``libprotobuf-c`` library and the ``protoc-c``
  compiler are needed; the compiler is a hard error if you request protobuf
  support but cannot find it. Disable with ``--without-protobuf``. Also,
  pkg-config is used to verify the correct minimum version of protobuf-c.

    https://github.com/protobuf-c/protobuf-c

* GTK (Optional, Version 2 series: 2.8.0 or higher)

  The GTK library is required to build the GUI version of shp2pgsql
  loader.

  To get packages on apt-based systems:

    apt-get install libgtk2.0-dev

Documentation Building
----------------------

Building the documentation requires the following in addition to the apt
packages listed above (``docbook-xsl-ns``, ``libxml2-utils`` and ``xsltproc``):

* Python 3 -- required to run the manual example tester that generates the
  visual examples which HTML and PDF embed. Those SVGs come from running the
  staged PostGIS build against a live PostgreSQL server via ``make -C regress
  visual-examples``; no Python database driver is required (the tooling talks
  to the server through the ``psql`` client).

* An SVG rasterizer for PDF output -- ``rsvg-convert`` (from librsvg) is
  preferred, with GraphicsMagick (``gm``) or ImageMagick (``convert`` /
  ``magick``) as fallbacks. HTML and EPUB embed the SVG files directly and do
  not need a rasterizer.

CONFIGURATION
-------------

To configure PostGIS, run::

  ./configure

Far faster math processing use below, may not work on all platforms:

  ./configure --enable-lto

If the configure file is missing you must be using a development version
of the code. In that case call ./autogen.sh to generate it.

The results of the configuration can be easily seen within the
``postgis_config.h`` file.

If ``pg_config`` can't be found in your ``$PATH`` configure will complain
and refuse to proceed. You can specify it using the
``--with-pgconfig=/path/to/pg_config`` flag.

PostGIS supports pkg-config for most dependencies.

If PROJ has been installed but cannot be found, configure will complain and
refuse to proceed. You can specify an alternative installation directory using
the ``--with-projdir=DIR`` option.

If GEOS has been installed but cannot be found, configure will complain and
refuse to proceed. You can specify an alternative ``geos-config`` file using
the ``--with-geosconfig=/path/to/geos-config`` option.

If GDAL cannot be found, configure will complain and refuse to proceed.
You can either proceed without raster support using ``--without-raster``
or use ``--with-gdalconfig=/path/to/gdal-config`` option.

By default, both Topology and Raster extensions are enabled in ``./configure``.

If you want to compile PostGIS *without* Raster support,
you must provide the ``--without-raster`` option.

If you want to compile PostGIS *without* Topology support,
you must provide the ``--without-topology`` option.

If you want to compile PostGIS *without* Protobuf formats support,
you must provide the ``--without-protobuf`` option.

PostGIS will be compiled with sfcgal support if it is found.
You can explicitly state the location with --with-sfcgal=path/to/sfcgal

See ``./configure --help`` for more options.


BUILD
-----

PostGIS uses the GNU make (aka gmake) for building. To build PostGIS library
and utilities, as postgres run::

  make


TESTING
-------

You want to run regress tests before installation. To do so, as postgres run::

  make check

The above will create a test database with PostGIS extensions, run tests and
then drop the test database.

Final lines of output contain a summary of test results: run, succeeded,
failed. If you have any failure please file a bug report using the online bug
tracker: http://trac.osgeo.org/postgis/report/3

DEBUGGING
---------

The normal build and testing procedure might not be enough for development and
debugging as that requires a debug build of PostgreSQL and other proper compilation
flags throughout. A way to get such an environment is to use the same docker images
as the PostGIS CI setup and that can be done on a *nix host by first running this
in a cloned postgis repository to later get core dump log output:

> sudo bash ./ci/github/logbt --setup

Then you can run the following to get a docker container up and running with the
correct requirements already in place and the postgis repository (at `/postgis`)
mounted into it:

> docker run -it --mount type=bind,source=/postgis,target=/src/postgis \
postgis/postgis-build-env:pg13-geos39-gdal31-proj71 /bin/bash

And finally the following command inside the container will build and run all the
postgis tests:

> bash ./ci/github/run_usan_gcc.sh

You can make customized versions of `run_usan_gcc.sh` to run only specific tests
and skip redundant steps.

If you need to get debug level logging in the PostgreSQL logs you can get it by
manipulating configuration in the container. Add these lines after the `./configure`
step:

```sh
sed -i 's/POSTGIS_DEBUG_LEVEL [0-9]$/POSTGIS_DEBUG_LEVEL 4/' postgis_config.h
sed -i 's/#log_min_messages = warning/log_min_messages = debug5/' \
/var/lib/postgresql/postgresql.conf
```

Note that PostgreSQL logs are directed to `/tmp/logfile` in fx. `run_usan_gcc.sh`.

INSTALLATION
------------

To install PostGIS library and utilities, as root run::

  make install

Installation paths will typically be derived by ``pg_config``:

 - Lib in ``pg_config --pkglibdir``
 - Binaries (loader/dumper) in ``pg_config --bindir``
 - Important support files in ``pg_config --sharedir``/contrib
 - Manual pages in ``pg_config --mandir``
 - Documentation in ``pg_config --docdir``

You can change them using ``./configure`` switches. See CONFIGURATION section.


CREATING NEW SPATIAL DATABASES
------------------------------

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
------------------------------------

Upgrade PostGIS using the "ALTER EXTENSION" facility.

  ALTER EXTENSION postgis UPDATE TO '2.2.0';


USAGE
-----

Try the following example SQL statements to create tables with
geometry columns::

  CREATE TABLE geom_test ( gid int4, geom geometry, name varchar(25) );
  INSERT INTO geom_test ( gid, geom, name )
    VALUES ( 1, 'POLYGON((0 0 0,0 5 0,5 5 0,5 0 0,0 0 0))', '3D Square');
  INSERT INTO geom_test ( gid, geom, name )
    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 ST_Intersects(geom, ST_MakeEnvelope(2,2,3,3));

The following SQL creates proper full entries in the ``SPATIAL_REF_SYS``
and ``GEOMETRY_COLUMNS`` tables, and ensures that all geometries are created
with an SRID::

  CREATE TABLE geotest (
    id INT4,
    name VARCHAR(32),
    geopoint GEOMETRY(POINT, 4326)
    );

  INSERT INTO geotest (id, name, geopoint)
    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)', 4326));

  SELECT name, AsText(geopoint) FROM geotest;


Spatial Indexes
~~~~~~~~~~~~~~~

PostgreSQL provides support for GiST spatial indexing. The GiST scheme offers
indexing even on large objects, using a system of "lossy" indexing where a
large object is proxied by a smaller one in the index.  In the case of the
PostGIS indexing system, all objects are proxied in the index by their
bounding boxes.

You can build a GiST index with::

  CREATE INDEX <indexname>
    ON <tablename>
    USING GIST ( <geometryfield> );

Always run the ``VACUUM ANALYZE <tablename>`` on your tables after creating an
index. This gathers statistics which the query planner uses to optimize index
usage.


PostGIS Topology support
~~~~~~~~~~~~~~~~~~~~~~~~

See topology/README for more information about topology support.
