r.out.gdal 循环正在导入空数据 (pygrass)

r.out.gdal loop is importing empty data (pygrass)

提问人:EmmaGIS 提问时间:11/9/2023 最后编辑:EmmaGIS 更新时间:11/9/2023 访问量:29

问:

我正在使用 GRASS GIS 和 Python 来处理和导出一组栅格切片。切片是使用 r.tile 生成的,并且应包含有效数据,如 GRASS 中的元数据所示。但是,当我在 Python 脚本中使用 r.out.gdal 将这些图块导出为 TIFF 格式时,生成的文件始终具有“无数据”值。

我编写了一个在 GRASS GIS 环境中运行的 Python 脚本。脚本的相关部分使用 r.out.gdal 将光栅文件导出到指定目录。下面是负责导出的脚本:

import os

import grass.script as gscript



#set region to match the raster
gscript.run_command('r.region', map='test_clump', raster='test_clump@PERMANENT')

# Tile the raster
gscript.run_command('r.tile', input='test_clump@PERMANENT', output='tile_test', width=5000, height=5000)


# Define the path to the output directory

output_dir = r"path\to my export folder"


# Get a list of all tiles that start with 'tile_test*'
tiles = gscript.read_command('g.list', type='raster', pattern='tile_test*', mapset='PERMANENT').strip().splitlines()



# Export each tile to a GeoTIFF file
for tile in tiles:

    # Define the output file path
    output_file = os.path.join(output_dir, f"{tile}.tif")
    #print(f"Exporting {tile} to {output_file}")
    
    gscript.run_command('r.out.gdal', flags='ct', input=tile, output=output_file, format='GTiff', type='Int32')


运行脚本后,我检查生成的 TIFF 文件,它们似乎都具有“无数据”值,这是意料之中的。但是,当使用元数据命令(r.info 或类似命令)检查 GRASS GIS 中的栅格时,它们似乎具有有效数据。

包含数据的磁贴的元数据示例

导出文件后,我在QGIS或类似应用程序中打开相同的文件,并且是空的。

Extent  0.0000000000000000,0.0000000000000000 : 1.0000000000000000,1.0000000000000000
Width   1
Height  1
Data type   Int32 - Thirty two bit signed integer
GDAL Driver Description GTiff
GDAL Driver Metadata    GeoTIFF

当元数据指示存在有效信息时,为什么 r.out.gdal 会将我的栅格数据导出为“无数据”?

我一直在寻找类似的问题,但到目前为止,我无法找到有用的解决方案,因为我正在循环导出数据。我已经回顾过之前设置区域将是解决方案,但在这种情况下,我正在循环保存所有瓷砖,我不知道如何管理它。

提前致谢。

Python GIS

评论


答: 暂无答案