PostGIS Installation and Configuration

PostGIS is an extension of the object-relational database PostgreSQL. PostGIS provides spatial information service functions, including spatial objects, spatial indexes, spatial operation functions, and spatial operators. At the same time, PostGIS complies with OpenGIS specifications.

In Copilot, PostGIS is used for structured data storage.

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

Below, we will provide a detailed guide on how to install and configure PostGIS.

Installing PostGIS on Windows

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

  1. Go to the PostGIS official website and download the .exe installation file corresponding to PostgreSQL 9.6.12 and compatible with a 64-bit operating system, postgis-bundle-pg96x64-setup-2.5.3-1.exe.
  2. Open the installation file and follow the prompts to set the installation components, set the PostGIS installation path, enter the PostgreSQL administrator password, set the name of the initialized spatial database, register the GDAL_DATA environment variable, and enable the raster driver to complete the installation.

After the installation is complete, 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. All subsequent spatial databases you need can be quickly created based on this template.

Installing PostGIS on Linux

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

  1. Check the versions of PostgreSQL and PostGIS supported in the apt-get repository. In this environment, choose to install PostgreSQL 12 and PostGIS 3.0 (the PostGIS version must correspond to the PostgreSQL version).
  • Check the supported PostgreSQL versions:

sudo apt-cache search postgresql

  • Check the supported PostGIS versions:

sudo apt-cache search postgis

  1. Install PostgreSQL and PostGIS in sequence.
  • Install PostgreSQL 12:

sudo apt-get install postgresql-12

  • Install PostGIS 3.0:

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 is automatically created, with a randomly generated password. Therefore, you need to change the passwords for these two users for subsequent use.
  • Change the password for the database user postgres:
  • Log in to PostgreSQL:

sudo -u postgres psql

  • Change the password for the database administrator user:

alter user postgres with password 'YourPassword';

  • Exit the database:

\q

  • Change the password for the system user postgres:
  • Delete the randomly generated password:

sudo passwd -d postgres

  • Reset the password for the user postgres:

sudo -u postgres passwd

  1. Create a database and add PostGIS support.
  • Switch to the postgres user:

sudo su postgres

  • Create a database, for example iPortaldb. You can customize the database name:

createdb [DatabaseName]

  • Execute the following scripts in sequence to provide PostGIS support for the created database (these scripts are located by default in /usr/share/postgresql/12/contrib/postgis-3.0).

psql -d [DatabaseName] -f /usr/share/postgresql/12/contrib/postgis-3.0/postgis.sql

psql -d [DatabaseName] -f /usr/share/postgresql/12/contrib/postgis-3.0/spatial_ref_sys.s

At this point, you have completed the installation of PostgreSQL and PostGIS and can proceed with structured data configuration in iPortal.