本文整理汇总了Python中sextante.core.Sextante.Sextante.getAlgorithm方法的典型用法代码示例。如果您正苦于以下问题:Python Sextante.getAlgorithm方法的具体用法?Python Sextante.getAlgorithm怎么用?Python Sextante.getAlgorithm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sextante.core.Sextante.Sextante
的用法示例。
在下文中一共展示了Sextante.getAlgorithm方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addRecentAlgorithms
# 需要导入模块: from sextante.core.Sextante import Sextante [as 别名]
# 或者: from sextante.core.Sextante.Sextante import getAlgorithm [as 别名]
def addRecentAlgorithms(self, updating):
showRecent = SextanteConfig.getSetting(SextanteConfig.SHOW_RECENT_ALGORITHMS)
if showRecent:
recent = SextanteLog.getRecentAlgorithms()
if len(recent) != 0:
found = False
if updating:
recentItem = self.algorithmTree.topLevelItem(0)
treeWidget = recentItem.treeWidget()
treeWidget.takeTopLevelItem(treeWidget.indexOfTopLevelItem(recentItem))
#self.algorithmTree.removeItemWidget(first, 0)
recentItem = QTreeWidgetItem()
recentItem.setText(0, self.tr("Recently used algorithms"))
for algname in recent:
alg = Sextante.getAlgorithm(algname)
if alg is not None:
algItem = TreeAlgorithmItem(alg)
recentItem.addChild(algItem)
found = True
if found:
self.algorithmTree.insertTopLevelItem(0, recentItem)
recentItem.setExpanded(True)
self.algorithmTree.setWordWrap(True)
示例2: fillTree
# 需要导入模块: from sextante.core.Sextante import Sextante [as 别名]
# 或者: from sextante.core.Sextante.Sextante import getAlgorithm [as 别名]
def fillTree(self):
useCategories = SextanteConfig.getSetting(SextanteConfig.USE_CATEGORIES)
if useCategories:
self.fillTreeUsingCategories()
else:
self.fillTreeUsingProviders()
self.algorithmTree.sortItems(0, Qt.AscendingOrder)
showRecent = SextanteConfig.getSetting(SextanteConfig.SHOW_RECENT_ALGORITHMS)
if showRecent:
recent = SextanteLog.getRecentAlgorithms()
if len(recent) != 0:
found = False
recentItem = QTreeWidgetItem()
recentItem.setText(0, self.tr("Recently used algorithms"))
for algname in recent:
alg = Sextante.getAlgorithm(algname)
if alg is not None:
algItem = TreeAlgorithmItem(alg)
recentItem.addChild(algItem)
found = True
if found:
self.algorithmTree.insertTopLevelItem(0, recentItem)
recentItem.setExpanded(True)
self.algorithmTree.setWordWrap(True)
示例3: executeAlgorithm
# 需要导入模块: from sextante.core.Sextante import Sextante [as 别名]
# 或者: from sextante.core.Sextante.Sextante import getAlgorithm [as 别名]
def executeAlgorithm(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
alg = Sextante.getAlgorithm(item.alg.commandLineName())
message = alg.checkBeforeOpeningParametersDialog()
if message:
dlg = MissingDependencyDialog(message)
dlg.exec_()
#QMessageBox.warning(self, self.tr("Warning"), message)
return
alg = alg.getCopy()
dlg = alg.getCustomParametersDialog()
if not dlg:
dlg = ParametersDialog(alg)
canvas = QGisLayers.iface.mapCanvas()
prevMapTool = canvas.mapTool()
dlg.show()
dlg.exec_()
if canvas.mapTool()!=prevMapTool:
try:
canvas.mapTool().reset()
except:
pass
canvas.setMapTool(prevMapTool)
if dlg.executed:
showRecent = SextanteConfig.getSetting(SextanteConfig.SHOW_RECENT_ALGORITHMS)
if showRecent:
self.addRecentAlgorithms(True)
if isinstance(item, TreeActionItem):
action = item.action
action.setData(self)
action.execute()
示例4: alghelp
# 需要导入模块: from sextante.core.Sextante import Sextante [as 别名]
# 或者: from sextante.core.Sextante.Sextante import getAlgorithm [as 别名]
def alghelp(name):
alg = Sextante.getAlgorithm(name)
if alg != None:
print(str(alg))
algoptions(name)
else:
print "Algorithm not found"
示例5: createTest
# 需要导入模块: from sextante.core.Sextante import Sextante [as 别名]
# 或者: from sextante.core.Sextante.Sextante import getAlgorithm [as 别名]
def createTest(text):
s = ""
tokens = text[len("sextante.runalg("):-1].split(",")
cmdname = tokens[0][1:-1];
methodname = "test_" + cmdname.replace(":","")
s += "def " + methodname + "(self):\n"
alg = Sextante.getAlgorithm(cmdname)
execcommand = "sextante.runalg("
i = 0
for token in tokens:
if i < alg.getVisibleParametersCount() + 1:
if os.path.exists(token[1:-1]):
token = os.path.basename(token[1:-1])[:-4]
execcommand += token + "(),"
else:
execcommand += "None,"
i+=1
s += "\toutputs=" + execcommand[:-1] + ")\n"
i = -1 * len(alg.outputs)
for out in alg.outputs:
filename = tokens[i][1:-1]
if (filename == str(None)):
raise Exception("Cannot create unit test for that algorithm execution.\nThe output cannot be a temporary file")
s+="\toutput=outputs['" + out.name + "']\n"
if isinstance(out, (OutputNumber, OutputString)):
s+="self.assertTrue(" + str(out) + ", output)\n"
if isinstance(out, OutputRaster):
dataset = gdal.Open(filename, GA_ReadOnly)
array = dataset.ReadAsArray(1)
s+="\tself.assertTrue(os.path.isfile(output))\n"
s+="\tself.assertEqual(hashraster(output)," + str(hash(array)) + ")\n"
if isinstance(out, OutputVector):
layer = Sextante.getObject(filename)
fields = layer.pendingFields()
s+="\tlayer=QGisLayers.getObjectFromUri(output, True)\n"
s+="\tfields=layer.pendingFields()\n"
s+="\texpectednames=[" + ",".join(["'" + str(f.name()) + "'" for f in fields]) + "]\n"
s+="\texpectedtypes=[" + ",".join(["'" + str(f.typeName()) +"'" for f in fields]) + "]\n"
s+="\tnames=[str(f.name()) for f in fields]\n"
s+="\ttypes=[str(f.typeName()) for f in fields]\n"
s+="\tself.assertEqual(expectednames, names)\n"
s+="\tself.assertEqual(expectedtypes, types)\n"
features = QGisLayers.features(layer)
numfeat = len(features)
s+="\tfeatures=sextante.getfeatures(layer)\n"
s+="\tself.assertEqual(" + str(numfeat) + ", len(features))\n"
if numfeat > 0:
feature = features.next()
attrs = feature.attributes()
s+="\tfeature=features.next()\n"
s+="\tattrs=feature.attributes()\n"
s+="\texpectedvalues=[" + ",".join(['"' + str(attr.toString()) + '"' for attr in attrs]) + "]\n"
s+="\tvalues=[str(attr.toString()) for attr in attrs]\n"
s+="\tself.assertEqual(expectedvalues, values)\n"
dlg = ShowTestDialog(s)
dlg.exec_()
示例6: createTest
# 需要导入模块: from sextante.core.Sextante import Sextante [as 别名]
# 或者: from sextante.core.Sextante.Sextante import getAlgorithm [as 别名]
def createTest(item):
s = ""
tokens = item.entry.text[len("sextante.runalg("):-1].split(",")
cmdname = tokens[0][1:-1];
methodname = "test_" + cmdname.replace(":","")
s += "def " + methodname + "():\n"
alg = Sextante.getAlgorithm(cmdname)
execcommand = "sextante.runalg("
i = 0
for token in tokens:
if i < alg.getVisibleParametersCount():
execcommand+=token + ","
else:
execcommand+="None,"
i+=1
s += "\toutputs=" + execcommand[:-1] + ")\n"
i = -1 * len(alg.outputs)
for out in alg.outputs:
filename = tokens[i][1:-1]
s+="\toutput=outputs['" + out.name + "']\n"
if isinstance(out, (OutputNumber, OutputString)):
s+="self.assertTrue(" + str(out) + ", output)\n"
if isinstance(out, OutputRaster):
dataset = gdal.Open(filename, GA_ReadOnly)
array = dataset.ReadAsArray(1)
s+="\tself.assertTrue(os.path.isfile(output))\n"
s+="\tself.assertEqual(hashraster(output)," + str(hash(array)) + ")\n"
if isinstance(out, OutputVector):
layer = Sextante.getObject(filename)
fields = layer.pendingFields()
s+="\tlayer=sextante.getobject(output)\n"
s+="\tfields=layer.pendingFields()\n"
s+="\texpectednames=[" + ",".join([str(f.name()) for f in fields]) + "]\n"
s+="\texpectedtypes=[" + ",".join([str(f.typeName()) for f in fields]) + "]\n"
s+="\tnames=[str(f.name()) for f in fields]\n"
s+="\ttypes=[str(f.typeName()) for f in fields]\n"
s+="\tself.assertEqual(exceptednames, names)\n"
s+="\tself.assertEqual(exceptedtypes, types)\n"
features = QGisLayers.features(layer)
numfeat = len(features)
s+="\tfeatures=sextante.getfeatures(layer))\n"
s+="\tself.assertEqual(" + str(numfeat) + ", len(features)\n"
if numfeat > 0:
feature = features.next()
attrs = feature.attributes()
s+="\tfeature=features.next()\n"
s+="\tattrs=feature.attributes()\n"
s+="\texpectedvalues=[" + ",".join([str(attr.toString()) for attr in attrs]) + "]\n"
s+="\tvalues=[str(attr.toString()) for attr in attrs]\n"
s+="\tself.assertEqual(exceptedtypes, types)\n"
dlg = ShowTestDialog(s)
dlg.exec_()
示例7: algoptions
# 需要导入模块: from sextante.core.Sextante import Sextante [as 别名]
# 或者: from sextante.core.Sextante.Sextante import getAlgorithm [as 别名]
def algoptions(name):
alg = Sextante.getAlgorithm(name)
if alg != None:
s =""
for param in alg.parameters:
if isinstance(param, ParameterSelection):
s+=param.name + "(" + param.description + ")\n"
i=0
for option in param.options:
s+= "\t" + str(i) + " - " + str(option) + "\n"
i+=1
print(s)
else:
print "Algorithm not found"
示例8: executeAlgorithmAsBatchProcess
# 需要导入模块: from sextante.core.Sextante import Sextante [as 别名]
# 或者: from sextante.core.Sextante.Sextante import getAlgorithm [as 别名]
def executeAlgorithmAsBatchProcess(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
alg = Sextante.getAlgorithm(item.alg.commandLineName())
dlg = BatchProcessingDialog(alg)
dlg.exec_()
示例9: editRenderingStyles
# 需要导入模块: from sextante.core.Sextante import Sextante [as 别名]
# 或者: from sextante.core.Sextante.Sextante import getAlgorithm [as 别名]
def editRenderingStyles(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
alg = Sextante.getAlgorithm(item.alg.commandLineName())
dlg = EditRenderingStylesDialog(alg)
dlg.exec_()
示例10: fillTree
# 需要导入模块: from sextante.core.Sextante import Sextante [as 别名]
# 或者: from sextante.core.Sextante.Sextante import getAlgorithm [as 别名]
def fillTree(self):
self.algorithmTree.clear()
text = unicode(self.searchBox.text())
for providerName in Sextante.algs.keys():
groups = {}
provider = Sextante.algs[providerName]
name = "ACTIVATE_" + providerName.upper().replace(" ", "_")
if not SextanteConfig.getSetting(name):
continue
algs = provider.values()
#add algorithms
for alg in algs:
if not alg.showInToolbox:
continue
if text =="" or text.lower() in alg.name.lower():
if alg.group in groups:
groupItem = groups[alg.group]
else:
groupItem = QTreeWidgetItem()
groupItem.setText(0,alg.group)
groups[alg.group] = groupItem
algItem = TreeAlgorithmItem(alg)
groupItem.addChild(algItem)
actions = Sextante.actions[providerName]
for action in actions:
if text =="" or text.lower() in action.name.lower():
if action.group in groups:
groupItem = groups[action.group]
else:
groupItem = QTreeWidgetItem()
groupItem.setText(0,action.group)
groups[action.group] = groupItem
algItem = TreeActionItem(action)
groupItem.addChild(algItem)
if len(groups) > 0:
providerItem = QTreeWidgetItem()
providerItem.setText(0, Sextante.getProviderFromName(providerName).getDescription()
+ " [" + str(len(provider)) + " geoalgorithms]")
providerItem.setIcon(0, Sextante.getProviderFromName(providerName).getIcon())
for groupItem in groups.values():
providerItem.addChild(groupItem)
self.algorithmTree.addTopLevelItem(providerItem)
providerItem.setExpanded(text!="")
for groupItem in groups.values():
if text != "":
groupItem.setExpanded(True)
self.algorithmTree.sortItems(0, Qt.AscendingOrder)
showRecent = SextanteConfig.getSetting(SextanteConfig.SHOW_RECENT_ALGORITHMS)
if showRecent:
recent = SextanteLog.getRecentAlgorithms()
if len(recent) != 0:
found = False
recentItem = QTreeWidgetItem()
recentItem.setText(0, self.tr("Recently used algorithms"))
for algname in recent:
alg = Sextante.getAlgorithm(algname)
if alg is not None:
algItem = TreeAlgorithmItem(alg)
recentItem.addChild(algItem)
found = True
if found:
self.algorithmTree.insertTopLevelItem(0, recentItem)
recentItem.setExpanded(True)
self.algorithmTree.setWordWrap(True)