PostGIS 2.5 with GEOS 3.7 and SFCGAL on Ubuntu18.04

A very technical post on installing the latest PostGIS.

I wanted to reinstall my PostGIS on my system with a full support for all the new functionalities. I mean a PostGIS 2.5+, with the latest versions of GEOS and sfcgal support. Here are my notes.

At the beginning I had this:

  • gdal 2.2.3
  • GEOS 3.6.2
  • libxml2 2.94
  • proj4 4.9.2
  • postgis 2.4.3
  • postgresql 10

But I want postgis 2.5 with sfcgal support and GEOS 3.7+ for using fancy brand new PostGIS functions such as ST_OrientedEnvelope or ST_ApproximateMedialAxis.

The procedure is inspired (but updated) from https://gis.stackexchange.com/questions/167687/how-to-enable-sfcgal-in-postgis

Install the latest GEOS

  • Go to https://trac.osgeo.org/geos/ and download the lastest GEOS
  • Compile it following these instructions: https://trac.osgeo.org/geos/wiki/BuildingOnUnixWithAutotools
./configure
make && sudo make install

Libraries have been installed in /usr/local/lib.

Install SFCGAL

First, install cgal:

apt install libcgal-dev

Go to the sfcgal project page https://github.com/Oslandia/SFCGAL and clone or download the sfcgal sources. Unzip the archive, go into it and run:

cmake . && make  && sudo make install

The following was actually necessary:

sudo chmod 777 /usr/local/lib/libSFCGAL.*
sudo cp /usr/local/lib/libSFCGAL.* /usr/lib/postgresql/9.5/lib
sudo ldconfig -v | grep -i sfcgal

Install postgis 2.5

Go to https://postgis.net/source/ and download the source of the postgis version you want.

Then, prepare the installation using configure and some arguments to be sure the latest sfcgal and GEOS will be used.

./configure --with-raster --with-topology --with-sfcgal=/usr/local/bin/sfcgal-config --with-geosconfig=/usr/local/bin/geos-config
make && sudo make install

At the end, it output the following and I’m happy with that! So I go on…

  PostGIS is now configured for x86_64-pc-linux-gnu

 -------------- Compiler Info -------------
  C compiler:           gcc -g -O2
  SQL preprocessor:     /usr/bin/cpp -traditional-cpp -w -P

 -------------- Additional Info -------------
  Interrupt Tests:   DISABLED use: --with-interrupt-tests to enable

 -------------- Dependencies --------------
  GEOS config:          /usr/local/bin/geos-config
  GEOS version:         3.7.2
  GDAL config:          /usr/bin/gdal-config
  GDAL version:         2.2.3
  SFCGAL config:        /usr/local/bin/sfcgal-config
  SFCGAL version:       1.3.7
  PostgreSQL config:    /usr/bin/pg_config
  PostgreSQL version:   PostgreSQL 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1)
  PROJ4 version:        49
  Libxml2 config:       /usr/bin/xml2-config
  Libxml2 version:      2.9.4
  JSON-C support:       yes
  protobuf-c support:   no
  PCRE support:         yes
  Perl:                 /usr/bin/perl

 --------------- Extensions ---------------
  PostGIS Raster:       enabled
  PostGIS Topology:     enabled
  SFCGAL support:       enabled
  Address Standardizer support:       enabled

 -------- Documentation Generation --------
  xsltproc:             /usr/bin/xsltproc
  xsl style sheets:     /usr/share/xml/docbook/stylesheet/docbook-xsl
  dblatex:              
  convert:              /usr/bin/convert
  mathml2.dtd:          /usr/share/xml/schema/w3c/mathml/dtd/mathml2.dtd

…and compile and install it.

make && sudo make install

Now test the postgis installation:

SELECT PostGIS_full_version();

Uh! What happens? I still have my old PostGIS version!

If like me you were updating your PostGIS and not doing a fresh install, the following command is required before enjoying the latest PostGIS functionalities:

ALTER EXTENSION postgis UPDATE;
SELECT PostGIS_full_version();

Leave a Reply

Your email address will not be published. Required fields are marked *