我正在尝试使用 saga_api 库执行 python 脚本,不幸的是我在第一步中停止了:(。当我托盘在 python 上执行此命令时:aga_api.CSG_Module_Library()
我收到此错误消息:
def init(self, args, *kwargs):
raise AttributeError("No constructor defined")
AttributeError: No constructor defined
它在 Windows 上也有同样的效果!
你能不能帮我越过这一步?!
System : Ubuntu 13.10 x64
python version : 2.7.5+
saga_api library version : 2.1.1
SAGA program version : 2.1.1
swig version : 2.0.10
这是代码:
!/usr/bin/env 蟒蛇
导入 saga_api、sys、os
def Import_raster(in__grid):
print saga_api.SAGA_API_Get_Version()
fmlb = '/usr/lib/saga/libio_gdal.so'
Library = saga_api.CSG_Module_Library() # here is the bug !!!
if Library.Create(saga_api.CSG_String(fmlb)) == 0:
print 'unable to load SAGA module library'
return 0
print '... success'
Module = Library.Get_Module('GDAL: Import Raster')
Parms = Module.Get_Parameters()
Parms('FILES').Set_Value(in__grid)
Parms('SELECT').Set_Value(1)
Parms('TRANSFORM').Set_Value(0)
Parms('INTERPOL').Set_Value(0)
Parms = Module.Get_Parameters(0) # additional parameter list
print Module.Get_Name() + ': ' + Parms('FILE').asString()
if Module.Execute() == 0:
print 'module execution failed'
return 0
print 'module successfully executed'
print 'save as SAGA grid'
if Parms('GRID').asGrid().Save(saga_api.CSG_String(in__grid)) == 0:
print '... failed'
return 0
print '... success'
return 1
如果名称== '主要':
if len( sys.argv ) != 4:
print 'Usage: this_script.py <in: gridfile> <out: gridfile> <in: shapefile> <out: shapefile>'
in__grid = '/home/.../CC432_landsat8.tif'
in__grid = os.path.abspath(in__grid)
else:
in__grid = sys.argv[1]
if os.path.split(in__grid)[0] == '':
in__grid = './' + in__grid
Import_raster(in__grid)
打印“完成!”
这是初始化: .... class CSG_Module_Library(_object): swig_setmethods = {} setattr = lambda self, name, value: _swig_setattr(self, CSG_Module_Library, name, value) swig_getmethods = {} getattr = lambda self, name: _swig_getattr (self, CSG_Module_Library, name) def init (self, *args, **kwargs): raise AttributeError("No constructor defined") repr= _swig_repr def is_Valid(self): return _saga_api.CSG_Module_Library_is_Valid(self) def Get_File_Name(self): return _saga_api.CSG_Module_Library_Get_File_Name(self) def Get_Library_Name(self): return _saga_api.CSG_Module_Library_Get_Library_Name(self) def Get_Info(self, *arg): return _saga_api.CSG_Module_Library_Get_Info(self, *args) def Get_Name(self): return _saga_api.CSG_Module_Library_Get_Name(self) def Get_Description(self): return _saga_api.CSG_Module_Library_Get_Description(self) def Get_Author(self): return _saga_api.CSG_Module_Library_ Get_Version(self): return _saga_api.CSG_Module_Library_Get_Version(self) def Get_Summary(self, *args): return _saga_api.CSG_Module_Library_Get_Summary(self, *args) def Get_Count(self): return _saga_api。CSG_Module_Library_Get_Count(self) def Get_Menu(self, *args): return _saga_api.CSG_Module_Library_Get_Menu(self, *args) def Get_Module(self, *args): return _saga_api.CSG_Module_Library_Get_Module(self, *args) def Get_Module_Grid(self, *args) : return _saga_api.CSG_Module_Library_Get_Module_Grid(self, *args) def Get_Module_Interactive(self, *args): return _saga_api.CSG_Module_Library_Get_Module_Interactive(self, *args) def Get_Module_Grid_Interactive(self, *args): return _saga_api.CSG_Module_Library_Get_Module_Grid_Interactive(self, *args) CSG_Module_Library_swigregister = _saga_api.CSG_Module_Library_swigregister CSG_Module_Library_swigregister(CSG_Module_Library) ....*args) def Get_Module_Grid(self, *args): return _saga_api.CSG_Module_Library_Get_Module_Grid(self, *args) def Get_Module_Interactive(self, *args): return _saga_api.CSG_Module_Library_Get_Module_Interactive(self, *args) def Get_Module_Grid_Interactive(self, *args): return _saga_api.CSG_Module_Library_Get_Module_Grid_Interactive(self, *args) CSG_Module_Library_swigregister = _saga_api.CSG_Module_Library_swigregister CSG_Module_Library_swigregister(CSG_Module_Library) ....*args) def Get_Module_Grid(self, *args): return _saga_api.CSG_Module_Library_Get_Module_Grid(self, *args) def Get_Module_Interactive(self, *args): return _saga_api.CSG_Module_Library_Get_Module_Interactive(self, *args) def Get_Module_Grid_Interactive(self, *args): return _saga_api.CSG_Module_Library_Get_Module_Grid_Interactive(self, *args) CSG_Module_Library_swigregister = _saga_api.CSG_Module_Library_swigregister CSG_Module_Library_swigregister(CSG_Module_Library) ....*args) CSG_Module_Library_swigregister = _saga_api.CSG_Module_Library_swigregister CSG_Module_Library_swigregister(CSG_Module_Library) ....*args) CSG_Module_Library_swigregister = _saga_api.CSG_Module_Library_swigregister CSG_Module_Library_swigregister(CSG_Module_Library) ....