Installation and configuration of PostGIS

Feedback


PostGIS is an extension of the object-relational database PostgreSQL. PostGIS provides spatial information services including spatial objects, spatial indexes, spatial operation functions, and spatial operators. At the same time, PostGIS follows the OpenGIS specification.

In iPortal, PostGIS is used to store structured data.

For more information about PostGIS, please refer to the official website: http://www.postgis.org.

The following content will introduce how to install and configure PostGIS.

Install PostGIS on Windows

Before installing PostGIS, you need to complete the installation and configuration of the PostgreSQL database, and then go to the PostGIS official website to download the installation package corresponding to your PostgreSQL version, and complete the installation according to the installation wizard. This article takes PostgreSQL with 9.6.12 version and Windows 64-bit operating system as an example to introduce the installation method of PostGIS:

1. Download the installation file in .exe format corresponding to PostgreSQL 9.6.12 and adapting to the 64-bit operating system on the PostGIS official website, postgis-bundle-pg96x64-setup-2.5.3-1.exe.

2. Open the installation package and follow the prompts to set the installation components, set the PostGIS installation path, set the PostgreSQL administrator account, set the initialized spatial database name, register the GDAL_DATA environment variable, and enable the raster drive.

After completing the installation, you can create a spatial database in PostgreSQL.

Note: When setting the installation components, it is recommended that you select "Create spatial database" to initialize a spatial database template, and all subsequent spatial databases can be quickly created based on this template.

Install PostGIS on Linux

PostGIS provides two installation methods based on package manager and source code for Linux operating system. This article takes the Ubuntu 20.04.1 Server operating system as an example to briefly introduce the installation method of PostgreSQL and PostGIS based on the package manager:

  1. Check the PostgreSQL and PostGIS package versions supported in the apt-get library. This article installs PostgreSQL 12 version and PostGIS 3.0 version (PostGIS version needs to correspond to the PostgreSQL version).

sudo apt-cache search postgresql

sudo apt-cache search postgis

  1. Install PostgreSQL and PostGIS in sequence.

sudo apt-get install postgresql-12

sudo apt-get install postgresql-12-postgis-3

  1. Change the password. After PostgreSQL is installed, a database administrator user named postgres and an operating system user named postgres will be created automatically. The passwords are randomly generated, so you need to change the passwords of these two users first.

sudo -u postgres psql

alter user postgres with password 'your password';

\q

sudo passwd -d postgres

sudo -u postgres passwd

  1. Create a database and provide PostGIS support.

sudo su postgres

createdb [database name]

psql -d [数据库名] -f /usr/share/postgresql/12/contrib/postgis-3.0/postgis.sql

psql -d [数据库名] -f /usr/share/postgresql/12/contrib/postgis-3.0/spatial_ref_sys.sql

 

Now, you have completed the installation of PostgreSQL and PostGIS, and then you can configure structured data in iPortal.