def convert2Prob(gdict, inventory, mustContainCenter=False):
"""Convert inventory shapefile to binary grid (with geodict of gdict) with 1 if any part of landslide was in a cell, 0 if not
:param gdict: geodict, likely taken from model to compare inventory against
:param inventory: full file path to shapefile of inventory, must be in geographic coordinates, WGS84
:type inventory: string
:returns rast: Grid2D object containing rasterized version of inventory where cell is 1. if any part of a landslide was in the cell
"""
with fiona.open(inventory) as f:
invshp = list(f.items())
shapes = [shape(inv[1]['geometry']) for inv in invshp]
# Rasterize with allTouch
rast = Grid2D.rasterizeFromGeometry(shapes, gdict, fillValue=0., burnValue=1.0, mustContainCenter=mustContainCenter)
return rast
评论列表
文章目录