def _global_lonlat2pix(self, lonlat):
x = np.searchsorted(self._coords_x, lonlat[:, 0], side='right') - 1
x = x.astype(int)
ycoords = self._coords_y
y = np.searchsorted(ycoords, lonlat[:, 1], side='right') - 1
y = y.astype(int)
# We want the *closed* interval, which means moving
# points on the end back by 1
on_end_x = lonlat[:, 0] == self._coords_x[-1]
on_end_y = lonlat[:, 1] == self._coords_y[-1]
x[on_end_x] -= 1
y[on_end_y] -= 1
if (not all(np.logical_and(x >= 0, x < self._full_res[0]))) or \
(not all(np.logical_and(y >= 0, y < self._full_res[1]))):
raise ValueError("Queried location is not "
"in the image {}!".format(self.source._filename))
result = np.concatenate((x[:, np.newaxis], y[:, np.newaxis]), axis=1)
return result
# @contract(lonlat='array[Nx2](float64),N>0')
评论列表
文章目录