Menu

#112 Resampling tool

v2.0.6
closed
nobody
Modules (45)
5
2012-07-20
2010-12-27
Tim
No

The resample tool overwrites the target grid when executing via the gui. In addition, there does not appear to be a method for passing a target grid using the python syntax. I tried a workaround suggested by vokler (passing an empty grid with the correct grid system as the -GRID), but was unsuccessful. The function executes okay, but the resulting grid contains no values.

I am fairly new to SAGA, so I apologize in advance if this but was reported or fixed already. I checked the bug tracker and didn't see an entry even though vokler suggested a bug be added in this thread (http://sourceforge.net/projects/saga-gis/forums/forum/790705/topic/3824315).

Thanks

Discussion

  • Volker Wichmann

    Volker Wichmann - 2010-12-27

    I don't think this is a bug, see my post in the user forum (https://sourceforge.net/projects/saga-gis/forums/forum/790705/topic/3824315).

    The following snippet of python code uses an existing grid to define the output's grid dimensions (i.e. the output grid system) and resamples the input grid to this. The trick is to get the parameters of parameter ('GRID') and to set their parameter 'GRID' to the output grid. The output grid has to be created from the target grid beforehand.

    I close this bug, but keep it open for posting. Feel free to re-open it in case you still think there is something buggy.

    Volker

    *************

    import saga_api, sys, os

    *************

    def resample_grid(fGridIn, fTarget, fGridOut):
    print saga_api.SAGA_API_Get_Version()

    fmlb    = os.environ['SAGA_MLB'] + '/grid_tools'
    mlb     = saga_api.CSG_Module_Library()
    
    if mlb.Create(saga_api.CSG_String(fmlb)) == 0:
        print '\n\nERROR loading ' + fmlb
        return 0
    
    m       = mlb.Get_Module_Grid('Resampling')
    p       = m.Get_Parameters()
    
    GridIn  = saga_api.SG_Create_Grid()
    if GridIn.Create(saga_api.CSG_String(fGridIn)) == 0:
        print '\n\nERROR loading ' + fGridIn
        return 0
    
    Target  = saga_api.SG_Create_Grid()
    if Target.Create(saga_api.CSG_String(fTarget)) == 0:
        print '\n\nERROR loading ' + fTarget
        return 0
    
    GridOut = saga_api.SG_Create_Grid(Target)
    
    m.Get_System().Assign(GridIn.Get_System())
    p('INPUT')    .Set_Value(GridIn)
    m.Get_Parameters('GRID').Get_Parameter('GRID').Set_Value(GridOut)
    p('TARGET')   .Set_Value(1)
    
    if m.Execute() == 0:
        print '\n\nERROR executing ' + m.Get_Name()
        return 0
    
    GridOut.Save(saga_api.CSG_String(fGridOut))
    
    # finalize
    print '\n\nExecution succeeded'
    return 1
    

    *************

    if name == 'main':

    if len( sys.argv ) != 4:
        print 'Usage: resample_grid.py <in: Input.sgrd> <in: DummyTarget.sgrd> <out: Output.sgrd>'
    else:
        fGridIn   = sys.argv[1]
        if os.path.split(fGridIn)[0] == '':
            fGridIn = './' + fGridIn
    
        fTarget  = sys.argv[2]
        if os.path.split(fTarget)[0] == '':
            fTarget  = './' + fTarget
    
        fGridOut   = sys.argv[3]
        if os.path.split(fGridOut)[0] == '':
            fGridOut = './' + fGridOut
    
        resample_grid(fGridIn, fTarget, fGridOut)
    
     
  • Volker Wichmann

    Volker Wichmann - 2010-12-27

    python script

     
  • Volker Wichmann

    Volker Wichmann - 2010-12-27

    I've attached the script as file to the bug report because the formatting of the code was lost in my previous post.

    Volker

     

Anonymous
Anonymous

Add attachments
Cancel