def unload(self): self.toolbox.setVisible(False) self.iface.removeDockWidget(self.toolbox) self.resultsDock.setVisible(False) self.iface.removeDockWidget(self.resultsDock) self.menu.deleteLater() # delete temporary output files folder = 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) removeMenus() Processing.deinitialize()
def getConsoleCommands(self): arguments = [] arguments.append('-resolution') arguments.append(self.RESOLUTION_OPTIONS[self.getParameterValue(self.RESOLUTION)]) if self.getParameterValue(buildvrt.SEPARATE): arguments.append('-separate') if self.getParameterValue(buildvrt.PROJ_DIFFERENCE): arguments.append('-allow_projection_difference') # Always write input files to a text file in case there are many of them and the # length of the command will be longer then allowed in command prompt listFile = os.path.join(tempFolder(), 'buildvrtInputFiles.txt') with open(listFile, 'w') as f: f.write(self.getParameterValue(buildvrt.INPUT).replace(';', '\n')) arguments.append('-input_file_list') arguments.append(listFile) out = self.getOutputValue(buildvrt.OUTPUT) # Ideally the file extensions should be limited to just .vrt but I'm not sure how # to do it simply so instead a check is performed. _, ext = os.path.splitext(out) if not ext.lower() == '.vrt': out = out.replace(ext, '.vrt') self.setOutputValue(self.OUTPUT, out) arguments.append(out) return ['gdalbuildvrt', GdalUtils.escapeAndJoin(arguments)]
def processAlgorithm(self, progress): arguments = [] arguments.append("-resolution") arguments.append(self.RESOLUTION_OPTIONS[self.getParameterValue(self.RESOLUTION)]) if self.getParameterValue(buildvrt.SEPARATE): arguments.append("-separate") if self.getParameterValue(buildvrt.PROJ_DIFFERENCE): arguments.append("-allow_projection_difference") # Always write input files to a text file in case there are many of them and the # length of the command will be longer then allowed in command prompt listFile = os.path.join(tempFolder(), "buildvrtInputFiles.txt") with open(listFile, "w") as f: f.write(self.getParameterValue(buildvrt.INPUT).replace(";", "\n")) arguments.append("-input_file_list") arguments.append(listFile) out = self.getOutputValue(buildvrt.OUTPUT) # Ideally the file extensions should be limited to just .vrt but I'm not sure how # to do it simply so instead a check is performed. _, ext = os.path.splitext(out) if not ext.lower() == ".vrt": out = out.replace(ext, ".vrt") self.setOutputValue(self.OUTPUT, out) arguments.append(out) GdalUtils.runGdal(["gdalbuildvrt", GdalUtils.escapeAndJoin(arguments)], progress)
def unload(self): self.toolbox.setVisible(False) self.menu.deleteLater() # delete temporary output files folder = tempFolder() if QDir(folder).exists(): shutil.rmtree(folder, True) self.iface.unregisterMainWindowAction(self.commanderAction)
def unload(self): self.toolbox.setVisible(False) self.iface.removeDockWidget(self.toolbox) self.menu.deleteLater() # delete temporary output files folder = tempFolder() 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.configAction) self.iface.unregisterMainWindowAction(self.resultsAction) self.iface.unregisterMainWindowAction(self.commanderAction) removeMenus()
def grassDataFolder(): tempfolder = os.path.join(tempFolder(), 'grassdata') mkdir(tempfolder) return tempfolder
def initialize(): icon = QIcon(os.path.dirname(__file__) + '/../images/alg.png') ProcessingConfig.settingIcons['General'] = icon ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.SHOW_DEBUG_IN_DIALOG, ProcessingConfig.tr('Show extra info in Log panel'), True)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.KEEP_DIALOG_OPEN, ProcessingConfig.tr('Keep dialog open after running an algorithm'), False)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.USE_SELECTED, ProcessingConfig.tr('Use only selected features'), True)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.USE_FILENAME_AS_LAYER_NAME, ProcessingConfig.tr('Use filename as layer name'), False)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.SHOW_RECENT_ALGORITHMS, ProcessingConfig.tr('Show recently executed algorithms'), True)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.OUTPUT_FOLDER, ProcessingConfig.tr('Output folder'), tempFolder(), valuetype=Setting.FOLDER)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.SHOW_CRS_DEF, ProcessingConfig.tr('Show layer CRS definition in selection boxes'), True)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.WARN_UNMATCHING_CRS, ProcessingConfig.tr("Warn before executing if layer CRS's do not match"), True)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.RASTER_STYLE, ProcessingConfig.tr('Style for raster layers'), '', valuetype=Setting.FILE)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.VECTOR_POINT_STYLE, ProcessingConfig.tr('Style for point layers'), '', valuetype=Setting.FILE)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.VECTOR_LINE_STYLE, ProcessingConfig.tr('Style for line layers'), '', valuetype=Setting.FILE)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.VECTOR_POLYGON_STYLE, ProcessingConfig.tr('Style for polygon layers'), '', valuetype=Setting.FILE)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.PRE_EXECUTION_SCRIPT, ProcessingConfig.tr('Pre-execution script'), '', valuetype=Setting.FILE)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.POST_EXECUTION_SCRIPT, ProcessingConfig.tr('Post-execution script'), '', valuetype=Setting.FILE)) ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.RECENT_ALGORITHMS, ProcessingConfig.tr('Recent algs'), '', hidden=True)) extensions = processing.tools.dataobjects.getSupportedOutputVectorLayerExtensions() ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.DEFAULT_OUTPUT_VECTOR_LAYER_EXT, ProcessingConfig.tr('Default output vector layer extension'), extensions[0], valuetype=Setting.SELECTION, options=extensions)) extensions = processing.tools.dataobjects.getSupportedOutputRasterLayerExtensions() ProcessingConfig.addSetting(Setting( ProcessingConfig.tr('General'), ProcessingConfig.DEFAULT_OUTPUT_RASTER_LAYER_EXT, ProcessingConfig.tr('Default output raster layer extension'), extensions[0], valuetype=Setting.SELECTION, options=extensions))
def initialize(): icon = QIcon(os.path.dirname(__file__) + '/../images/alg.png') ProcessingConfig.settingIcons['General'] = icon ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.SHOW_DEBUG_IN_DIALOG, ProcessingConfig.tr('Show extra info in Log panel'), True)) ProcessingConfig.addSetting( Setting( ProcessingConfig.tr('General'), ProcessingConfig.KEEP_DIALOG_OPEN, ProcessingConfig.tr( 'Keep dialog open after running an algorithm'), False)) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.USE_SELECTED, ProcessingConfig.tr('Use only selected features'), True)) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.USE_FILENAME_AS_LAYER_NAME, ProcessingConfig.tr('Use filename as layer name'), False)) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.SHOW_RECENT_ALGORITHMS, ProcessingConfig.tr('Show recently executed algorithms'), True)) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.OUTPUT_FOLDER, ProcessingConfig.tr('Output folder'), tempFolder(), valuetype=Setting.FOLDER)) ProcessingConfig.addSetting( Setting( ProcessingConfig.tr('General'), ProcessingConfig.SHOW_CRS_DEF, ProcessingConfig.tr( 'Show layer CRS definition in selection boxes'), True)) ProcessingConfig.addSetting( Setting( ProcessingConfig.tr('General'), ProcessingConfig.WARN_UNMATCHING_CRS, ProcessingConfig.tr( "Warn before executing if layer CRS's do not match"), True)) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.RASTER_STYLE, ProcessingConfig.tr('Style for raster layers'), '')) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.VECTOR_POINT_STYLE, ProcessingConfig.tr('Style for point layers'), '')) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.VECTOR_LINE_STYLE, ProcessingConfig.tr('Style for line layers'), '')) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.VECTOR_POLYGON_STYLE, ProcessingConfig.tr('Style for polygon layers'), '')) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.VECTOR_POLYGON_STYLE, ProcessingConfig.tr('Style for polygon layers'), '')) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.PRE_EXECUTION_SCRIPT, ProcessingConfig.tr('Pre-execution script'), '')) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.POST_EXECUTION_SCRIPT, ProcessingConfig.tr('Post-execution script'), '')) ProcessingConfig.addSetting( Setting(ProcessingConfig.tr('General'), ProcessingConfig.RECENT_ALGORITHMS, ProcessingConfig.tr('Recent algs'), '', hidden=True))
#Algorithm body #================================== import os from processing.tools.system import tempFolder from processing.core.ProcessingLog import ProcessingLog loglines = [] loglines.append('Post-classification comparison script console output') loglines.append('') # set up the actual and temporary outputs outputFile = open(output, 'w') outputFile.close() tempOutput = tempFolder() + os.sep + "postclassificationComparisionScript.txt" if os.path.exists(tempOutput): os.remove(tempOutput) if processing.runalg("grass7:r.kappa",classification,reference,'CHANGE DETECTION MATRIX',True,w,extent,tempOutput): with open(tempOutput) as inputFile, open(output, "a") as outputFile: lines = inputFile.readlines() writeLines = False for line in lines: if line.startswith('Cats') or line.startswith('cat#'): break if writeLines: outputFile.write(line) elif line.startswith('Error Matrix'): writeLines = True outputFile.write('Change detection matrix\n')