gismath
安装
pip install gismath
示例
import gismath
lon, lat, alt = 121.57156751580956, 31.287623375403385, 0.15180000000691507
# c++ 实现
ecef_cpp = gismath.geodetic2ecef_cpp(lon, lat, alt)
# cython 实现
ecef_cy = gismath.geodetic2ecef_cy(lon, lat, alt)
print(ecef_cpp)
>>> [-2856298.1505069532, 4648013.005657461, 3293186.773949799]
print(ecef_cy)
>>> (-2856298.1505069532, 4648013.005657461, 3293186.773949799)
提供常用 GIS 算法的 CPP 版本和 Cython 版本
| 测试 | CPP 版耗时 | Cython 版耗时 | numba.njit 耗时 | numba.njit(fastmath=True) 耗时 | Pure Python 3.11.3 |
|---|---|---|---|---|---|
| 经纬度转ECEF(50000000 条) | 16.043000 秒 | 08.345999 秒 | 14.576452 秒 | 10.386999 秒 | 40.454000 秒 |
批量接口(推荐用于大数据量)
标量接口逐点调用会被 Python 的函数调用开销拖垮。处理成千上万个点时,
一律使用 *_fast_array 系列——它们内部用 OpenMP prange 多线程 + AVX2/FMA
向量化,一次调用处理整个数组。
输入输出统一为 (N, 3) 的 float64 numpy 数组,且要求 C 连续。
| 函数 | 输入每行 | 输出每行 |
|---|---|---|
geodetic2ecef_fast_array(arr) |
[经度(度), 纬度(度), 高程(米)] |
ECEF [X, Y, Z](米) |
geodetic_to_web_mercator_fast_array(arr) |
[经度(度), 纬度(度), 高程(米)] |
[x, y, z](EPSG:3857 米) |
web_mercator_to_geodetic_fast_array(arr) |
[x, y, z](EPSG:3857 米) |
[经度(度), 纬度(度), 高程(米)] |
web_mercator_to_ecef_fast_array(arr) |
[x, y, z](EPSG:3857 米) |
ECEF [X, Y, Z](米) |
import numpy as np
import gismath
lla = np.array([
[121.57156751580956, 31.287623375403385, 0.1518],
[116.39123456, 39.90600000, 43.5 ],
], dtype=np.float64)
ecef = gismath.geodetic2ecef_fast_array(lla)
# EPSG:3857 -> ECEF:一步到位,内部全程用弧度,
# 省去 rad->deg->rad 的往返与一次中间数组分配
merc = gismath.geodetic_to_web_mercator_fast_array(lla)
ecef2 = gismath.web_mercator_to_ecef_fast_array(merc)
ecef2geodetic_np_cy(pos_array, transform=np.eye(4), return_z=False) 提供 ECEF 转经纬度的
批量版本,可选地先应用一个 4×4 变换矩阵。
角度单位约定
所有对外接口的经纬度一律使用「度」,包括 Web Mercator 系列的输入与输出。 因此下面两种写法等价,可直接串联:
lon, lat, alt = 121.5, 31.2, 0.0
# 直接转
a = gismath.geodetic2ecef_cpp(lon, lat, alt)
# 经 Web Mercator 中转
x, y, z = gismath.geodetic_to_web_mercator_cpp(lon, lat, alt)
b = gismath.geodetic2ecef_cpp(*gismath.web_mercator_to_geodetic_cpp(x, y, z))
0.1.7 之前的版本存在两个缺陷:
webMercatorToGeodetic返回的是弧度而非度, 且geodeticToWebMercator把输入当作弧度处理,导致上面两种写法结果不一致; 同时三个 C++ 接口因std::vector<double> v(3)后又push_back, 实际返回 6 个元素(前 3 个恒为 0)。两者均已修复。
本机构建(VS 2026 + 较旧 CMake)
若本机的 Visual Studio 版本比 CMake 支持的 generator 更新(例如 VS 2026 + CMake 3.25,
CMake 最高只认识 Visual Studio 17 2022),直接 uv build 会失败。
此时用本机专用脚本,它会自动探测 VS、导入 MSVC 环境并强制使用 Ninja generator:
.\scripts\build_local_wheels_homepc.ps1 # Windows,cp311-cp314
.\scripts\build_local_wheels_homepc.ps1 -PythonVersions 3.11 # 只构建 3.11
.\scripts\build_local_wheels_homepc.ps1 -Platform linux # Docker + cibuildwheel
.\scripts\build_local_wheels_homepc.ps1 -Platform all -Clean
测试
pytest test/
test/test_web_mercator.py 覆盖返回值长度、角度单位、批量与标量一致性、
多线程正确性,并在安装了 pyproj 时做交叉验证。
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gismath-0.1.7-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: gismath-0.1.7-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 161.2 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b656c86cf9dcf81169bf620d7ac962175554ecaf95580a1ea5e42fd849df59dc
|
|
| MD5 |
42760a136f77a4020a6e88fe320fa003
|
|
| BLAKE2b-256 |
3777f8093d459bee7b397ffa36beb65b849f0b72fa7fb1b2a7e82d8e3ed1ceec
|
File details
Details for the file gismath-0.1.7-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: gismath-0.1.7-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 300.0 kB
- Tags: CPython 3.14, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddf6f2573a7ba0cdf6f7f6ce70547f024b6a85fbb7695074da18cc82bae173a7
|
|
| MD5 |
1ec63b1e101c3d88dbc8e4c31a6e52b8
|
|
| BLAKE2b-256 |
234cb880a82444b89186886434f4577e122c286847c6196efa7e7b6d7e233050
|
File details
Details for the file gismath-0.1.7-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: gismath-0.1.7-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 157.6 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b43c7ef4ae84a2421854a56331ef39f9db08829fd82c861fa7285ba5e55bb3e
|
|
| MD5 |
f395c9fba8572752db8ad2ad666f68d2
|
|
| BLAKE2b-256 |
6c34a443bfb93b2a019989c8802b53e760cbe1c60d63e428591777826b532ad5
|
File details
Details for the file gismath-0.1.7-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: gismath-0.1.7-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 298.4 kB
- Tags: CPython 3.13, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5cd9713e22ee01ffd9582bc03c95d7d07c0d29c6f6076d506e40db7701e3ce8
|
|
| MD5 |
8c6065fbb348622d1c055684d5a20cf1
|
|
| BLAKE2b-256 |
e69dd1bb0c953ffafe724f275c6b6fc57b739af671d555588ff42d09421621c5
|
File details
Details for the file gismath-0.1.7-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: gismath-0.1.7-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 156.0 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ec3d16cdbc728f3faecaccf57d6623bcf2a06ec0cd032808ad43e879a825897
|
|
| MD5 |
0c60f3fe98f15683e4f425095e2d894f
|
|
| BLAKE2b-256 |
5e2af9a353a7888c421a395987d166f1247fc76d7df873d536d322d2b19dfabd
|
File details
Details for the file gismath-0.1.7-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: gismath-0.1.7-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 299.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fd7d8851e0c6361c9ab24fc9c563f49bbe5553e131be2926b1d79a625500857
|
|
| MD5 |
59ea387d5481aab127028dd0a52d7af0
|
|
| BLAKE2b-256 |
3dfec9b918197e6b88398324e2bfb78561c0012cec9e2dbcc992cbf8e42032de
|
File details
Details for the file gismath-0.1.7-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: gismath-0.1.7-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 160.4 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7751ffa295b567f22eff0024900f715e32523f2f3387159e039015d730345c92
|
|
| MD5 |
eb698c0805cbbbf38bfd6bfd18d2eabe
|
|
| BLAKE2b-256 |
414798cb37fc75ff3d189504cf96ef9a6d82881a3e39fc88331e1822baf91978
|
File details
Details for the file gismath-0.1.7-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: gismath-0.1.7-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 312.2 kB
- Tags: CPython 3.11, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
632d31e4e50fdec62255f18cf935ab1c731e235a57bd1c3fb9e2dbce3397cf5b
|
|
| MD5 |
f753c8e84783fa1a92769d8cc28b7d05
|
|
| BLAKE2b-256 |
297e0ef5053caba88570256a548afcf03e87f54e7f482174a4f749dacd842dd2
|