pyinterp.geometry.geographic.RTree#
- class pyinterp.geometry.geographic.RTree(self)#
Bases:
objectSpatial index for geographic longitude/latitude points.
Build an R-tree on geographic coordinates expressed directly in degrees. All distance calculations and interpolations are performed on the spheroid; no conversion to ECEF is applied.
Note
Searching this tree evaluates geodesic distances to its nodes, which is slow.
pyinterp.RTree3D()created with a spheroid accepts longitude/latitude too and searches the points in ECEF:RTree3D(Spheroid(), distance="geodesic")returns the same neighbors and geodesic distances as this class, 5 to 10 times faster, for points without altitude;RTree3D(Spheroid())measures straight-line (chord) distances, 10 to 20 times faster than this class. The chord is shorter than the geodesic by about 0.1% at 1,000 km and 2.6% at 5,000 km; at short range, both find the same neighbors, except for near-ties.
Examples
>>> import numpy as np >>> from pyinterp.core.geometry.geographic import RTree
>>> coords = np.array([ ... [2.0, 48.0], ... [3.0, 49.0] ... ]) >>> values = np.array([10.5, 20.3]) >>> tree = RTree() >>> tree.packing(coords, values)
>>> from pyinterp.core.config.rtree import Query >>> query = np.array([[2.5, 48.5]]) >>> distances, neighbors = tree.query(query, Query().with_k(2))
Create an empty geographic RTree.
Public Methods
bounds(self)Return the bounding box containing all stored points, or None if the tree is empty.
clear(self)Remove all points from the tree.
empty(self)Check if the tree is empty.
insert(self, coordinates[, shape, writable, ...])Insert points into the tree.
inverse_distance_weighting(self, coordinates)Inverse distance weighting interpolation on geographic coordinates.
kriging(self, coordinates[, shape, writable])Kriging interpolation on geographic coordinates.
packing(self, coordinates[, shape, ...])Bulk-load points using the STR packing algorithm.
query(self, coordinates[, shape, writable])Query k-nearest neighbors for multiple points.
radial_basis_function(self, coordinates[, ...])Radial basis function interpolation on geographic coordinates.
size(self)Return the number of points in the tree.
window_function(self, coordinates[, shape, ...])Window function interpolation on geographic coordinates.
Special Methods
__getstate__(self)Get the state for pickling.
__new__(*args, **kwargs)__setstate__(self, state)Set the state for unpickling.