def createImageDS(filename, x_min, y_min, x_max, y_max, pixel_size, srs=None):
# Create the destination data source
x_res = int((x_max - x_min) / pixel_size) # resolution
y_res = int((y_max - y_min) / pixel_size) # resolution
ds = gdal.GetDriverByName('GTiff').Create(filename, x_res,
y_res, 1, gdal.GDT_Byte)
ds.SetGeoTransform((
x_min, pixel_size, 0,
y_max, 0, -pixel_size,
))
if srs:
# Make the target raster have the same projection as the source
ds.SetProjection(srs.ExportToWkt())
else:
# Source has no projection (needs GDAL >= 1.7.0 to work)
ds.SetProjection('LOCAL_CS["arbitrary"]')
# Set nodata
band = ds.GetRasterBand(1)
band.SetNoDataValue(0)
return ds
评论列表
文章目录