def array_to_raster_clone(a, proto, xoff=None, yoff=None):
'''
Creates a raster from a given array and a prototype raster dataset, with
optional x- and y-offsets if the array was clipped. Arguments:
a A NumPy array
proto A prototype dataset
xoff The offset in the x-direction; should be provided when clipped
yoff The offset in the y-direction; should be provided when clipped
'''
rast = gdal_array.OpenNumPyArray(a)
kwargs = dict()
if xoff is not None and yoff is not None:
kwargs = dict(xoff=xoff, yoff=yoff)
# Copy the projection info and metadata from a prototype dataset
if type(proto) == str:
proto = gdal.Open(proto)
gdalnumeric.CopyDatasetInfo(proto, rast, **kwargs)
return rast
评论列表
文章目录