Skip to main content

Python/NumPy compatible geographical index based on s2geometry

Project description

pys2index

test status

Python / NumPy compatible geographical index based on s2geometry.

This project doesn't provide Python wrappers for the whole s2geometry library. Instead, it aims to provide some index wrappers with an API similar to scipy.spatial.cKDTree.

Build Dependencies

Installation

Using conda

pys2index can be installed using conda (or mamba):

$ conda install pys2index -c conda-forge

From source

First, clone this repository:

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

You can install all the dependencies using conda (or mamba):

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

Build and install this library

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

Usage

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)

Running the tests

Running the tests requires pytest (it is also available on conda-forge).

$ pytest .

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

pys2index-0.1.5.tar.gz (14.0 kB view details)

Uploaded Source

File details

Details for the file pys2index-0.1.5.tar.gz.

File metadata

  • Download URL: pys2index-0.1.5.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for pys2index-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a5b18a010afba73a2a85a679cc62450d3bed8e6fc99a3f97d393f351a6bf2d71
MD5 16d6a3083adaec8e5aacce46fb3970b5
BLAKE2b-256 c5041316bc9c5c38f1fe6e7f3e0a14b19333d9087f5b67312b38b64483366352

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page