pg_sphere
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pgsphere | 1.5.2 | TYPE | BSD 3-Clause | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 3590 | pg_sphere | No | Yes | No | Yes | No | Yes | - |
| Related | postgis q3c earthdistance prefix semver unit pgpdf pglite_fusion |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | MIXED | 1.5.2 | 1817161514 | pgsphere | - |
| RPM | PIGSTY | 1.5.2 | 1817161514 | pgsphere_$v | - |
| DEB | PGDG | 1.5.2 | 1817161514 | postgresql-$v-pgsphere | - |
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>';
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.