def reproject_tiff_from_model(old_name, new_name, model, unit):
"""
Reprojects an tiff on a tiff model. Can be used to warp tiff.
Keyword arguments:
old_name -- the name of the old tiff file
new_name -- the name of the output tiff file
model -- the gdal dataset which will be used to warp the tiff
unit -- the gdal unit in which the operation will be performed
"""
mem_drv = gdal.GetDriverByName("MEM")
old = gdal.Open(old_name)
new = mem_drv.Create(new_name, model.RasterXSize, model.RasterYSize, 1,
unit)
new.SetGeoTransform(model.GetGeoTransform())
new.SetProjection(model.GetProjection())
res = gdal.ReprojectImage(old, new, old.GetProjection(),
model.GetProjection(), gdal.GRA_NearestNeighbour)
assert res == 0, 'Error in ReprojectImage'
arr = new.ReadAsArray()
new = None
return arr
评论列表
文章目录