def nearest_cell(self, x, y, bbox=None, shape=None):
"""
Returns the index of the cell (column, row) closest
to a given geographical coordinate.
Parameters
----------
x : int or float
x coordinate.
y : int or float
y coordinate.
"""
if not bbox:
bbox = self._bbox
if not shape:
shape = self.shape
# Note: this speedup assumes grid cells are square
y_ix, x_ix = self.bbox_indices(self._bbox, self.shape)
y_ix += self.cellsize / 2.0
x_ix += self.cellsize / 2.0
desired_y = np.argmin(np.abs(y_ix - y))
desired_x = np.argmin(np.abs(x_ix - x))
return desired_x, desired_y
评论列表
文章目录