def grid_asc2sgrd(fASC): # fmlb = '/usr/local/lib/saga/libio_grid.so' # Linux fmlb = os.environ[ 'SAGA'] + '/bin/saga_vc_Win32/modules/io_grid.dll' # Windows mlb = saga_api.CSG_Module_Library() print 'load module library: ' + fmlb if mlb.Create(saga_api.CSG_String(fmlb)) == 0: print '... failed' return 0 print '... success' m = mlb.Get_Module(1) p = m.Get_Parameters() p('FILE').Set_Value(fASC) print m.Get_Name() + ': ' + p('FILE').asString() if m.Execute() == 0: print '... failed' return 0 print '... success' print 'save as SAGA grid' if p('GRID').asGrid().Save(saga_api.CSG_String(fASC)) == 0: print '... failed' return 0 print '... success' return 1
def __init__(self, filename, iface=None): self.sagalib = saga.CSG_Module_Library(saga.CSG_String(str(filename))) if not self.sagalib.is_Valid(): raise InvalidLibrary(filename) self._modules = None self.iface = iface processing.framework.registerModuleProvider(self)
def shp2xyz(fshp, fxyz): # fmlb = '/usr/local/lib/saga/libio_shapes.so' # Linux fmlb = os.environ[ 'SAGA'] + '/bin/saga_vc_Win32/modules/io_shapes.dll' # Windows mlb = saga_api.CSG_Module_Library() shp = saga_api.SG_Create_Shapes() print 'load module library: ' + fmlb if mlb.Create(saga_api.CSG_String(fmlb)) == 0: print '... failed' return 0 print '... success' m = mlb.Get_Module(2) p = m.Get_Parameters() print 'load shape file: ' + fshp if shp.Create(saga_api.CSG_String(fshp)) == 0: print '... failed' return 0 print '... success' p('SHAPES').Set_Value(shp) p('FILENAME').Set_Value(fxyz) print p('SHAPES').Get_Name() + ' >> ' + p('SHAPES').asString() print p('FILENAME').Get_Name() + ' >> ' + p('FILENAME').asString() print 'execute module: ' + m.Get_Name() if m.Execute() == 0: print '... failed' return 0 print '... success' return 1
def __init__(self, filename): self.sagalib = saga.CSG_Module_Library(saga.CSG_String(str(filename))) if not self.sagalib.is_Valid(): raise ImportError(filename) self.libname = filename.split(os.sep)[-1].split(".")[0] if self.libname.startswith("lib"): self.libname = self.libname[3:] self.name = self.sagalib.Get_Name().c_str() self._modules = None
def xyz2shp(fTable): print saga_api.SAGA_API_Get_Version() # fmlb = '/usr/local/lib/saga/libshapes_points.so' # Linux fmlb = os.environ[ 'SAGA'] + '/bin/saga_vc_Win32/modules/shapes_points.dll' # Windows mlb = saga_api.CSG_Module_Library() print 'load module library: ' + fmlb if mlb.Create(saga_api.CSG_String(fmlb)) == 0: print '... failed' return 0 print '... success' # 1. load table from file or create a test data set table = saga_api.SG_Create_Table() if table.Create(saga_api.CSG_String(fTable)) == 0: table.Add_Field('X', saga_api.TABLE_FIELDTYPE_Float) table.Add_Field('Y', saga_api.TABLE_FIELDTYPE_Float) table.Add_Field('Z', saga_api.TABLE_FIELDTYPE_Float) rec = table.Add_Record() rec.Set_Value(0, 0) rec.Set_Value(1, 0) rec.Set_Value(2, 2) rec = table.Add_Record() rec.Set_Value(0, 0) rec.Set_Value(1, 1) rec.Set_Value(2, 2) rec = table.Add_Record() rec.Set_Value(0, 1) rec.Set_Value(1, 1) rec.Set_Value(2, 1) rec = table.Add_Record() rec.Set_Value(0, 1) rec.Set_Value(1, 0) rec.Set_Value(2, 1) # 2. convert table to points m = mlb.Get_Module(0) p = m.Get_Parameters() p('TABLE').Set_Value(table) p('POINTS').Set_Value(saga_api.SG_Create_Shapes(saga_api.SHAPE_TYPE_Point)) p('X').Set_Value(0) p('Y').Set_Value(1) print 'execute module: ' + m.Get_Name() if m.Execute() == 0: print '... failed' return 0 print '... success' p('POINTS').asShapes().Save(saga_api.CSG_String(fTable)) return 1
def morphometry(fDEM, fSlope, fAspect): # fmlb = '/usr/local/lib/saga/libta_morphometry.so' # Linux fmlb = os.environ['SAGA'] + '/bin/saga_vc_Win32/modules/ta_morphometry.dll' # Windows mlb = saga_api.CSG_Module_Library() print 'load module library: ' + fmlb if mlb.Create(saga_api.CSG_String(fmlb)) == 0: print '... failed' return 0 print '... success' m = mlb.Get_Module_Grid(0) p = m.Get_Parameters() DEM = saga_api.SG_Create_Grid() print 'load grid file: ' + fDEM if DEM.Create(saga_api.CSG_String(fDEM)) == 0: print '... failed' return 0 print '... success' Slope = saga_api.SG_Create_Grid(DEM.Get_System()) Aspect = saga_api.SG_Create_Grid(DEM.Get_System()) m.Get_System().Assign(DEM.Get_System()) # module needs to use conformant grid system! p('ELEVATION').Set_Value(DEM) p('SLOPE') .Set_Value(Slope) p('ASPECT') .Set_Value(Aspect) print 'execute module: ' + m.Get_Name() if m.Execute() == 0: print '... failed' return 0 print '... success' Slope .Set_Name('Slope') Aspect.Set_Name('Aspect') Slope .Save(saga_api.CSG_String(fSlope)) Aspect.Save(saga_api.CSG_String(fAspect)) return 1
def grid_contour(fGrid, fLines): # fmlb = '/usr/local/lib/saga/libshapes_grid.so' # Linux fmlb = os.environ[ 'SAGA'] + '/bin/saga_vc_Win32/modules/shapes_grid.dll' # Windows mlb = saga_api.CSG_Module_Library() print 'load module library: ' + fmlb if mlb.Create(saga_api.CSG_String(fmlb)) == 0: print '... failed' return 0 print '... success' m = mlb.Get_Module_Grid('Contour Lines from Grid') p = m.Get_Parameters() Grid = saga_api.SG_Create_Grid() print 'load grid file: ' + fGrid if Grid.Create(saga_api.CSG_String(fGrid)) == 0: print '... failed' return 0 print '... success' Lines = saga_api.SG_Create_Shapes() m.Get_System().Assign( Grid.Get_System()) # module needs to use conformant grid system! p('INPUT').Set_Value(Grid) p('CONTOUR').Set_Value(Lines) p('ZSTEP').Set_Value(25.0) print 'execute module: ' + m.Get_Name() if m.Execute() == 0: print '... failed' return 0 print '... success' Lines.Save(saga_api.CSG_String(fLines)) return 1
def morphometry(fDEM, fSlope, fAspect, fCurvCls): # fmlb = '/usr/local/lib/saga/libta_morphometry.so' # Linux fmlb = os.environ[ 'SAGA'] + '/bin/saga_vc_Win32/modules/ta_morphometry.dll' # Windows mlb = saga_api.CSG_Module_Library() print 'load module library: ' + fmlb if mlb.Create(saga_api.CSG_String(fmlb)) == 0: print '... failed' return 0 print '... success' m = mlb.Get_Module_Grid(0) p = m.Get_Parameters() DEM = saga_api.SG_Create_Grid() print 'load grid file: ' + fDEM if DEM.Create(saga_api.CSG_String(fDEM)) == 0: print '... failed' return 0 print '... success' Slope = saga_api.SG_Create_Grid(DEM.Get_System()) Aspect = saga_api.SG_Create_Grid(DEM.Get_System()) hCurv = saga_api.SG_Create_Grid(DEM.Get_System()) vCurv = saga_api.SG_Create_Grid(DEM.Get_System()) CurvCls = saga_api.SG_Create_Grid(DEM.Get_System()) m.Get_System().Assign( DEM.Get_System()) # module needs to use conformant grid system! p('ELEVATION').Set_Value(DEM) p('SLOPE').Set_Value(Slope) p('ASPECT').Set_Value(Aspect) p('HCURV').Set_Value(hCurv) p('VCURV').Set_Value(vCurv) print 'execute module: ' + m.Get_Name() if m.Execute() == 0: print '... failed' return 0 print '... success' ###################################### m = mlb.Get_Module_Grid('Curvature Classification') p = m.Get_Parameters() p('CPLAN').Set_Value(hCurv) p('CPROF').Set_Value(vCurv) p('CLASS').Set_Value(CurvCls) print 'execute module: ' + m.Get_Name() if m.Execute() == 0: print '... failed' return 0 print '... success' Slope.Set_Name('Slope') Aspect.Set_Name('Aspect') CurvCls.Set_Name('Cuvature Classification') Slope.Save(saga_api.CSG_String(fSlope)) Aspect.Save(saga_api.CSG_String(fAspect)) CurvCls.Save(saga_api.CSG_String(fCurvCls)) hCurv.Save(saga_api.CSG_String('./hcurv')) vCurv.Save(saga_api.CSG_String('./vcurv')) ###################################### return 1