def get_geometry_cells(self, geometry, bounds=None):
if bounds is None:
bounds = self._get_geometry_bounds(geometry)
minx, miny, maxx, maxy = bounds
height, width = self.data.shape
minx = max(minx, self.x)
miny = max(miny, self.y)
maxx = min(maxx, self.x + width)
maxy = min(maxy, self.y + height)
from shapely import prepared
from shapely.geometry import box
cells = np.zeros_like(self.data, dtype=np.bool)
prep = prepared.prep(geometry)
res = self.resolution
for iy, y in enumerate(range(miny * res, maxy * res, res), start=miny - self.y):
for ix, x in enumerate(range(minx * res, maxx * res, res), start=minx - self.x):
if prep.intersects(box(x, y, x + res, y + res)):
cells[iy, ix] = True
return cells
评论列表
文章目录