Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

anyone,

first day Grass programming with python scripting; first prob;

simple I want to reclass the same raster several times; and save the file with the value loop variable at the end ... can not 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())

greetz, piet

share|improve this question
add comment (requires an account with 50 reputation)

1 Answer

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.

share|improve this answer
Ok it's working thanks a lot !!!!! – piet May 26 at 15:28
Excellent - when you get a chance can you hit the tick symbol to Accept the Answer, please? – PolyGeo May 26 at 19:43
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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