This post will cover install PostGIS 3.x on CentOS 8.
If you do not already have PostgreSQL 12 installed, do so here
PostGIS 3.x requires additional packages not available in the PostgreSQL repository.
Install the Epel repository for these dependencies:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@demo ~]# yum install epel-release Last metadata expiration check: 0:14:47 ago on Mon 16 Mar 2020 10:21:19 PM UTC. Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Installing: epel-release noarch 8-5.el8 extras 22 k Transaction Summary ================================================================================ Install 1 Package Total download size: 22 k Installed size: 30 k Is this ok [y/N]: y |
With Epel installed, we can now use Yum to install the PostGIS 3.x packages from the PostgreSQL Repository:
1 |
[root@demo ~]# yum -y install postgis30_12-client postgis30_12-devel postgis30_12-docs postgis30_12-utils |
Once completed, su to postgres and connect to the target database where you wish to enable PostGIS.
Below, we are using database ‘demo’:
1 2 3 4 5 6 7 8 9 |
[root@demo ~]# su - postgres Last login: Mon Mar 16 22:19:39 UTC 2020 on pts/0 [postgres@demo ~]$ psql Password for user postgres: psql (12.2) Type "help" for help. postgres=# \c demo You are now connected to database "demo" as user "postgres". |
Install the PostGIS extension using CREATE EXTENSION:
1 2 3 |
demo=# create extension postgis; CREATE EXTENSION demo=# |
Check the PostGIS version installed:
1 2 3 4 5 6 7 8 9 10 11 |
demo=# SELECT PostGIS_full_version(); postgis_ full_version -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----- POSTGIS="3.0.1 ec2a9aa" [EXTENSION] PGSQL="120" GEOS="3.8.0-CAPI-1.13.1 " PROJ= "6.3.1" LIBXML="2.9.7" LIBJSON="0.13.1" LIBPROTOBUF="1.3.0" WAGYU="0.4.3 (Intern al)" (1 row) |
Lets test out our extension using a basic example from https://postgis.net/docs/using_postgis_dbmanagement.html
Create a table with a GEOGRAPHY column:
1 2 3 4 |
CREATE TABLE global_points ( id SERIAL PRIMARY KEY, name VARCHAR(64), location GEOGRAPHY(POINT,4326); |
Insert some data:
1 2 3 |
INSERT INTO global_points (name, location) VALUES ('Town', 'SRID=4326;POINT(-110 30)'); INSERT INTO global_points (name, location) VALUES ('Forest', 'SRID=4326;POINT(-109 29)'); INSERT INTO global_points (name, location) VALUES ('London', 'SRID=4326;POINT(0 49)'); |
Select the name column values:
1 2 3 4 5 6 7 |
demo=# select name from global_points; name -------- Town Forest London (3 rows) |
And run a Spatial Query:
1 2 3 4 5 6 |
demo=# SELECT name FROM global_points WHERE ST_DWithin(location, 'SRID=4326;POINT(-110 29)'::geography, 1000000); name -------- Town Forest (2 rows) |
Learn more at https://postgis.net/