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
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.
-
An alternative is using pyGRASS. Example:
r.in_gdal(input=L7f,output=L7r,flags="e",overwrite=OVR)
, see grasswiki.osgeo.org/wiki/Python/pygrassmarkusN– markusN2021年02月01日 20:21:12 +00:00Commented Feb 1, 2021 at 20:21 -
Thanks @Micha ,it was really helpful.Omkar Kadlag– Omkar Kadlag2021年02月02日 06:25:54 +00:00Commented Feb 2, 2021 at 6:25