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

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 https://github.com/PastorD/localcartesian.git
cd localcartesian
uv sync --dev

It will fetch the GeographicLib binaries, build the C++ extension, and install the package in editable mode. You can now import and use localcartesian in your Python environment. See examples/basic_usage.py for example usage.

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 cp313-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.2.tar.gz (51.1 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for localcartesian-0.1.2.tar.gz
Algorithm Hash digest
SHA256 73eea1bedad9d88f68c0336ed622ac44e6df5bc25676766e9780255dd95a18f0
MD5 c54da4ddbcdc3c9137c5d5a97db5904d
BLAKE2b-256 097d6c357478d87a2a77cbeb24edf331e7dbdba3d478252d3d039833b37e19b6

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