1

Trying to run r.random using the script but receiving an error message. It works when the module is run outside of the python shell so it must be te code, I'm new to this so I can't figure out what is wrong.

input:

grass.run_command("r.random", overwrite=True, input="island",npoints=15, raster="randomsample", vector="randomsample")

error:

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

1
  • The error is the same if I make them different, plus the module works with the same names if run outside of the python shell. – grassgis1234 May 14 '20 at 12:02
0

Did you import the respective GRASS GIS Python scripting API?

Using the "North Carolina sample dataset", it works like this:

>>> import grass.script as grass
>>> grass.run_command("r.random", overwrite=True, input="basin_50K",npoints=15, raster="randomsample", vector="randomsample")
Collecting Stats...
 100%
WARNING: Vector map <randomsample> already exists and will be overwritten
Writing raster map <randomsample> and vector map <randomsample> ...
 100%
Building topology for vector map <randomsample@user1>...
Registering primitives...
0
>>> 

You can find examples here (and of course in the GRASS GIS source code as well):

https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library#Calling_a_GRASS_module_in_Python

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.