Install PostGIS 2.5.5 on CentOS7

Introduction

I decided to use PostJIS because I was dealing with a little detailed map information. I was working while looking at various installation methods, but there were some things that got stuck, so I will write it as a memorandum.

What is PostGIS

You will be able to save latitude, longitude, area, etc. using a dedicated data type (geometry type, etc.) that will be available once installed. You can use this to calculate location information and work with map objects using GIS objects.

See here for details: https://lets.postgresql.jp/documents/tutorial/PostGIS/1

environment

CentOS 7.6

What you need to use PostGIS

PostGIS has a lot to do with it. I will install the following.

Advance preparation

Install PostgreSQL 11

First, prepare the DB to be actually used.

###Install repository
$ sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

###Install PostgreSQL
$ sudo yum install postgresql11
$ sudo yum install postgresql11-server

###Check if it was done
$ id postgres
uid=26(postgres) gid=26(postgres) groups=26(postgres) 
$  ls /usr/pgsql-11
bin  lib  share

###Password setting, you will be asked twice, so enter the same password
$ sudo su - postgres -c '/usr/pgsql-11/bin/initdb -E UTF8 --locale=C -A scram-sha-256 -W'

###Switch account to postgres
sudo su - postgres

### pgsql_Open profile and write below
vi ~/.pgsql_profile
PATH=/usr/pgsql-11/bin:$PATH
MANPATH=/usr/pgsql-11/share/man:$MANPATH
PGDATA=/var/lib/pgsql/11/data
export PATH MANPATH PGDATA

### bash_Reload profile and exit postgres
$ . ~/.bash_profile
$ exit

### postgresql-Start 11 and complete if you can start it safely
$ sudo systemctl start postgresql-11.service

Install various other packages

In addition, install the necessary packages to facilitate the work to be performed later. Depending on your environment, you may already have one installed, but in that case, skip the command.

###enable wget
$ sudo yum install wget
###Prevent postgres11 from getting angry with LLVM-related package dependencies
$ sudo yum install epel-release centos-release-scl
###Enable gcc compilation
$ sudo yum install gcc-c++
###Development header files and libraries
### epel-release and centos-release-If you do not install scl, you may not be able to install due to dependencies, so install it
$ sudo yum install postgresql11-devel
###Library that handles XML
$ sudo yum install libxml2-devel
###Enable python3
sudo yum install python36

PostGIS installation

We will install PostGIS when the preparations are complete. The flow is to install PostGIS after installing the module for using PostGIS.

Install GEOS 3.7.2.

$ cd /tmp/
$ wget http://download.osgeo.org/geos/geos-3.7.2.tar.bz2
$ tar xf geos-3.7.2.tar.bz2
$ cd geos-3.7.2/
$ ./configure
$ make
$ sudo make install
$ cd ../
$ rm -rf geos-3.7.2

Install Proj4 4.8

$ sudo yum install proj-devel.x86_64

Install GDAL 2.4.0

$ sudo yum install libstdc++.so.6
$ cd /tmp/
$ wget https://download.osgeo.org/gdal/2.4.0/gdal-2.4.0.tar.gz
$ tar xzf gdal-2.4.0.tar.gz
$ cd gdal-2.4.0
$ ./configure
$ make
$ sudo make install
$ cd ../
$ rm -rf gdal-2.4.0

Install PostGIS 2.5.5

$ sudo yum install llvm-toolset-7
$ /tmp/
$ wget https://download.osgeo.org/postgis/source/postgis-2.5.5.tar.gz
$ tar xvzf postgis-2.5.5.tar.gz
$ cd postgis-2.5.5
$ ./configure --with-pgconfig='/usr/pgsql-11/bin/pg_config' 
$ make
$ sudo make install
$ cd ../
$ rm -rf postgis-2.5.5

If you do not have "--with-pgconfig ='/ usr / pgsql-11 / bin / pg_config'" in the ./configure option when installing PostGIS, the following error may occur.

configure: error: could not find pg_config within the current path. You may need to re-run configure with a --with-pgconfig parameter.

I can't find pg_config, so I'm told to specify it, so set the options and it's OK.

Make a symbolic link

$ ls -l /usr/pgsql-11/lib/libgdal.so.20

Probably, "/usr/pgsql-11/lib/libgdal.so.20" cannot be found. Therefore, I will create a symbolic link below.

$ sudo ln -s /usr/local/lib/libgdal.so.20.5.0 /usr/pgsql-11/lib/libgdal.so.20

Without this, the following error will occur when creating EXTENSION from psql.

test_postgis=# CREATE EXTENSION postgis;
ERROR:  could not load library "/usr/pgsql-11/lib/postgis-2.5.so": libgeos_c.so.1: cannot open shared object file: No such file or directory

Cache shared libraries

Finally cache the shared library again. At that time, write "/ usr / local / lib" in the last line of "/etc/ld.so.conf". If you don't do this, you may get another error when creating EXTENSION.

$ sudo vi /etc/ld.so.conf
/usr/local/lib ← Add only this line
$ sudo ldconfig

This completes the installation work.

DB creation

Create a DB to check if it was installed properly. For the time being, restart postgresql-11 before working.

$ sudo systemctl restart postgresql-11.service
###Start psql
$ psql -U postgres
###Create a test DB for confirmation
postgres=# CREATE DATABASE test_postgis;
CREATE DATABASE
postgres=# \c test_postgis
###Create EXTENSION
test_postgis=# CREATE EXTENSION postgis;
CREATE EXTENSION
test_postgis=# \dx
                                     List of installed extensions
  Name   | Version |   Schema   |                             Description
---------+---------+------------+---------------------------------------------------------------------
 plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis | 2.5.5   | public     | PostGIS geometry, geography, and raster spatial types and functions
