Skip to main content

object-oriented spherical geometry

Project description

STScI Logo STScI Name

sphersgeo

build tests Powered by STScI

object-oriented spherical geometry

[!IMPORTANT] sphersgeo is still in development and does NOT currently implement all of the functionality provided by other geo packages such as geo or Shapely.

[!NOTE] Intersections between geometries are NOT rigorous; the .intersection() function will ONLY return the lower order of geometry being compared, and does NOT handle degenerate cases / touching geometries.

Installation

pip install sphersgeo

Usage

Euclidean geometry packages classify geometries into points, linestrings, and polygons (along with multi-variations: multipoints, multilinestrings, and multipolygons). Spherical geometry analogues are spherical points, arcstrings, and spherical polygons.

Full class definitions can be found in sphersgeo.pyi.

Points on a sphere

Spherical points are represented internally as 3-dimensional Euclidean points (X, Y, Z) relative to the origin of the unit sphere.

import sphersgeo

# define a point on the sphere in angular coordinates (longitude and latitude)
a = sphersgeo.SphericalPoint((60.0, 30.0))
b = sphersgeo.SphericalPoint((60.0, 0.0))
c = sphersgeo.SphericalPoint((-30.0, -30.0))

# ... or in Euclidean coordinates (X, Y, Z)
a = sphersgeo.SphericalPoint((0.43301270189221946, 0.75, 0.5))
b = sphersgeo.SphericalPoint((0.5, 0.8660254037844386, 0.0))
c = sphersgeo.SphericalPoint((0.75, -0.4330127018922193, -0.5))
d = sphersgeo.SphericalPoint((0.0, 0.0, 1.0))
e = sphersgeo.SphericalPoint((0.0, 0.0, -1.0))

# collate multiple points together by passing lists of angular or Euclidean coordinates
ab = sphersgeo.MultiSphericalPoint([(60.0, 30.0), (60.0, 0.0)])
ab = sphersgeo.MultiSphericalPoint(
    [(0.43301270189221946, 0.75, 0.5), (0.5, 0.8660254037844386, 0.0)]
)
de = sphersgeo.MultiSphericalPoint(
    [
        (0.0, 0.0, 1.0),
        (0.0, 0.0, -1.0),
    ]
)

# ... or a Numpy array of coordinates
import numpy as np
ab = sphersgeo.MultiSphericalPoint(np.array([(60.0, 30.0), (60.0, 0.0)]))
ab = sphersgeo.MultiSphericalPoint(
    np.array([(0.43301270189221946, 0.75, 0.5), (0.5, 0.8660254037844386, 0.0)])
)

# ... or a list of SphericalPoint objects
abcde = sphersgeo.MultiSphericalPoint([a, b, c, d, e])

Strings of great circle arcs on a sphere

A great circle arcs is the shortest geodesic distance over the surface of the sphere between any two points. Arcstrings are comprised of an ordered collection of spherical points. Arcstrings can also be closed, in which case the final point is considered as connected back to the first point.

import sphersgeo

# define an arcstring on the sphere by passing angular or Euclidean coordinates
abc = sphersgeo.ArcString([(60.0, 0.0), (60.0, 30.0), (-30.0, -30.0)])
de = sphersgeo.ArcString(
    [
        (0.0, 0.0, 1.0),
        (0.0, 0.0, -1.0),
    ]
)

# ... or a list of SphericalPoint objects
abc = sphersgeo.ArcString(
    [
        sphersgeo.SphericalPoint((60.0, 0.0)),
        sphersgeo.SphericalPoint((60.0, 30.0)),
        sphersgeo.SphericalPoint((-30.0, -30.0)),
    ],
    closed=True,
)
de = sphersgeo.ArcString(
    [
        sphersgeo.SphericalPoint((0.0, 0.0, 1.0)),
        sphersgeo.SphericalPoint((0.0, 0.0, -1.0)),
    ]
)

# collate arcstrings into a MultiArcString by passing the same inputs you would to the individual objects
abc_de = sphersgeo.MultiArcString(
    [
        [(60.0, 0.0), (60.0, 30.0), (-30.0, -30.0)],
        [
            (0.0, 0.0, 1.0),
            (0.0, 0.0, -1.0),
        ],
    ]
)

# ... or a list of ArcString objects
abc_de = sphersgeo.MultiArcString([abc, de])

Polygons on a sphere

