Skip to main content

Fast GPS to local Cartesian coordinate conversion using GeographicLib

Project description

LocalCartesian

Fast GPS to local Cartesian coordinate conversion using GeographicLib.

Description

This package provides efficient conversion between GPS coordinates (latitude, longitude) and local Cartesian coordinates (x, y). It uses the GeographicLib C++ library through Python bindings created with pybind11.

The package exists because GeographicLib's Python bindings don't include the equivalent of the C++ LocalCartesian class, which is essential for many geospatial applications.

Installation

Install from PyPI using uv:

uv add localcartesian

or via pip globally, or inside any Python environment like virtualenv or conda:

pip install localcartesian

Usage

import numpy as np
from localcartesian import gps2xy, xy2gps

# Define some GPS coordinates (lat, lon pairs)
gps_coords = [
    [40.7128, -74.0060],  # New York City
    [40.7589, -73.9851],  # Times Square
    [40.6892, -74.0445],  # Statue of Liberty
]

# Define origin point (lat, lon, altitude)
origin = [40.7128, -74.0060, 0.0]  # NYC as origin

# Convert GPS to local Cartesian coordinates
local_coords = gps2xy(gps_coords, origin)
print("Local coordinates:", local_coords)

# Convert back to GPS coordinates
gps_back = xy2gps(local_coords, origin)
print("GPS coordinates:", gps_back)

API Reference

gps2xy(latlon, origin_latlonalt)

Convert GPS coordinates to local Cartesian coordinates.

Parameters:

  • latlon: List of [latitude, longitude] pairs
  • origin_latlonalt: Origin point as [latitude, longitude, altitude]

Returns:

  • List of [x, y] coordinate pairs in meters

xy2gps(xy, origin_latlonalt)

Convert local Cartesian coordinates to GPS coordinates.

Parameters:

  • xy: List of [x, y] coordinate pairs in meters
  • origin_latlonalt: Origin point as [latitude, longitude, altitude]

Returns:

  • List of [latitude, longitude] pairs

Development

Building from Source Locally

Clone the repository and navigate to the project directory:

git clone <repository-url>
cd localcartesian
uv sync --dev
uv build

Generate multiple wheels locally

For Linux

uvx cibuildwheel --platform linux --only "cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64"

For MacOS

uvx cibuildwheel --platform macos \
  --only "cp39-macosx_x86_64 cp310-macosx_x86_64 cp311-macosx_x86_64 cp312-macosx_x86_64 \
          cp39-macosx_arm64  cp310-macosx_arm64  cp311-macosx_arm64  cp312-macosx_arm64"

Running Tests

uv sync --extra test
uv run pytest

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

localcartesian-0.1.1.tar.gz (50.9 kB view details)

Uploaded Source

File details

Details for the file localcartesian-0.1.1.tar.gz.

File metadata

  • Download URL: localcartesian-0.1.1.tar.gz
  • Upload date:
  • Size: 50.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.14

File hashes

Hashes for localcartesian-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8e472195a93c447e39ff186b88dc8e21404cc1859f21885b8141af3e0497476f
MD5 478d4496066a7dd84e1c492610ea622e
BLAKE2b-256 2b08e5139bec0941e289a9ccaf1c91fb3fd1e4cd93da892e566fc12d867fa100

See more details on using hashes here.

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