(2 rows)

If the return value of \ dx looks like the above, it is successful.

Insert test data

Certainly it seems that the installation is done, but it may be ... so I will input the data and check it.

###Create table
test_postgis=# CREATE TABLE station_position
(
  id serial PRIMARY KEY,
  station_name varchar(20),
  position geometry
);
CREATE TABLE
###Insert data
test_postgis=# INSERT INTO station_position (id, station_name, position) VALUES 
(1, 'Ikebukuro Station', ST_GeomFromText('POINT(139.710911 35.729660)', 4326)),
(2, 'Shibuya station', ST_GeomFromText('POINT(139.701647 35.658252)', 4326)),
(3, 'Tokyo Station', ST_GeomFromText('POINT(139.767114 35.681437)', 4326));
###Data confirmation
test_postgis=# SELECT * FROM station_position;
  1 |Ikebukuro Station| 0101000020E6100000BCEB6CC8BF7661408599B67F65DD4140
  2 |Shibuya station| 0101000020E6100000C5CA68E4737661406743FE9941D44140
  3 |Tokyo Station| 0101000020E6100000B8C9A8328C78614066A4DE5339D74140

After inputting, let's check the data using pgAdmin. If pgAdmin is not included, the following article will be helpful. Reference URL: pgAdmin installation procedure If you try to check the contents of the table created by pgAdmin, you will see the following screen. screencapture-127-0-0-1-55572-browser-2020-10-27-22_19_45.png I think there is an eye-like icon surrounded by a red frame. If you click on it, the map will be displayed from "Geometry Viewer", and if you press the "+" button to enlarge it, you can see the blue dots at Tokyo Station. That is the location set in the DB. screencapture-127-0-0-1-55572-browser-2020-10-27-22_26_08.png Finally, let's calculate the distance. Use a function that calculates how far Tokyo Station and Ikebukuro Station are by a straight line distance.

test_postgis=# SELECT ST_Distance( (SELECT position FROM station_position WHERE station_name = 'Tokyo Station')::GEOGRAPHY , (SELECT position FROM station_position WHERE station_name = 'Ikebukuro Station')::GEOGRAPHY, TRUE);
 7382.264423442

The unit is meters, so it's about 7.38km. When I check the distance on google map, it is 7.36km, so it is almost there. screencapture-google-co-jp-maps-place-35-7141559-139-7185288-14z-data-4m5-3m4-1s0x60188d5d4043e0dd-0x213775d25d2b034d-8m2-3d35-7295028-4d139-7109001-2020-10-27-21_36_37.png

Finally

When I installed it myself, I couldn't find much material and got an error and stumbled, so I hope it helps someone.

URL that I used as a reference

Installing PostgreSQL on CentOS https://medium.com/@basstazz3/install-postgis-2-5-to-centos-7-48bd5b261f1a

Recommended Posts

Install PostGIS 2.5.5 on CentOS7
Install Neo4j 4.1.3 on centOS
Install Vertica 10.0 on CentOS 6.10
Install PostgreSQL 12 on Centos8
Install nginx on centOS7
Install Python 3 on CentOS 7
Install kuromoji on CentOS7
Install Mattermost on CentOS 7
Install jpndistrict on CentOS 7
Install Redmine 4.1.1 on CentOS 7
Smokeping Install on CentOS7
Install PostgreSQL 13 on CentOS 7.5
Install OpenFOAM v2006 on CentOS
Install Jenkins on Docker's CentOS
Install Apache on CentOS on VirtualBox
Install Ruby 2.7 on CentOS 7 (SCL)
Try DPDK20 SDK on CentOS7 ①Install
Install Ruby 2.5 on CentOS 7 using SCL
Install Java Open JDK 8 on CentOS 7
How to install MariaDB 10.4 on CentOS 8
Install apache 2.4.46 from source on CentOS7
Steps to install MySQL 8 on CentOS 8
Steps to install devtoolset-6 on CentOS 7
Install Java 9 on windows 10 and CentOS 7
Install MariaDB (CentOS 8)
[CentOS] Install apache-loggen
OpenVPN on CentOS 8
Install samba4 from source code on CentOS8
Install the webmail client Rainloop on CentOS 8
How to install beta php8.0 on CentOS8
Install CentOS 7 on Raspberry pi 4 Model B
Install NextCloud on CentOS 7 with Alibaba Cloud ECS
Install gradle on mac
Command to install nginx / PHP7 / php-fpm on CentOS7
Install Corretto 8 on Windows
Maven on CentOS 7 tutorial
Install Java on Mac
Docker installation on CentOS 6
Use perltidy on CentOS 8
Install pyqt5 on ubuntu
Try OpenLiteSpeed on CentOS8
Tomcat v8 on CentOS7
[CentOS7] Install aws cli
Install Docker on Manjaro
Zabbix 5 installation on CentOS 8
Install Ruby on Ubuntu 20.04
Use mod_auth_cas on CentOS 8
Install lombok on SpringToolSuite4
Install GitLab on CentOS 8 with no internet connection
Jetty v8 on CentOS7
Install Autoware on Ubuntu 18.04.5
OpenJDK installation on CentOS 7
Install openjdk11 on mac
Install Homebrew on Ubuntu 20.04
Install CMS Made Simple v2.2.2 on LAMP on CentOS 7.3
Install OpenJDK 8 on mac
Install MySQL 5.6 on CentOS6 [How to specify the version]
Install ag (the silver searcher) [on CentOS / Ubuntu / Mac]
Try RabbitMQ + PHP on CentOS
Install Docker on Raspberry Pi
Network install CentOS 8 with Kickstart.