Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

PostGIS: A powerful geospatial extension for PostgreSQL

Learn how to work with maps, coordinates, and spatial queries using PostGIS in your PostgreSQL database

October 2, 2025
Lukas Javorsky Ales Nezbeda
Related topics:
C, C#, C++DatabasesLinux
Related products:
Red Hat Enterprise Linux

Share:

    PostGIS is a spatial extension for PostgreSQL that adds support for geographic and location-based data. It allows users to store, query, and analyze spatial data such as points, lines, and polygons directly in a PostgreSQL database. PostGIS enables powerful spatial operations such as calculating distances, measuring areas, performing spatial joins, and more. This makes it ideal for applications in mapping, Geographic Information Systems (GIS), and geospatial analytics. 

    Installation

    Despite PostGIS having its own command-line tools and the possibility to use certain features outside the server, the main functionality is in extending the features available in PostgreSQL databases. For this reason, this article will imply that the setup we want to achieve is extending the PostgreSQL server with PostGIS.

    Note

    The PostgreSQL and PostGIS versions must be compatible with each other.

    As of publishing, the only supported version of PostgreSQL is 16 on both Red Hat Enterprise Linux (RHEL) 9 and RHEL 10. Subsequent versions of PostgreSQL added to RHEL 9 and RHEL 10 will also come with supported PostGIS.

    Install PostgreSQL server on RHEL 10

    To install PostgreSQL server on RHEL 10, run the following:

    # dnf install postgresql-server

    This will install the default version of postgresql-server package.

    Next, to install PostGIS, run:

    # dnf install postgis

    This will install PostGIS compatible with the default version of PostgreSQL. 

    To choose a specific version (for example, 16), you can install specific PostgreSQL server by running:

    # dnf install postgresql16-server

    You can also install compatible PostGIS by running:

    # dnf install postgresql16-postgis

    Remember, the major version of PostgreSQL in the name of the package has to match.

    Install PostgreSQL server on RHEL 9

    In the RHEL 9 use case, modules will be used, and PostGIS will be present in the module that contains the PostgreSQL version of your choice.

    Since the support for PostGIS starts with PostgreSQL version 16, it is necessary to first enable module containing PostgreSQL 16 by running the following:

    # dnf module enable postgresql:16

    Now, install PostgreSQL server:

    # dnf install postgresql-server

    Also install PostGIS:

    # dnf install postgis

    If you would like to use a different version of PostgreSQL, you will need to enable a different version of the module and install both aforementioned packages from that module.

    Keep in mind that PostgreSQL 16 is the first version that has PostGIS available.

    To use PostGIS extension with PostgreSQL server, it must be installed on the same system as the PostgreSQL server. The client that will be connecting to the server doesn’t need the PostGIS package installed.

    After running the aforementioned commands, you should be able to continue with the practical examples in the next section.

    Practical examples

    The following queries require a working PostgreSQL server with PostGIS installed. For setup instructions, refer to the installation section above.

    Add PostGIS extension to the PostgreSQL server

    To add the PostGIS extension, simply make use of the CREATE EXTENSION query:

    CREATE EXTENSION postgis;

    You can verify if the extension was added successfully with the following:

    SELECT postgis_full_version();

     Use the Geometry type of PostGIS extension

    The PostGIS Geometry type supports various geometric shapes, including points, lines, polygons, polygons with holes, and collections.

    To create a table using these types, use the following syntax:

    CREATE TABLE geometries (name varchar, geom geometry);

    To insert individual types, use the following INSERT query:

    INSERT INTO geometries VALUES
      ('Point', 'POINT(0 0)'),
      ('Linestring', 'LINESTRING(0 0, 1 1, 2 1, 2 2)'),
      ('Polygon', 'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'),
      ('PolygonWithHole', 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1))'),
      ('Collection', 'GEOMETRYCOLLECTION(POINT(2 0),POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)))');

    Project data using PostGIS extension

    There are multiple ways to project data using PostGIS extension, which are mentioned in the upstream documentation.

    For example, you can convert coordinates of an existing table for Broad St. subway station into geographics using this syntax:

    SELECT ST_AsText(ST_Transform(geom,4326))
    FROM nyc_subway_stations
    WHERE name = 'Broad St'; 

    Use the PostGIS Raster extension

    PostGIS comes with a Raster extension that can be used for storing and analyzing raster data.

    In order to use the Raster extension, it needs to be created:

    CREATE EXTENSION postgis_raster;

    Red Hat Enterprise Linux does not ship all Geospatial Data Abstraction Library (GDAL) drivers with PostGIS by default, as some might include outdated or unsupported code. Additionally, we strive to keep the PostGIS extension as lean as possible to maintain a minimal footprint and ensure stability.

    To check which drivers are available, use:

    SELECT short_name AS driver_name, long_name AS description, can_read, can_write FROM ST_GDALDrivers() ORDER BY driver_name;

    To view metadata of a newly created raster, use this command:

    SELECT ST_Metadata(ST_AddBand(ST_MakeEmptyRaster(5, 5, 0, 0, 1, -1, 0, 0, 4326), 1, '8BUI', 10, NULL));

    To view the actual pixel values of some other newly created raster, use this command:

    SELECT * FROM ST_DumpValues(ST_AddBand(ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 4326), 1, '8BUI', 7, NULL));

    Notable related tools

    Other related tools worth mentioning include:

    • GDAL: Translator for both vector and raster geospatial data formats. Even though the main use is as a library, this tool includes multiple command-line tools. Apart from simple conversions between data formats, it is also able to manipulate and modify the geospatial data.
    • PROJ: Library for performing cartographic projections and coordinate transformations. This package also includes multiple command-line tools, but is mainly used as a library for other applications, including GDAL.
    • GEOS: Command-line tool and a C++ library, that is used for vector geometry math. Unlike the other mentioned tools, it doesn’t handle coordinate systems or projections. It only works with geometry and math behind it, although there is a focus on algorithms used in GIS software. This library is also used by GDAL. You can use the command-line tool geosop to interact with the library without having to program and create the C++ application yourself. 

    Notes

    All mentioned packages, including PostGIS, can miss certain less-used features in RHEL to ensure a low storage footprint and the safety of provided packages. Some features might require old, unmaintained, or otherwise unsafe software, so they are not included to ensure the highest standards.

    Sources

    • PostGIS

    • GDAL

    • Introduction to PostGIS: Projecting Data

    • Introduction to PostGIS: Geometries

    • Raster reference

    • Introduction to PostGIS: Rasters

    Related Posts

    • Connect to an external PostgreSQL database using SSL/TLS for Red Hat's single sign-on technology

    • Simplify secure connections to PostgreSQL databases with Node.js

    • How to package Go applications in RHEL 10

    • Discover packaging parallel database streams in RHEL 10

    • Using a MySQL database in your Red Hat OpenShift application

    • How to use RHEL as a WSL Podman machine

    Recent Posts

    • Autoscaling vLLM with OpenShift AI

    • Filtering packets from anywhere in the networking stack

    • PostGIS: A powerful geospatial extension for PostgreSQL

    • Kafka Monthly Digest: September 2025

    • A more secure way to handle secrets in OpenShift

    What’s up next?

    Download the Advanced Linux Commands cheat sheet. You'll learn to manage applications and executables in a Linux operating system, define search criteria and query audit logs, set and monitor network access, and more.

    Get the cheat sheet
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue