3

I am a few days new to Linux Ubuntu and am in the process of setting up a PostGIS database to use in GeoDjango.

I am going to post all my commands that I have done so far

these are installed in order:

-------------------------------postgres------------------------
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install postgresql postgresql-contrib libpq-dev pgadmin4

sudo apt-get install postgis

-------------------------------geodjango------------------------

sudo apt-get install binutils libproj-dev gdal-bin
sudo apt-get install build-essential
sudo apt-get install gcc g++ clang make

--geos
wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
tar xjf geos-3.4.2.tar.bz2
cd geos-3.4.2
export CXX="g++ -std=c++98"
./configure
make
sudo make install
cd ..

--proj 4
wget http://download.osgeo.org/proj/proj-4.9.1.tar.gz
wget http://download.osgeo.org/proj/proj-datumgrid-1.5.tar.gz
tar xzf proj-4.9.1.tar.gz
cd proj-4.9.1/nad
tar xzf ../../proj-datumgrid-1.5.tar.gz
cd ..
./configure
make
sudo make install
cd ..

--gdal
wget http://download.osgeo.org/gdal/2.2.0/gdal-2.2.0.tar.gz
tar xzf gdal-2.2.0.tar.gz
cd gdal-2.2.0
./configure
make
sudo make install

now when I go into pgAdmin 4 and run create extension postgis i get this error

ERROR:  could not load library "/usr/lib/postgresql/10/lib/postgis-2.4.so": /usr/lib/liblwgeom-2.4.so.0: undefined symbol: GEOSVoronoiDiagram
SQL state: XX000

UPDATE

followed the directions in this link https://kitcharoenp.github.io/postgresql/postgis/2018/05/28/set_up_postgreSQL_postgis.html and still got the same error

2

The error message points to GEOS,

ERROR: could not load library "/usr/lib/postgresql/10/lib/postgis-2.4.so": /usr/lib/liblwgeom-2.4.so.0: undefined symbol: GEOSVoronoiDiagram

You might have better luck with installing a more recent version of GEOS (see e.g. Error building GEOS on Ubuntu 18.04):

Replace 3.4.2 with 3.6.2 in:

--geos
wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
tar xjf geos-3.4.2.tar.bz2
cd geos-3.4.2
export CXX="g++ -std=c++98"
./configure
make
sudo make install
cd ..

-- Update --

With new versions of GEOS, you also don't need the CXX flag, which forces (a quite) old C++ standard. When possible, I'd try to compile the libraries with the same compiler and settings with PostgreSQL.

  • okay, does it matter which one I install first? – ziggy Jul 20 '18 at 15:15
  • @ziggy I updated the answer, just realizing that you are not compiling PostGIS. But if you are, you can specify which geos version to use: gis.stackexchange.com/questions/253202 – tinlyx Jul 20 '18 at 15:32
  • okay I uninstalled 3.4.2 and reinstalled 3.6.2 and it worked, thank you – ziggy Jul 20 '18 at 15:35
3

If you are in Ubuntu, you can install it from packages!

Instead of compiling them from source, you can just execute this command and all the required packages will be installed.

sudo apt-get install binutils libproj-dev gdal-bin

Here is a complete example on how to set up a database with PostGIS on Ubuntu 18, PostgreSQL 10

$ sudo apt-get update
$ sudo apt-get install -y binutils postgresql postgresql-contrib
# Password for the database
$ sudo su - postgres
$ psql
> CREATE USER myprojectuser WITH PASSWORD 'password';
> CREATE DATABASE myproject OWNER myprojectuser;
> ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
> ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
> ALTER ROLE myprojectuser SET timezone TO 'UTC';
> GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
# Test conection, quit with \q or ctrl+d
$ psql -h localhost -U myprojectuser myproject

# Install 
$ sudo apt-get install binutils libproj-dev gdal-bin 
# Check package version, searching with command
# sudo apt-cache search postgresql | grep gis
$ sudo apt-get install -y postgis postgresql-10-postgis-2.4 python-psycopg2
$ sudo -u postgres psql -c "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;" myproject 

Reference: Installing Geospatial libraries: GDAL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.