1

I want to reclassify the same raster several times and then save the file with the value loop variable at the end ... I cannot get it working.

    import sys
    import os
    import atexit

    import grass.script as grass

    def cleanup():
        pass

    def main():
        for i in range (2,4):
        out = "reclasstest" + str(i)
        rulesvar = "C:\Grass_data\datareclassfile") + str(i) 
        grass.run_command("r.reclass",
                          overwrite = True,
                          input = "glg@PERMANENT",
                          output = out,
                          rules = rulesvar)

        return 0

    if __name__ == "__main__":
        options, flags = grass.parser()
        atexit.register(cleanup)
        sys.exit(main())

1 Answer 1

2

It looks like an indentation problem, plus had an extra ")" and was missing an "r" on a file path - try ...

import sys
import os
import atexit

import grass.script as grass

def cleanup():
    pass

def main():
    for i in range (2,4):
        out = "reclasstest" + str(i)
        rulesvar = r"C:\Grass_data\datareclassfile" + str(i) 
        grass.run_command("r.reclass",
                          overwrite = True,
                          input = "glg@PERMANENT",
                          output = out,
                          rules = rulesvar)

    return 0

if __name__ == "__main__":
    options, flags = grass.parser()
    atexit.register(cleanup)
    sys.exit(main())

If this does not work be sure to post any error message you receive.

0

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.