def _executeAlgorithm(alg): ok, message = alg.canExecute() if not ok: dlg = MessageDialog() dlg.setTitle(Processing.tr('Missing dependency')) dlg.setMessage( Processing.tr('<h3>Missing dependency. This algorithm cannot ' 'be run :-( </h3>\n{0}').format(message)) dlg.exec_() return if (alg.countVisibleParameters()) > 0: dlg = alg.createCustomParametersWidget(None) if not dlg: dlg = AlgorithmDialog(alg) canvas = iface.mapCanvas() prevMapTool = canvas.mapTool() dlg.show() dlg.exec_() if canvas.mapTool() != prevMapTool: try: canvas.mapTool().reset() except: pass canvas.setMapTool(prevMapTool) else: feedback = MessageBarProgress() context = dataobjects.createContext(feedback) parameters = {} ret, results = execute(alg, parameters, context, feedback) handleAlgorithmResults(alg, context, feedback) feedback.close()
def unload(self): self.toolbox.setVisible(False) self.iface.removeDockWidget(self.toolbox) self.iface.attributesToolBar().removeAction(self.toolboxAction) self.resultsDock.setVisible(False) self.iface.removeDockWidget(self.resultsDock) self.toolbox.deleteLater() self.menu.deleteLater() # delete temporary output files folder = QgsProcessingUtils.tempFolder() if QDir(folder).exists(): shutil.rmtree(folder, True) # also delete temporary help files folder = tempHelpFolder() if QDir(folder).exists(): shutil.rmtree(folder, True) self.iface.unregisterMainWindowAction(self.toolboxAction) self.iface.unregisterMainWindowAction(self.modelerAction) self.iface.unregisterMainWindowAction(self.historyAction) self.iface.unregisterMainWindowAction(self.resultsAction) self.iface.unregisterOptionsWidgetFactory(self.options_factory) self.iface.deregisterLocatorFilter(self.locator_filter) self.iface.unregisterCustomDropHandler(self.drop_handler) QgsApplication.dataItemProviderRegistry().removeProvider(self.item_provider) removeMenus() Processing.deinitialize()
def setUpClass(cls): start_app() from processing_gsoc_grass.core.Processing import Processing Processing.initialize() cls.cleanup_paths = [] assert Grass7Utils.installedVersion()
def setUpClass(cls): start_app() QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) from processing_gsoc_grass.core.Processing import Processing Processing.initialize() cls.cleanup_paths = [] cls.in_place_layers = {} cls.vector_layer_params = {}
def setUpClass(cls): start_app() from processing_gsoc_grass.core.Processing import Processing Processing.initialize() cls.cleanup_paths = [] cls.temp_dir = tempfile.mkdtemp() cls.cleanup_paths.append(cls.temp_dir) assert Grass7Utils.installedVersion()
def __init__(self, iface): self.iface = iface self.options_factory = ProcessingOptionsFactory() self.options_factory.setTitle(self.tr('Processing')) iface.registerOptionsWidgetFactory(self.options_factory) self.drop_handler = ProcessingDropHandler() iface.registerCustomDropHandler(self.drop_handler) self.item_provider = ProcessingDataItemProvider() QgsApplication.dataItemProviderRegistry().addProvider(self.item_provider) self.locator_filter = AlgorithmLocatorFilter() iface.registerLocatorFilter(self.locator_filter) Processing.initialize()
def runAndLoadResults(algOrName, parameters, feedback=None, context=None): """Executes given algorithm and load its results into QGIS project when possible. """ if isinstance(algOrName, QgsProcessingAlgorithm): alg = algOrName else: alg = QgsApplication.processingRegistry().createAlgorithmById( algOrName) # output destination parameters to point to current project for param in alg.parameterDefinitions(): if not param.name() in parameters: continue if isinstance(param, (QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination, QgsProcessingParameterRasterDestination)): p = parameters[param.name()] if not isinstance(p, QgsProcessingOutputLayerDefinition): parameters[param.name()] = QgsProcessingOutputLayerDefinition( p, QgsProject.instance()) else: p.destinationProject = QgsProject.instance() parameters[param.name()] = p return Processing.runAlgorithm(alg, parameters=parameters, onFinish=handleAlgorithmResults, feedback=feedback, context=context)
from processing_gsoc_grass.gui.MessageDialog import MessageDialog from processing_gsoc_grass.gui.AlgorithmDialog import AlgorithmDialog from qgis.utils import iface from qgis.core import QgsApplication from processing_gsoc_grass.gui.MessageBarProgress import MessageBarProgress from processing_gsoc_grass.gui.AlgorithmExecutor import execute from processing_gsoc_grass.gui.Postprocessing import handleAlgorithmResults from processing_gsoc_grass.core.Processing import Processing from processing_gsoc_grass.tools import dataobjects algorithmsToolbar = None menusSettingsGroup = 'Menus' defaultMenuEntries = {} vectorMenu = QApplication.translate('MainWindow', 'Vect&or') analysisToolsMenu = vectorMenu + "/" + Processing.tr('&Analysis Tools') defaultMenuEntries.update({'qgis:distancematrix': analysisToolsMenu, 'qgis:sumlinelengths': analysisToolsMenu, 'qgis:countpointsinpolygon': analysisToolsMenu, 'qgis:listuniquevalues': analysisToolsMenu, 'qgis:basicstatisticsforfields': analysisToolsMenu, 'qgis:nearestneighbouranalysis': analysisToolsMenu, 'native:meancoordinates': analysisToolsMenu, 'native:lineintersections': analysisToolsMenu}) researchToolsMenu = vectorMenu + "/" + Processing.tr('&Research Tools') defaultMenuEntries.update({'qgis:creategrid': researchToolsMenu, 'qgis:randomselection': researchToolsMenu, 'qgis:randomselectionwithinsubsets': researchToolsMenu, 'qgis:randompointsinextent': researchToolsMenu, 'qgis:randompointsinlayerbounds': researchToolsMenu, 'qgis:randompointsinsidepolygons': researchToolsMenu,
def run(algOrName, parameters, onFinish=None, feedback=None, context=None): """Executes given algorithm and returns its outputs as dictionary object. """ return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
def tearDownClass(cls): from processing_gsoc_grass.core.Processing import Processing Processing.deinitialize() for path in cls.cleanup_paths: shutil.rmtree(path)
def setUpClass(cls): start_app() from processing_gsoc_grass.core.Processing import Processing Processing.initialize() cls.cleanup_paths = []
def setUpClass(cls): # start_app() from processing_gsoc_grass.core.Processing import Processing Processing.initialize()