Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

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

    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

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    • Best Practice Configuration and Tuning for Linux and Windows VMs

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.