1

While performing actions in python console as described in the module of GRASS GIS,am getting following error:

import grass.script as gs

r.in.gdal -e input="D:...\ASTGTMV003_N19E073_dem" output=DEM

File "", line 1

r.in.gdal -e input="D:\...\ASTGTMV003_N19E073_dem" output=DEM

   ^

SyntaxError: invalid syntax

Then I gave input from import raster and was able to view my DEM tile in GUI but the next actions gave me other errors.

gs.run_command('g.region', raster='elevation')

Traceback (most recent call last):

File "", line 1, in

File "C:\OSGEO4~1\apps\grass\grass78\etc\python\grass\script\core.py", line 441, in run_command return handle_errors(returncode, returncode, args, kwargs)

File "C:\OSGEO4~1\apps\grass\grass78\etc\python\grass\script\core.py", line 343, in handle_errors returncode=returncode)

grass.exceptions.CalledModuleError: Module run None g.region raster=elevation ended with error

Process ended with non-zero return code 1. See errors in the (error) output.

s.run_command('r.neighbors', input='elevation', output='elev_smoothed', method='average', flags='c')

Traceback (most recent call last):

File "", line 1, in

File "C:\OSGEO4~1\apps\grass\grass78\etc\python\grass\script\core.py", line 441, in run_command return handle_errors(returncode, returncode, args, kwargs)

File "C:\OSGEO4~1\apps\grass\grass78\etc\python\grass\script\core.py", line 343, in handle_errors returncode=returncode)

grass.exceptions.CalledModuleError: Module run None r.neighbors -c input=elevation output=elev_smoothed method=average ended with error

Process ended with non-zero return code 1. See errors in the (error) output.

1 Answer 1

1

Several questions here. I'll try one by one...

r.in.gdal -e input="D:...\ASTGTMV003_N19E073_dem" output=DEM
File "", line 1
r.in.gdal -e input="D:\...\ASTGTMV003_N19E073_dem" output=DEM
   ^

This GRASS command must be run at the command prompt. Not in a python shell.

gs.run_command('g.region', raster='elevation')

Above you imported your Aster DEM as "DEM", but here you refer to "elevation". Is there a mixup of raster names?

s.run_command('r.neighbors', input='elevation', output='elev_smoothed', method='average', flags='c')

Possibly the same mixup in raster names?

In general, I would suggest to first run these commands at the GRASS prompt, to make sure you have the syntax right, Then move over to python.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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