I want to export a GeoTIFF with PyGRASS but i can't figure out how I can do that. my code so far:

# import grass python libraries
from grass.pygrass.modules.shortcuts import general as g
from grass.pygrass.modules.shortcuts import raster as r
from grass.pygrass.modules.shortcuts import vector as v
from grass_session import Session

inputfile = './data/gtifs/13.tif'

with Session(gisdb="./tmp", location="location", create_opts="EPSG:4326"):
    r.external(input=inputfile, output="layer_1", overwrite = True)

    r.mapcalc(expression='if(layer_1>0, 1, null())',overwrite=True)

    print(g.list(type='raster', flags="m").get_dict())
    # neither of the approaches below work
    r.external.out(directory='./', format="GTiff")
    r.out.gdal(input='layer_1', output='./test.tif')

r.out.gdal() produces an FileNotFoundError: [Errno 2] No such file or directory: 'r.out': 'r.out' and an GrassError: Error running: 'r.out --interface-description'. error

r.external.out() does not seem to exist as a method

how do I save my grass raster as an GeoTIFF? I'm using the Grass GIS 7.8 binaries and python 3.6.9


Since you are using the "Modules" approach of PyGRASS, be sure to change the second dot in 3-word-commands to an underscore:





See "Example 3, using "shortcuts" and external raster format support" in https://grasswiki.osgeo.org/wiki/GRASS_and_Python#pygrass_Library

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.