pg_sphere
pg_sphere
pgsphere : spherical objects with useful functions, operators and index support
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3590 | pg_sphere | pgsphere | 1.5.2 | TYPE | BSD 3-Clause | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | postgis q3c earthdistance prefix semver unit pgpdf pglite_fusion |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 1.5.2 | 18 17 16 15 14 | pgsphere | - |
| RPM | PIGSTY | 1.5.2 | 18 17 16 15 14 | pgsphere_$v | - |
| DEB | PGDG | 1.5.2 | 18 17 16 15 14 | postgresql-$v-pgsphere | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 |
el8.aarch64 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 |
el9.x86_64 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 |
el9.aarch64 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 |
el10.x86_64 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 |
el10.aarch64 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 | PIGSTY 1.5.2 |
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 | PGDG 1.5.2 | PGDG 1.5.2 | PGDG 1.5.2 | PGDG 1.5.2 | PGDG 1.5.2 |
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 | PGDG 1.5.2 | PGDG 1.5.2 | PGDG 1.5.2 | PGDG 1.5.2 | PGDG 1.5.2 |
u24.aarch64 | PGDG 1.5.2 | PGDG 1.5.2 | PGDG 1.5.2 | PGDG 1.5.2 | PGDG 1.5.2 |
Source
pig build pkg pgsphere; # build rpmInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pgsphere; # install via package name, for the active PG version
pig install pg_sphere; # install by extension name, for the current active PG version
pig install pg_sphere -v 18; # install for PG 18
pig install pg_sphere -v 17; # install for PG 17
pig install pg_sphere -v 16; # install for PG 16
pig install pg_sphere -v 15; # install for PG 15
pig install pg_sphere -v 14; # install for PG 14Create this extension with:
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 updated on