Python Gdal 栅格数据处理之将数组存为Tif数据
一、功能
基于gdal库,通过指定数组、投影系、转换参数。将数组存为TIF影像数据。
二、Python代码
import os
from osgeo import gdal
def write_img(filename, im_proj, im_geotrans, im_data, no_data='null'):
"""
filename: 输出文件路径
im_proj:指定投影系
im_geotrans:指定仿射变换矩阵
im_data: 输入一个数组
no_data: 默认参数,把无效值设置为 nodata
"""
dtypes = {
'int8': gdal.GDT_Byte,
'unit16': gdal.GDT_UInt16,
'int16': gdal.GDT_Int16,
'unit32': gdal.GDT_UInt32,
'int32': gdal.GDT_Int32,
'float32': gdal.GDT_Float32,
'float64': gdal.GDT_Float64,
}
if not dtypes.get(im_data.dtype.name, None)