def rasterizeShapes(pshapes, geodict, all_touched=True):
"""
Rastering a shape
Args:
pshapes: Sequence of orthographically projected shapes.
goedict: Mapio geodictionary.
all_touched: Turn pixel "on" if shape touches pixel, otherwise turn it
on if the center of the pixel is contained within the shape. Note
that the footprint of the shape is inflated and the amount of
inflation depends on the pixel size if all_touched=True.
Returns:
Rasterio grid.
"""
outshape = (geodict.ny, geodict.nx)
txmin = geodict.xmin - geodict.dx / 2.0
tymax = geodict.ymax + geodict.dy / 2.0
transform = Affine.from_gdal(
txmin, geodict.dx, 0.0, tymax, 0.0, -geodict.dy)
img = rasterio.features.rasterize(
pshapes, out_shape=outshape, fill=0.0, transform=transform,
all_touched=all_touched, default_value=1.0)
return img
评论列表
文章目录