Spherical polygons are comprised of

  1. closed arcstring that represents the outer boundary, and
  2. a sample point that defines which side of the closed spherical region is "inside" the boundary.

If the "inside point" is not given, the smaller of the two regions split by the boundary will be assigned to be the "inside".

[!NOTE] Polygons in sphersgeo do NOT have holes.

import sphersgeo

# define a spherical polygon by passing angular or Euclidean coordinates to form the boundary
abc = sphersgeo.SphericalPolygon([(60.0, 0.0), (60.0, 30.0), (-30.0, -30.0)])
abc = sphersgeo.SphericalPolygon(
    [
        (0.43301270189221946, 0.75, 0.5),
        (0.5, 0.8660254037844386, 0.0),
        (0.75, -0.4330127018922193, -0.5),
    ]
)

# ... or pass an ArcString object (the arcstring is assumed to be closed)
abc = sphersgeo.SphericalPolygon(
    sphersgeo.ArcString([(60.0, 0.0), (60.0, 30.0), (-30.0, -30.0)])
)

# collate multiple polygons into a MultiSphericalPolygon by passing the same inputs you would to the individual objects
abc_def = sphersgeo.MultiSphericalPolygon(
    [
        [(60.0, 30.0), (60.0, 0.0), (-30.0, -30.0)],
        [
            (0.0, 0.0, 1.0),
            (0.0, 0.0, -1.0),
            (1.0, 1.0, 0.0),
        ],
    ]
)

# ... or a list of SphericalPolygon objects
abc_def = sphersgeo.MultiSphericalPolygon(
    [
        sphersgeo.SphericalPolygon([(60.0, 30.0), (60.0, 0.0), (-30.0, -30.0)]),
        sphersgeo.SphericalPolygon(
            [
                (0.0, 0.0, 1.0),
                (0.0, 0.0, -1.0),
                (1.0, 1.0, 0.0),
            ]
        ),
    ]
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphersgeo-0.0.1.tar.gz (7.8 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sphersgeo-0.0.1-cp311-abi3-musllinux_1_2_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ x86-64

sphersgeo-0.0.1-cp311-abi3-manylinux_2_28_x86_64.whl (596.9 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

sphersgeo-0.0.1-cp311-abi3-macosx_11_0_arm64.whl (544.0 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file sphersgeo-0.0.1.tar.gz.

File metadata

  • Download URL: sphersgeo-0.0.1.tar.gz
  • Upload date:
  • Size: 7.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sphersgeo-0.0.1.tar.gz
Algorithm Hash digest
SHA256 63e25112e1ad0bdb515768e03bfadbd21240fc7c38d04861e7f7ececc37df913
MD5 0be879ca2ae043804f052a4c414f1729
BLAKE2b-256 2f7a31c79dc10434ce692a97e47df88dc04fd4d9e21146e19def55ab0d3b2a62

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphersgeo-0.0.1.tar.gz:

Publisher: build.yml on spacetelescope/sphersgeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphersgeo-0.0.1-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sphersgeo-0.0.1-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d01d3ac4f7491def19bfcb039d317bb3b321d2739e94d0d5dae4084eddb3a1c8
MD5 4178eb8a6e8309ef1589b5eb5eb3f233
BLAKE2b-256 aa27ea1a7da33948c59656981225f2491ea7554fa362b54267df6c51fb80cb97

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphersgeo-0.0.1-cp311-abi3-musllinux_1_2_x86_64.whl:

Publisher: build.yml on spacetelescope/sphersgeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphersgeo-0.0.1-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sphersgeo-0.0.1-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 860db47fabc11ddac3e2d5d45042fb6debfbc61eac6f84ce3d7a7c156aa4042e
MD5 2330216615354b0e9f976c37b91e3103
BLAKE2b-256 07a21fdd8afdfcdc0de9450dd168767e945801ec1cc519442f1f0dd94d775e1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphersgeo-0.0.1-cp311-abi3-manylinux_2_28_x86_64.whl:

Publisher: build.yml on spacetelescope/sphersgeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphersgeo-0.0.1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sphersgeo-0.0.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7789f2454cf4a2d0d59d457e9c56ad86fda0063711077aed9c586cb0e1348e26
MD5 9c09d3ad99ab2d84cfeb4c3b8ffd10e4
BLAKE2b-256 433d301c054304b12a90af0d2351aaecf8924a5b571fada325ae7db860203b2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphersgeo-0.0.1-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: build.yml on spacetelescope/sphersgeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page