Skip to main content

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

gismath-0.1.7-cp314-cp314-win_amd64.whl (161.2 kB view details)

Uploaded CPython 3.14Windows x86-64

gismath-0.1.7-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (300.0 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

gismath-0.1.7-cp313-cp313-win_amd64.whl (157.6 kB view details)

Uploaded CPython 3.13Windows x86-64

gismath-0.1.7-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (298.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

gismath-0.1.7-cp312-cp312-win_amd64.whl (156.0 kB view details)

Uploaded CPython 3.12Windows x86-64

gismath-0.1.7-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (299.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

gismath-0.1.7-cp311-cp311-win_amd64.whl (160.4 kB view details)

Uploaded CPython 3.11Windows x86-64

gismath-0.1.7-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (312.2 kB view details)

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

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

Hashes for gismath-0.1.7-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 b656c86cf9dcf81169bf620d7ac962175554ecaf95580a1ea5e42fd849df59dc
MD5 42760a136f77a4020a6e88fe320fa003
BLAKE2b-256 3777f8093d459bee7b397ffa36beb65b849f0b72fa7fb1b2a7e82d8e3ed1ceec

See more details on using hashes here.

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

File hashes

Hashes for gismath-0.1.7-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ddf6f2573a7ba0cdf6f7f6ce70547f024b6a85fbb7695074da18cc82bae173a7
MD5 1ec63b1e101c3d88dbc8e4c31a6e52b8
BLAKE2b-256 234cb880a82444b89186886434f4577e122c286847c6196efa7e7b6d7e233050

See more details on using hashes here.

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

Hashes for gismath-0.1.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4b43c7ef4ae84a2421854a56331ef39f9db08829fd82c861fa7285ba5e55bb3e
MD5 f395c9fba8572752db8ad2ad666f68d2
BLAKE2b-256 6c34a443bfb93b2a019989c8802b53e760cbe1c60d63e428591777826b532ad5

See more details on using hashes here.

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

File hashes

Hashes for gismath-0.1.7-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f5cd9713e22ee01ffd9582bc03c95d7d07c0d29c6f6076d506e40db7701e3ce8
MD5 8c6065fbb348622d1c055684d5a20cf1
BLAKE2b-256 e69dd1bb0c953ffafe724f275c6b6fc57b739af671d555588ff42d09421621c5

See more details on using hashes here.

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

Hashes for gismath-0.1.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8ec3d16cdbc728f3faecaccf57d6623bcf2a06ec0cd032808ad43e879a825897
MD5 0c60f3fe98f15683e4f425095e2d894f
BLAKE2b-256 5e2af9a353a7888c421a395987d166f1247fc76d7df873d536d322d2b19dfabd

See more details on using hashes here.

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

File hashes

Hashes for gismath-0.1.7-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6fd7d8851e0c6361c9ab24fc9c563f49bbe5553e131be2926b1d79a625500857
MD5 59ea387d5481aab127028dd0a52d7af0
BLAKE2b-256 3dfec9b918197e6b88398324e2bfb78561c0012cec9e2dbcc992cbf8e42032de

See more details on using hashes here.

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

Hashes for gismath-0.1.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7751ffa295b567f22eff0024900f715e32523f2f3387159e039015d730345c92
MD5 eb698c0805cbbbf38bfd6bfd18d2eabe
BLAKE2b-256 414798cb37fc75ff3d189504cf96ef9a6d82881a3e39fc88331e1822baf91978

See more details on using hashes here.

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

File hashes

Hashes for gismath-0.1.7-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 632d31e4e50fdec62255f18cf935ab1c731e235a57bd1c3fb9e2dbce3397cf5b
MD5 f753c8e84783fa1a92769d8cc28b7d05
BLAKE2b-256 297e0ef5053caba88570256a548afcf03e87f54e7f482174a4f749dacd842dd2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.7 This release

8 files

0.1.6

8 files

0.1.5

8 files

0.1.4

8 files

0.1.3

8 files

0.1.2

8 files

0.1.1

8 files

0.1.0

8 files

0.0.32

4 files

0.0.30

2 files

0.0.29

4 files

0.0.28

1 file

0.0.27

1 file

0.0.26

1 file

0.0.25

1 file

0.0.24

1 file

0.0.23

1 file

0.0.22

1 file

0.0.21

5 files

0.0.20

1 file

0.0.1

5 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page