How to add PostGIS extension in PostgreSQL?

account_box
Syntactica Sophia
2 years ago

To add PostGIS extension in PostgreSQL, follow these steps:

  • Step 1: Install the PostGIS package
  • Step 2: Create a PostGIS enabled database
  • Step 3: Add the PostGIS extension
  • Step 4: Verify the installation

Here is a detailed explanation of each step:

Step 1: Install the PostGIS package

The first step is to install the PostGIS package on your system. You can use the following command to install it on Ubuntu:

sudo apt-get install postgis

If you are using a different operating system, please refer to the official documentation for the installation instructions.

Step 2: Create a PostGIS enabled database

Once the PostGIS package is installed, you need to create a new database and enable PostGIS in it. You can use the following commands to achieve this:

createdb mygisdatabase
psql -d mygisdatabase -c 'CREATE EXTENSION postgis;'
psql -d mygisdatabase -c 'CREATE EXTENSION postgis_topology;'

Replace 'mygisdatabase' with the name of your database.

Step 3: Add the PostGIS extension

Next, you need to add the PostGIS extension to your PostgreSQL installation. You can use the following command to achieve this:

psql -d mygisdatabase -c 'CREATE EXTENSION postgis;'

This command will add the PostGIS extension to your PostgreSQL installation.

Step 4: Verify the installation

Finally, you can verify the installation by running the following command:

psql -d mygisdatabase -c 'SELECT postgis_version();'

This command will return the version of PostGIS installed in your PostgreSQL database.