grid.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:pysheds 作者: mdbartos 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号