def polygon_box(polygon):
"""From a shapely polygon, return the information about the polygon bounding box.
These information are offset (x, y), width and height.
Parameters
----------
polygon: shapely.geometry.Polygon
The polygon of which the bounding box should be computed
Returns
-------
offset: tuple (int, int)
The offset of the polygon bounding box
width: int
The bounding box width
height
The bounding box heigth
"""
minx, miny, maxx, maxy = polygon.bounds
fminx, fminy = int(math.floor(minx)), int(math.floor(miny))
cmaxx, cmaxy = int(math.ceil(maxx)), int(math.ceil(maxy))
offset = (fminx, fminy)
width = cmaxx - fminx
height = cmaxy - fminy
return offset, width, height
评论列表
文章目录