fix: 矩形竞对格子按整窗填色
This commit is contained in:
@@ -176,6 +176,22 @@ def pixel_center_mask_for_geometry(geometry, window, minx, maxy, pixel_width, pi
|
||||
return np.asarray(shapely.contains_xy(geometry, x_grid, y_grid), dtype=bool)
|
||||
|
||||
|
||||
def rectangle_center_window(bounds, minx, maxy, pixel_width, pixel_height, width, height):
|
||||
"""像元中心严格落在轴对齐矩形内的窗口。整窗都在矩形内,可直接填充。"""
|
||||
geom_minx, geom_miny, geom_maxx, geom_maxy = bounds
|
||||
col_first = math.floor((geom_minx - minx) / pixel_width - 0.5) + 1
|
||||
col_last = math.ceil((geom_maxx - minx) / pixel_width - 0.5) - 1
|
||||
row_first = math.floor((maxy - geom_maxy) / pixel_height - 0.5) + 1
|
||||
row_last = math.ceil((maxy - geom_miny) / pixel_height - 0.5) - 1
|
||||
col_start = max(0, col_first)
|
||||
col_stop = min(width, col_last + 1)
|
||||
row_start = max(0, row_first)
|
||||
row_stop = min(height, row_last + 1)
|
||||
if row_start >= row_stop or col_start >= col_stop:
|
||||
return None
|
||||
return row_start, row_stop, col_start, col_stop
|
||||
|
||||
|
||||
def pixel_center_mask_for_bounds(bounds, window, minx, maxy, pixel_width, pixel_height):
|
||||
"""轴对齐矩形的像元中心判断。边界上的中心点不算在内,和多边形 contains 一致。"""
|
||||
row_start, row_stop, col_start, col_stop = window
|
||||
|
||||
Reference in New Issue
Block a user