本文整理汇总了Python中processing.run方法的典型用法代码示例。如果您正苦于以下问题:Python processing.run方法的具体用法?Python processing.run怎么用?Python processing.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类processing
的用法示例。
在下文中一共展示了processing.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runAlg
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def runAlg(self, algName, parameters, feedback=None, context=None):
"""
Executes a given algorithm.
:param algName: (str) target algorithm's name.
:param parameters: (dict) set of arguments for target algorithm.
:param feedback: (QgsProcessingFeedback) QGIS progress tracking object.
:param context: (QgsProcessingContext) execution's environmental parameters.
"""
out = processing.run(algName, parameters, None,\
feedback or QgsProcessingFeedback(),
context or QgsProcessingContext()
)
outputstr = 'FLAGS' if 'FLAGS' in out else 'OUTPUT' if 'OUTPUT' in out else ''
if outputstr:
out[outputstr].setName(algName.split(':')[-1])
return out[outputstr]
return out
示例2: expectedOutput
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def expectedOutput(self, algName, test):
"""
Gets the expect output layer.
:param algName: (str) target algorithm's name.
:param test: (int) test being run.
:return: (QgsVectorLayer) expected output layer.
"""
path = os.path.join(
self.CURRENT_PATH, 'expected_outputs', algName.split(':')[-1],
'test_{0}.gpkg'.format(test)
)
if os.path.exists(path):
return QgsVectorLayer(
path,
"{alg}_test_{test}_output".format(alg=algName.split(':')[-1], test=test),
"ogr"
)
示例3: runGrassDissolve
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def runGrassDissolve(self, inputLyr, context, feedback=None, column=None, outputLyr=None, onFinish=None):
"""
Runs dissolve from GRASS algorithm provider.
:param inputLyr: (QgsVectorLayer) layer to be dissolved.
:param context: (QgsProcessingContext) processing context.
:param feedback: (QgsProcessingFeedback) QGIS object to keep track of progress/cancelling option.
:param column: ()
:param outputLyr: (str) URI to output layer.
:param onFinish: (list-of-str) sequence of algs to be run after dissolve is executed, in execution order.
:return: (QgsVectorLayer) dissolved (output) layer.
"""
parameters = {
'GRASS_MIN_AREA_PARAMETER' : 0.0001,
'GRASS_OUTPUT_TYPE_PARAMETER' : 0,
'GRASS_REGION_PARAMETER' : None,
'GRASS_SNAP_TOLERANCE_PARAMETER' : -1,
'GRASS_VECTOR_DSCO' : '',
'GRASS_VECTOR_EXPORT_NOCAT' : False,
'GRASS_VECTOR_LCO' : '',
'column' : column,
'input' : inputLyr,
'output' : outputLyr or QgsProcessingUtils.generateTempFilename('output.shp')
}
output = processing.run('grass7:v.dissolve', parameters, onFinish, feedback, context)
return self.getGrassReturn(output, context)
示例4: runOverlay
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def runOverlay(self, lyrA, lyrB, context, feedback = None, snap=0, operator=0, minArea=0.0001):
output = QgsProcessingUtils.generateTempFilename('output.shp')
parameters = {
'ainput':lyrA,
'atype':0,
'binput':lyrB,
'btype':0,
'operator':operator,
'snap':snap,
'-t':False,
'output':output,
'GRASS_REGION_PARAMETER':None,
'GRASS_SNAP_TOLERANCE_PARAMETER':-1,
'GRASS_MIN_AREA_PARAMETER':minArea,
'GRASS_OUTPUT_TYPE_PARAMETER':0,
'GRASS_VECTOR_DSCO':'',
'GRASS_VECTOR_LCO':''
}
outputDict = processing.run('grass7:v.overlay', parameters, context = context, feedback = feedback)
return self.getGrassReturn(outputDict, context)
示例5: runIdentifyDangles
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def runIdentifyDangles(self, inputLayer, searchRadius, context, feedback = None, onlySelected=False, lineFilter = None, polygonFilter = None, ignoreUnsegmented = False, ignoreInner = False, flagLyr=None):
flagLyr = 'memory:' if flagLyr is None else flagLyr
lineFilter = [] if lineFilter is None else lineFilter
polygonFilter = [] if polygonFilter is None else polygonFilter
parameters = {
'INPUT' : inputLayer,
'SELECTED' : onlySelected,
'TOLERANCE' : searchRadius,
'LINEFILTERLAYERS' : lineFilter,
'POLYGONFILTERLAYERS' : polygonFilter,
'TYPE' : ignoreUnsegmented,
'IGNOREINNER' : ignoreInner,
'FLAGS' : flagLyr
}
output = processing.run('dsgtools:identifydangles', parameters, context = context, feedback = feedback)
return output['FLAGS']
示例6: runBuffer
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def runBuffer(self, inputLayer, distance, context, dissolve=False, endCapStyle=None, joinStyle=None,\
segments=None, mitterLimit=None, feedback=None, outputLyr=None):
endCapStyle = 0 if endCapStyle is None else endCapStyle
joinStyle = 0 if joinStyle is None else joinStyle
segments = 5 if segments is None else segments
mitterLimit = 2 if mitterLimit is None else mitterLimit
outputLyr = 'memory:' if outputLyr is None else outputLyr
parameters = {
'INPUT' : inputLayer,
'DISTANCE' : distance,
'DISSOLVE' : dissolve,
'END_CAP_STYLE' : endCapStyle,
'JOIN_STYLE' : endCapStyle,
'SEGMENTS' : segments,
'MITER_LIMIT' : mitterLimit,
'OUTPUT' : outputLyr
}
output = processing.run("native:buffer", parameters, context = context, feedback = feedback)
return output['OUTPUT']
示例7: modelParameters
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def modelParameters(self, model=None):
"""
A list of parameters needed to be filled for the model to run.
:param model: (QgsProcessingModelAlgorithm) model to have its parameters
checked.
:return: (list-of-str)
"""
# IMPORTANT: this method seems to be causing QGIS to crash when called
# from command line. Error is "corrupted double-linked list / Aborted (core dumped)"
# seems to be a QGIS mishandling, but should be lloked into deeper.
# It works just fine running on plugin's thread - e.g. does not crash
# whilst running an algorithm or using it internally
# It seems the culprit is the parameterDefinitions method, from
# QgsProcessingModelAlgorithm
if not self._param:
return []
model = model or self.model()
return [
param.name() \
for param in model.parameterDefinitions()
]
示例8: run
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def run(self):
"""
Method reimplemented in order to run models in thread as a QgsTask.
:return: (bool) task success status.
"""
start = time()
try:
if not self.feedback.isCanceled() or not self.isCanceled():
self.output = {
"result" : {
k.split(":", 2)[-1] : v \
for k, v in self.runModel(self.feedback).items()
},
"status" : True,
"errorMessage" : ""
}
except Exception as e:
self.output = {
"result" : {},
"status" : False,
"errorMessage" : self.tr("Model has failed:\n'{error}'")\
.format(error=str(e))
}
self.output["executionTime"] = time() - start
return self.output["status"]
示例9: overlayCoverage
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def overlayCoverage(self, coverage, context):
output = QgsProcessingUtils.generateTempFilename('output.shp')
parameters = {
'ainput':coverage,
'atype':0,
'binput':coverage,
'btype':0,
'operator':0,
'snap':0,
'-t':False,
'output':output,
'GRASS_REGION_PARAMETER':None,
'GRASS_SNAP_TOLERANCE_PARAMETER':-1,
'GRASS_MIN_AREA_PARAMETER':0.0001,
'GRASS_OUTPUT_TYPE_PARAMETER':0,
'GRASS_VECTOR_DSCO':'',
'GRASS_VECTOR_LCO':''
}
x = processing.run('grass7:v.overlay', parameters, context = context)
lyr = QgsProcessingUtils.mapLayerFromString(x['output'], context)
lyr.setCrs(coverage.crs())
return lyr
示例10: overlayCoverage
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def overlayCoverage(self, coverage, context, feedback):
output = QgsProcessingUtils.generateTempFilename('output.shp')
parameters = {
'ainput':coverage,
'atype':0,
'binput':coverage,
'btype':0,
'operator':0,
'snap':0,
'-t':False,
'output':output,
'GRASS_REGION_PARAMETER':None,
'GRASS_SNAP_TOLERANCE_PARAMETER':-1,
'GRASS_MIN_AREA_PARAMETER':0.0001,
'GRASS_OUTPUT_TYPE_PARAMETER':0,
'GRASS_VECTOR_DSCO':'',
'GRASS_VECTOR_LCO':''
}
x = processing.run('grass7:v.overlay', parameters, context = context, feedback = feedback)
lyr = QgsProcessingUtils.mapLayerFromString(x['output'], context)
return lyr
示例11: cleanCoverage
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def cleanCoverage(self, coverage, context):
output = QgsProcessingUtils.generateTempFilename('output.shp')
error = QgsProcessingUtils.generateTempFilename('error.shp')
parameters = {
'input':coverage,
'type':[0,1,2,3,4,5,6],
'tool':[0,6],
'threshold':'-1',
'-b':False,
'-c':True,
'output' : output,
'error': error,
'GRASS_REGION_PARAMETER':None,
'GRASS_SNAP_TOLERANCE_PARAMETER': -1,
'GRASS_MIN_AREA_PARAMETER': 0.0001,
'GRASS_OUTPUT_TYPE_PARAMETER': 0,
'GRASS_VECTOR_DSCO':'',
'GRASS_VECTOR_LCO':''
}
x = processing.run('grass7:v.clean', parameters, context = context)
lyr = QgsProcessingUtils.mapLayerFromString(x['output'], context)
return lyr
示例12: cleanLayer
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def cleanLayer(self, inputLyr, toolList, context, typeList=[0,1,2,3,4,5,6]):
#TODO write one class that runs all processing stuff (model that tomorrow)
output = QgsProcessingUtils.generateTempFilename('output.shp')
error = QgsProcessingUtils.generateTempFilename('error.shp')
parameters = {
'input':inputLyr,
'type':typeList,
'tool':toolList,
'threshold':'-1',
'-b':False,
'-c':True,
'output' : output,
'error': error,
'GRASS_REGION_PARAMETER':None,
'GRASS_SNAP_TOLERANCE_PARAMETER': -1,
'GRASS_MIN_AREA_PARAMETER': 0.0001,
'GRASS_OUTPUT_TYPE_PARAMETER': 0,
'GRASS_VECTOR_DSCO':'',
'GRASS_VECTOR_LCO':''
}
x = processing.run('grass7:v.clean', parameters, context = context)
lyr = QgsProcessingUtils.mapLayerFromString(x['output'], context)
return lyr
示例13: buffer_creation
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def buffer_creation(self):
answer = self.question("Buffer Creation", "Would you like to create a buffer?")
if answer == QMessageBox.Yes:
bufferNumber = self.inputDialog(2, "Buffer Creation", "How many buffers do you want to create?")
for x in range(0, (bufferNumber[0])):
layerInput = self.inputDialog(1, "Buffer %d" % (x+1), "Enter the name of your layer to be buffered: ")
while ((layerInput[1] == True) and (len(QgsProject.instance().mapLayersByName(layerInput[0])) == 0)):
self.information("Error", "There is no layer named " + layerInput[0] + "!")
layerInput = self.inputDialog(1, "Buffer %d" % (x+1), "Enter the name of your layer to be buffered: ")
if layerInput[1] == False:
break
layerName = layerInput[0]
bufferDist = self.inputDialog(2, "Buffer %d" % (x+1), "Enter the distance to buffer: ")[0]
param = { 'INPUT' : QgsProject.instance().mapLayersByName(layerName)[0], 'DISTANCE' : bufferDist, 'SEGMENTS' : 5, 'END_CAP_STYLE' : 0, 'JOIN_STYLE' : 0, 'MITER_LIMIT' : 2, 'DISSOLVE' : False, 'OUTPUT' : 'memory:' }
bufferLayer = QgsProject.instance().addMapLayer(processing.run("qgis:buffer", param)['OUTPUT'])
inputAnswer = self.inputDialog(1, "Layer Name", "Name the output buffer layer: ")
if (inputAnswer[1] == True):
bufferLayer.setName(inputAnswer[0])
开发者ID:geometalab,项目名称:GeoPythonConf2018-QGIS-Processing-Workshop,代码行数:21,代码来源:Master Script Model.py
示例14: old_buffer_creation
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def old_buffer_creation(self):
answer = self.question("Buffer Creation", "Would you like to create a buffer?")
if answer == QMessageBox.Yes:
bufferNumber = self.inputDialog(2, "Buffer Creation", "How many buffers do you want to create?")
print("Input selected: " + str(bufferNumber[0]))
for x in range(0, (bufferNumber[0])):
layerName = self.inputDialog(1, "Buffer %d" % x, "Enter the name of your layer to be buffered: ")
if (layerName[1] == QMessageBox.Cancel):
break
while (len(QgsProject.instance().mapLayersByName(layerName[0])) == 0):
if (layerName[1] == QMessageBox.Cancel):
break
self.information("Error", "There is no layer named " + layerName[0] + "!")
layerName = self.inputDialog(1, "Buffer %d" % x, "Enter the name of your layer to be buffered: ")
bufferDist = self.inputDialog(2, "Buffer %d" % x, "Enter the distance to buffer: ")[0]
while (len(layerName) != 0):
param = { 'INPUT' : QgsProject.instance().mapLayersByName(layerName[0])[0], 'DISTANCE' : bufferDist, 'SEGMENTS' : 5, 'END_CAP_STYLE' : 0, 'JOIN_STYLE' : 0, 'MITER_LIMIT' : 2, 'DISSOLVE' : False, 'OUTPUT' : 'memory:' }
bufferLayer = QgsProject.instance().addMapLayer(processing.run("qgis:buffer", param)['OUTPUT'])
inputAnswer = self.inputDialog(1, "Layer Name", "Name the output buffer layer: ")
if (inputAnswer[1] == True):
bufferLayer.setName(inputAnswer[0])
if (len(layerName) == 0):
self.information("Error!", "The layer name you gave does not exist! Try again!")
开发者ID:geometalab,项目名称:GeoPythonConf2018-QGIS-Processing-Workshop,代码行数:26,代码来源:Master Script Model.py
示例15: perform_union
# 需要导入模块: import processing [as 别名]
# 或者: from processing import run [as 别名]
def perform_union(self):
answer = self.question("Union Creation", "Would you like to union 2 layers?")
if answer == QMessageBox.Yes:
layer1 = self.inputDialog(1, "Layer 1", "Enter the name of your first/base layer: ")
while ((layer1[1] == True) and (len(QgsProject.instance().mapLayersByName(layer1[0])) == 0)):
self.information("Error", "There is no layer named " + layer1[0] + "!")
layer1 = self.inputDialog(1, "Layer 1", "Enter the name of your first/base layer: ")
if (layer1[1] == True):
layer2 = self.inputDialog(1, "Layer 2", "Enter the name of your second/overlay layer: ")
while ((layer2[1] == True) and (len(QgsProject.instance().mapLayersByName(layer2[0])) == 0)):
self.information("Error", "There is no layer named " + layer2[0] + "!")
layer2 = self.inputDialog(1, "Layer 2", "Enter the name of your second/overlay layer: ")
if (layer2[1] == True):
param = { 'INPUT' : QgsProject.instance().mapLayersByName(layer1[0])[0], 'OVERLAY' : QgsProject.instance().mapLayersByName(layer2[0])[0], 'OUTPUT' : 'memory:' }
algoOutput = processing.run("qgis:union", param)
unionResult = QgsProject.instance().addMapLayer(algoOutput['OUTPUT'])
outputName = self.inputDialog(1, "Layer Name", "Name the output union layer: ")
if (outputName[1] == True):
unionResult.setName(outputName[0])
开发者ID:geometalab,项目名称:GeoPythonConf2018-QGIS-Processing-Workshop,代码行数:21,代码来源:Master Script Model.py