def window_from_polygon(self, polygon, mask=False):
"""Build and return a window being the minimum bounding box around the passed polygon.
At least a part of the polygon should fit the image
Parameters
----------
polygon: shapely.geometry.Polygon
The polygon of which the minimum bounding window should be returned
mask: boolean (optional, default: False)
True for applying a mask to the image
Returns
-------
window: ImageWindow
The resulting image window
Raises
------
IndexError: if the polygon box offset is not inside the image
"""
offset, width, height = Image.polygon_box(polygon)
if not self._check_tile_offset(offset):
raise IndexError("Offset {} is out of the image.".format(offset))
return self.window(offset, width, height, polygon_mask=polygon if mask else None)
评论列表
文章目录