pg_sphere

spherical objects with useful functions, operators and index support

Overview

PackageVersionCategoryLicenseLanguage
pgsphere1.5.2TYPEBSD 3-ClauseC
IDExtensionBinLibLoadCreateTrustRelocSchema
3590pg_sphereNoYesNoYesNoYes-
Relatedpostgis q3c earthdistance prefix semver unit pgpdf pglite_fusion

Version

TypeRepoVersionPG VerPackageDeps
EXTMIXED1.5.21817161514pgsphere-
RPMPIGSTY1.5.21817161514pgsphere_$v-
DEBPGDG1.5.21817161514postgresql-$v-pgsphere-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
d12.aarch64
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
d13.x86_64
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
d13.aarch64
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
u22.x86_64
u22.aarch64
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
u24.x86_64
u24.aarch64
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2
PGDG 1.5.2

Build

You can build the RPM packages for pgsphere using pig build:

pig build pkg pgsphere         # build RPM packages

Install

You can install pgsphere directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pgsphere;          # Install for current active PG version
pig ext install -y pgsphere -v 18  # PG 18
pig ext install -y pgsphere -v 17  # PG 17
pig ext install -y pgsphere -v 16  # PG 16
pig ext install -y pgsphere -v 15  # PG 15
pig ext install -y pgsphere -v 14  # PG 14
dnf install -y pgsphere_18       # PG 18
dnf install -y pgsphere_17       # PG 17
dnf install -y pgsphere_16       # PG 16
dnf install -y pgsphere_15       # PG 15
dnf install -y pgsphere_14       # PG 14
apt install -y postgresql-18-pgsphere   # PG 18
apt install -y postgresql-17-pgsphere   # PG 17
apt install -y postgresql-16-pgsphere   # PG 16
apt install -y postgresql-15-pgsphere   # PG 15
apt install -y postgresql-14-pgsphere   # PG 14

Create Extension:

CREATE EXTENSION pg_sphere;

Usage

pg_sphere: spherical geometry data types and operations for PostgreSQL

The pg_sphere extension provides spherical geometry types and operations, useful for astronomy, geospatial, and other applications involving spherical coordinates.

CREATE EXTENSION pg_sphere;

Data Types

  • Spherical point (spoint): A location on a sphere (longitude, latitude in radians)
  • Spherical circle (scircle): A circular region defined by center and radius
  • Spherical line (sline): A great circle segment
  • Spherical ellipse (sellipse): An elliptical region on a sphere
  • Spherical polygon (spoly): A multi-vertex shape on a sphere
  • Spherical path (spath): A connected sequence of points
  • Spherical box (sbox): A bounding box on a sphere

Core Operations

  • Membership testing (point in polygon, point in circle, etc.)
  • Overlap detection between spherical objects
  • Circumference and area calculations
  • Object rotation using Euler angles for coordinate transformations
  • Distance calculations between spherical objects

Index Support

  • GiST index: R-tree implementation for efficient spatial queries
  • BRIN index: Block range indexing for large datasets

Input/Output

The extension handles input and output in various coordinate formats commonly used in astronomy and geospatial applications, including degrees, radians, and HMS/DMS notation.

-- Create a spherical point (RA, Dec)
SELECT spoint '(10.25d, 45.5d)';

-- Create a spherical circle (center, radius)
SELECT scircle '<(10.25d, 45.5d), 1d>';

-- Check containment
SELECT spoint '(10.25d, 45.5d)' @ scircle '<(10d, 45d), 2d>';

Last Modified 2026-03-12: add pg extension catalog (95749bf)