我正在尝试合并4个栅格文件(数据类型:float32),代码可以工作,但是输出的栅格数据的范围在1.79769e + 308和-1.79769e + 308之间。栅格中的无数据值设置为-3.3999999e + 38
我正在使用以下代码:
# Set tiles directory and find all files ending with .tif
path = "/home/DATA/" # tiles directory
onlyTIFF = [f for f in listdir(path) if isfile(join(path, f)) and f.endswith(".tif")]
onlyTIFF = [os.path.join(outdir, f) for f in listdir(outdir) if isfile(join(outdir, f)) and f.endswith(".tif")]
# List for the source files
src_files_to_mosaic = []
# Iterate over raster files and add them to source -list in 'read mode'
for fp in onlyTIFF:
src = rio.open(fp)
src_files_to_mosaic.append(src)
# Merge function returns a single mosaic array and the transformation info
mosaic, out_trans = merge(src_files_to_mosaic)
# Copy the metadata
out_meta = src.meta.copy()
# Update the metadata
out_meta.update({"driver": "GTiff",
"height": mosaic.shape[1],
"width": mosaic.shape[2],
"transform": out_trans})
"dtype": rio.float32,
"count": 1})
with rio.open("/home/DATA/mosaic.tif","w", **out_meta) as dest:
dest.write(mosaic)