跳转到主要内容

基于s2geometry的Python/NumPy兼容地理索引

项目描述

pys2index

test status

基于s2geometry的Python/NumPy兼容地理索引。

此项目不提供整个s2geometry库的Python包装器。相反,它旨在提供一些API类似于scipy.spatial.cKDTree的索引包装器。

构建依赖项

安装

使用conda

pys2index可以使用conda(或mamba)安装

$ conda install pys2index -c conda-forge

从源代码

首先,克隆此存储库

$ git clone https://github.com/benbovy/pys2index
$ cd pys2index

您可以使用conda(或mamba)安装所有依赖项

$ conda install python cxx-compiler numpy s2geometry pybind11 xtensor-python cmake scikit-build-core -c conda-forge

构建并安装此库

$ python -m pip install . --no-build-isolation

使用方法

In [1]: import numpy as np

In [2]: from pys2index import S2PointIndex

In [3]: latlon_points = np.array([[40.0, 15.0],
   ...:                           [-20.0, 53.0],
   ...:                           [81.0, 153.0]])
   ...:

In [4]: index = S2PointIndex(latlon_points)

In [5]: query_points = np.array([[-10.0, 60.0],
   ...:                          [45.0, -20.0],
   ...:                          [75.0, 122.0]])
   ...:

In [6]: distances, positions = index.query(query_points)

In [7]: distances
Out[7]: array([12.06534671, 26.07312392,  8.60671311])

In [8]: positions
Out[8]: array([1, 0, 2])

In [9]: index.get_cell_ids()
Out[9]: array([1386017682036854979, 2415595305706115691, 6525033740530229539],
              dtype=uint64)

运行测试

运行测试需要pytest(它也位于conda-forge上)。

$ pytest .

项目细节


下载文件

下载适合您平台的应用程序。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源分发

pys2index-0.1.5.tar.gz (14.0 kB 查看散列)

上传于

由以下支持