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

42 views Asked by At

I'm working with GRASS GIS and Python to process and export a set of raster tiles. The tiles are generated using r.tile and should contain valid data, as indicated by the metadata within GRASS. However, when I export these tiles to TIFF format using r.out.gdal within a Python script, the resulting files have "No Data" values throughout.

I've written a Python script that runs within the GRASS GIS environment. The relevant part of the script uses r.out.gdal to export the raster files to a specified directory. Here is the the script responsible for the export:

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')


After running the script, I check the resulting TIFF files, and they all seem to have "No Data" values, which is not expected. However, when examining the rasters in GRASS GIS using the metadata commands (r.info or similar), they appear to have valid data.

Metadata example of a tile with data

after exporting the files i open the same file in QGIS or similar application and is empty.

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

Why might r.out.gdal be exporting my raster data as "No Data" when the metadata indicates there is valid information present?

I've been looking for similar problems but so far i was unable to find useful solution since i'm exporting the data with a loop. I have review that setting the region before would be the solution but in this case that I'm looping to save all the tiles and i don't know how to manage it.

thanks in advance.

0

There are 0 answers