def initialize_grid(self, geom):
"""
"""
bounds = geom.bounds
(minx, miny, maxx, maxy) = bounds
(minx, miny, maxx, maxy) = (
round(np.floor(minx * self.psi)) / self.psi,
round(np.floor(miny * self.psi)) / self.psi,
round(np.ceil(maxx * self.psi)) / self.psi,
round(np.ceil(maxy * self.psi)) / self.psi)
clean_bounds = (minx, miny, maxx, maxy)
top_left_lon = minx
top_left_lat = maxy
affine = Affine(self.pixel_size, 0, top_left_lon,
0, -self.pixel_size, top_left_lat)
# base_rasterize, base_bounds = self.rasterize_geom(geom)
# self.shape = base_rasterize.shape
nrows = int(np.ceil( (maxy - miny) / self.pixel_size ))
ncols = int(np.ceil( (maxx - minx) / self.pixel_size ))
self.shape = (nrows, ncols)
self.bounds = clean_bounds
self.affine = affine
self.topleft = (top_left_lon, top_left_lat)
self.grid_box = prep(box(*self.bounds))
# https://stackoverflow.com/questions/8090229/
# resize-with-averaging-or-rebin-a-numpy-2d-array/8090605#8090605
评论列表
文章目录