Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
astraw committed Sep 10, 2024
0 parents commit 9c7097e
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 0 deletions.
169 changes: 169 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# This file is autogenerated by maturin v1.7.1
# To update, run
#
# maturin generate-ci github
#
name: CI

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, musllinux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
73 changes: 73 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/target

# Byte-compiled / optimized / DLL files
__pycache__/
.pytest_cache/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
.venv/
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
include/
man/
venv/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
pip-selfcheck.json

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

.DS_Store

# Sphinx documentation
docs/_build/

# PyCharm
.idea/

# VSCode
.vscode/

# Pyenv
.python-version
Cargo.lock
17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "pyned2lla"
version = "0.1.0"
edition = "2021"
authors = ["Andrew Straw <[email protected]>"]
description = "NED (North East Down) to LLA (Latitude Longitude Altitude) conversion for Python"
license = "MIT"
readme = "README.md"
repository = "https://github.com/strawlab/pyned2lla"

[lib]
name = "pyned2lla"
crate-type = ["cdylib"]

[dependencies]
coord_transforms = "1.4.0"
pyo3 = "0.22.0"
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# pyned2lla - NED (North East Down) to LLA (Latitude Longitude Altitude) conversion for Python

## Example use

```python
import pyned2lla
import math

D2R = math.pi/180.0
R2D = 180.0/math.pi

wgs84 = pyned2lla.wgs84()

(lat0, lon0, alt0) = 47.992875, 7.853876, 281 # Schwabentor, Freiburg
(north, east, down) = 1650, 170, 20

(lat, lon, alt) = pyned2lla.ned2lla(lat0*D2R, lon0*D2R, alt0, north, east, down, wgs84)
print((lat*R2D, lon*R2D, alt)) # Institute of Biology I, Faculty of Biology, University of Freiburg
```

The above should print approximately `(48.00771378931424, 7.8561542926911985, 261.21592491399497)`.

## License

MIT license
13 changes: 13 additions & 0 deletions examples/example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pyned2lla
import math

D2R = math.pi/180.0
R2D = 180.0/math.pi

wgs84 = pyned2lla.wgs84()

(lat0, lon0, alt0) = 47.992875, 7.853876, 281 # Schwabentor, Freiburg
(north, east, down) = 1650, 170, 20

(lat, lon, alt) = pyned2lla.ned2lla(lat0*D2R, lon0*D2R, alt0, north, east, down, wgs84)
print((lat*R2D, lon*R2D, alt)) # Institute of Biology I, Faculty of Biology, University of Freiburg
25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[project]
name = "pyned2lla"
requires-python = ">=3.8"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]
description = "NED (North East Down) to LLA (Latitude Longitude Altitude) conversion for Python"
readme = "README.md"
authors = [{ name = "Andrew Straw", email = "[email protected]" }]

[project.urls]
Homepage = "https://github.com/strawlab/pyned2lla"

[build-system]
requires = ["maturin>=1.7,<2.0"]
build-backend = "maturin"

[tool.maturin]
features = ["pyo3/extension-module"]
40 changes: 40 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use coord_transforms::prelude::Vector3;
use pyo3::prelude::*;

#[pyclass]
struct GeoEllipsoid {
inner: coord_transforms::structs::geo_ellipsoid::geo_ellipsoid,
}

#[pyfunction]
fn wgs84() -> PyResult<GeoEllipsoid> {
let inner = coord_transforms::structs::geo_ellipsoid::geo_ellipsoid::new(
coord_transforms::structs::geo_ellipsoid::WGS84_SEMI_MAJOR_AXIS_METERS,
coord_transforms::structs::geo_ellipsoid::WGS84_FLATTENING,
);
Ok(GeoEllipsoid { inner })
}

#[pyfunction]
fn ned2lla(
lat0: f64,
lon0: f64,
alt0: f64,
north_m: f64,
east_m: f64,
down_m: f64,
geo_ellipsoid: &GeoEllipsoid,
) -> PyResult<(f64, f64, f64)> {
let lla0 = Vector3::new(lat0, lon0, alt0);
let ned = Vector3::new(north_m, east_m, down_m);
let lla = coord_transforms::geo::ned2lla(&lla0, &ned, &geo_ellipsoid.inner);
Ok((lla[0], lla[1], lla[2]))
}

/// A Python module implemented in Rust.
#[pymodule]
fn pyned2lla(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(ned2lla, m)?)?;
m.add_function(wrap_pyfunction!(wgs84, m)?)?;
Ok(())
}

0 comments on commit 9c7097e

Please sign in to comment.