def troubleShootCLUZFiles(setupObject): cluz_setup.checkStatusObjectValues(setupObject) targetFileFine, targetFeatIDSet = checkTargetCsvFile(setupObject) puvspr2FileFine, puvspr2PuIDSet, puvspr2FeatIDSet, puvspr2RowNum, puvspr2RecCountDict = checkPuvspr2DatFile(setupObject) sporderFileFine, sporderPuIDSet, sporderFeatIDSet, sporderRowNum, sporderRecCountDict = checkSporderDatFile(setupObject) puFileFine, puPuIDSet = checkPuShapeFile(setupObject) progressMessage = "Comparing the files..." qgis.utils.iface.mainWindow().statusBar().showMessage(progressMessage) idValuesNotDuplicated = True idValuesNotDuplicated = checkIDsMatchInTargetTableAndPuvspr2(targetFeatIDSet, puvspr2FeatIDSet, idValuesNotDuplicated) idValuesNotDuplicated = checkIDsMatchInPULayerAndPuvspr2(puvspr2PuIDSet, puPuIDSet, idValuesNotDuplicated) abundDatFilesSame = True if puvspr2PuIDSet != sporderPuIDSet or puvspr2FeatIDSet != sporderFeatIDSet or puvspr2RowNum != sporderRowNum or puvspr2RecCountDict != sporderRecCountDict: qgis.utils.iface.messageBar().pushMessage("puvspr2.dat and sporder.dat: ", "The two files do not contain the same data. Delete the sporder.dat file in the input folder and CLUZ will create a new one in the correct format.", QgsMessageBar.WARNING) abundDatFilesSame = False if targetFileFine == True and puvspr2FileFine == True and puFileFine == True and idValuesNotDuplicated == True and abundDatFilesSame == True: if setupObject.setupStatus == "files_checked": cluz_setup.makeTargetDict(setupObject) qgis.utils.iface.messageBar().pushMessage("Status: ", "No problems were found and the Target table has been updated to ensure it reflects the current data.", QgsMessageBar.INFO) else: qgis.utils.iface.messageBar().pushMessage("Status: ", "No problems were found.", QgsMessageBar.INFO) progressMessage = "CLUZ Troubleshoot files completed" qgis.utils.iface.mainWindow().statusBar().showMessage(progressMessage)
def removeSelectedFeatures(self, setupObject, featStringDict): selectedFeatIDList = [ featStringDict[item.text()] for item in self.featListWidget.selectedItems() ] selectedFeatIDSet = set(selectedFeatIDList) selectedFeatIDListLength = len(selectedFeatIDList) if selectedFeatIDListLength > 0: qgis.utils.iface.mainWindow().statusBar().showMessage( "Updating puvspr2.dat.") cluz_functions1.remFeaturesFromPuvspr2(setupObject, selectedFeatIDSet) setupObject.abundPUKeyDict = cluz_setup.makeAbundancePUKeyDict( setupObject) cluz_setup.makeSporderDatFile(setupObject) qgis.utils.iface.mainWindow().statusBar().showMessage( "Updating target table.") cluz_functions1.remFeaturesFromTargetCsv_Dict( setupObject, selectedFeatIDSet) setupObject.targetDict = cluz_setup.makeTargetDict(setupObject) qgis.utils.iface.mainWindow().statusBar().showMessage( "Task successfully completed: " + str(selectedFeatIDListLength) + " features have been removed.") self.close() else: self.close() QMessageBox.critical( None, "No features selected", "No features were selected and so no changes have been made.")
def __init__(self, iface, setupObject): QDialog.__init__(self) self.iface = iface self.setupUi(self) self.clip = QApplication.clipboard() targetDict = cluz_setup.makeTargetDict(setupObject) if targetDict != "blank": setupObject.targetDict = targetDict self.loadTargetDictData(setupObject)
def convertCSVToAbundTable(self, setupObject): layerFactorCheck = True convFactorCheck = True unitIDFieldName = self.idfieldComboBox.currentText() csvFilePath = self.csvFileLineEdit.text() if csvFilePath == "": self.close() QMessageBox.critical(None, "No file specified", "Please specify a csv file to import.") layerFactorCheck = False elif os.path.isfile(csvFilePath) == False: self.close() QMessageBox.critical(None, "Incorrect format", "The specified csv file does not exist.") layerFactorCheck = False else: pass if layerFactorCheck == True: convFactor = 1 # Default value if self.userRadioButton.isChecked(): try: convFactor = float(self.convLineEdit.text()) if convFactor <= 0: self.close() QMessageBox.critical(None, "Incorrect conversion value", "The conversion value must be a number greater than 0.") convFactorCheck = False except: self.close() QMessageBox.critical(None, "Incorrect conversion value", "The conversion value must be a number greater than 0.") convFactorCheck = False if layerFactorCheck == True and convFactorCheck == True: addAbundDict, featIDList, warningStatus = cluz_functions1.makeCsvAddAbundDict(setupObject, csvFilePath, unitIDFieldName, convFactor) if warningStatus == "ExistingFeatures": self.close() QMessageBox.critical(None, "Duplicate features", "The feature ID values in the table duplicate some of those in the abundance table. This process will terminate.") elif warningStatus == "HeaderWithNoID": self.close() QMessageBox.critical(None, "Missing ID code", "One of the fields containing abundance data in the specified table does not contain any numerical characters and so does not specify the feature ID. This process will terminate.") else: setupObject.abundPUKeyDict = cluz_functions1.addAbundDictToAbundPUKeyDict(setupObject, addAbundDict) cluz_setup.makePuvspr2DatFile(setupObject) cluz_setup.makeSporderDatFile(setupObject) cluz_functions1.addFeaturesToTargetCsvFile(setupObject, addAbundDict, featIDList) setupObject.targetDict = cluz_setup.makeTargetDict(setupObject) self.close()
def removeSelectedFeatures(self, setupObject, featStringDict): selectedFeatIDList = [featStringDict[item.text()] for item in self.featListWidget.selectedItems()] selectedFeatIDSet = set(selectedFeatIDList) selectedFeatIDListLength = len(selectedFeatIDList) if selectedFeatIDListLength > 0: qgis.utils.iface.mainWindow().statusBar().showMessage("Updating puvspr2.dat.") cluz_functions1.remFeaturesFromPuvspr2(setupObject, selectedFeatIDSet) setupObject.abundPUKeyDict = cluz_setup.makeAbundancePUKeyDict(setupObject) cluz_setup.makeSporderDatFile(setupObject) qgis.utils.iface.mainWindow().statusBar().showMessage("Updating target table.") cluz_functions1.remFeaturesFromTargetCsv_Dict(setupObject, selectedFeatIDSet) setupObject.targetDict = cluz_setup.makeTargetDict(setupObject) qgis.utils.iface.mainWindow().statusBar().showMessage("Task successfully completed: " + str(selectedFeatIDListLength) + " features have been removed.") self.close() else: self.close() QMessageBox.critical(None, "No features selected", "No features were selected and so no changes have been made.")
def convertLayersToAbundTable(self, setupObject): layerFactorCheck = True convFactorCheck = True layerList = [] idFieldName = self.idfieldLineEdit.text() selectedLayerNameList = [item.text() for item in self.selectListWidget.selectedItems()] if len(selectedLayerNameList) == 0: self.close() qgis.utils.iface.messageBar().pushMessage("No layers selected", "No layers were selected.", QgsMessageBar.WARNING) layerFactorCheck = False else: listMapItems = QgsMapLayerRegistry.instance().mapLayers() for nameCode, layer in listMapItems.iteritems(): layerName = layer.name() if layerName in selectedLayerNameList: layerList.append(layer) for aLayer in layerList: provider = aLayer.dataProvider() aLayerName = aLayer.name() idFieldOrder = provider.fieldNameIndex(idFieldName) if idFieldOrder == -1: self.close() qgis.utils.iface.messageBar().pushMessage("Layer format error with " + aLayerName, "The specified ID field " + idFieldName + " is not in the layer " + aLayerName + ".", QgsMessageBar.WARNING) layerFactorCheck = False else: idField = provider.fields().field(idFieldOrder) idFieldType = idField.typeName() if idFieldType != "Integer": self.close() qgis.utils.iface.messageBar().pushMessage("Layer format error" + aLayerName, "The specified ID field " + idFieldName + " does not contain integer values.", QgsMessageBar.WARNING) layerFactorCheck = False if layerFactorCheck: convFactor = 1 if self.userRadioButton.isChecked(): try: convFactor = float(self.convLineEdit.text()) if convFactor <= 0: self.close() qgis.utils.iface.messageBar().pushMessage("Incorrect conversion value", "The conversion value must be a number greater than 0.", QgsMessageBar.WARNING) convFactorCheck = False except: self.close() qgis.utils.iface.messageBar().pushMessage("Incorrect conversion value", "The conversion value must be a number greater than 0.", QgsMessageBar.WARNING) convFactorCheck = False if layerFactorCheck and convFactorCheck: addAbundDict, addFeatIDList = cluz_functions1.makeVecAddAbundDict(setupObject, layerList, idFieldName, convFactor) existingIDSet = set(addFeatIDList).intersection(set(setupObject.targetDict.keys())) if len(existingIDSet) > 0: self.close() listText = "" for aID in existingIDSet: listText += str(aID) + ", " finalListText = listText[0: -2] qgis.utils.iface.messageBar().pushMessage("Existing features", "The abundance table already contains features with ID values of " + finalListText + ". This process will terminate without adding the new values.", QgsMessageBar.WARNING) else: if setupObject.abundPUKeyDict == "blank": setupObject.abundPUKeyDict = cluz_setup.makeAbundancePUKeyDict(setupObject) cluz_functions1.addFeaturesToPuvspr2File(setupObject, addAbundDict) setupObject.abundPUKeyDict = cluz_setup.makeAbundancePUKeyDict(setupObject) cluz_setup.makeSporderDatFile(setupObject) cluz_functions1.addFeaturesToTargetCsvFile(setupObject, addAbundDict, addFeatIDList) setupObject.targetDict = cluz_setup.makeTargetDict(setupObject) self.close()
def checkCreateAddFiles(setupObject): cluz_setup.createAndCheckCLUZFiles(setupObject) cluz_setup.makeTargetDict(setupObject) cluz_setup.checkAddPULayer(setupObject)
def convertCSVToAbundTable(self, setupObject): layerFactorCheck = True convFactorCheck = True unitIDFieldName = self.idfieldComboBox.currentText() csvFilePath = self.csvFileLineEdit.text() if csvFilePath == "": self.close() QMessageBox.critical(None, "No file specified", "Please specify a csv file to import.") layerFactorCheck = False elif os.path.isfile(csvFilePath) == False: self.close() QMessageBox.critical(None, "Incorrect format", "The specified csv file does not exist.") layerFactorCheck = False else: pass if layerFactorCheck == True: convFactor = 1 # Default value if self.userRadioButton.isChecked(): try: convFactor = float(self.convLineEdit.text()) if convFactor <= 0: self.close() QMessageBox.critical( None, "Incorrect conversion value", "The conversion value must be a number greater than 0." ) convFactorCheck = False except: self.close() QMessageBox.critical( None, "Incorrect conversion value", "The conversion value must be a number greater than 0." ) convFactorCheck = False if layerFactorCheck == True and convFactorCheck == True: addAbundDict, featIDList, warningStatus = cluz_functions1.makeCsvAddAbundDict( setupObject, csvFilePath, unitIDFieldName, convFactor) if warningStatus == "ExistingFeatures": self.close() QMessageBox.critical( None, "Duplicate features", "The feature ID values in the table duplicate some of those in the abundance table. This process will terminate." ) elif warningStatus == "HeaderWithNoID": self.close() QMessageBox.critical( None, "Missing ID code", "One of the fields containing abundance data in the specified table does not contain any numerical characters and so does not specify the feature ID. This process will terminate." ) else: setupObject.abundPUKeyDict = cluz_functions1.addAbundDictToAbundPUKeyDict( setupObject, addAbundDict) cluz_setup.makePuvspr2DatFile(setupObject) cluz_setup.makeSporderDatFile(setupObject) cluz_functions1.addFeaturesToTargetCsvFile( setupObject, addAbundDict, featIDList) setupObject.targetDict = cluz_setup.makeTargetDict(setupObject) self.close()
def convertLayersToAbundTable(self, setupObject): layerFactorCheck = True convFactorCheck = True layerList = [] idFieldName = self.idfieldLineEdit.text() selectedLayerNameList = [ item.text() for item in self.selectListWidget.selectedItems() ] if len(selectedLayerNameList) == 0: self.close() qgis.utils.iface.messageBar().pushMessage( "No layers selected", "No layers were selected.", QgsMessageBar.WARNING) layerFactorCheck = False else: listMapItems = QgsMapLayerRegistry.instance().mapLayers() for nameCode, layer in listMapItems.iteritems(): layerName = layer.name() if layerName in selectedLayerNameList: layerList.append(layer) for aLayer in layerList: provider = aLayer.dataProvider() aLayerName = aLayer.name() idFieldOrder = provider.fieldNameIndex(idFieldName) if idFieldOrder == -1: self.close() qgis.utils.iface.messageBar().pushMessage( "Layer format error with " + aLayerName, "The specified ID field " + idFieldName + " is not in the layer " + aLayerName + ".", QgsMessageBar.WARNING) layerFactorCheck = False else: idField = provider.fields().field(idFieldOrder) idFieldType = idField.typeName() if idFieldType != "Integer" and idFieldType != "Integer64": self.close() qgis.utils.iface.messageBar().pushMessage( "Layer format error" + aLayerName, "The specified ID field " + idFieldName + " does not contain integer values.", QgsMessageBar.WARNING) layerFactorCheck = False if layerFactorCheck: convFactor = 1 if self.userRadioButton.isChecked(): try: convFactor = float(self.convLineEdit.text()) if convFactor <= 0: self.close() qgis.utils.iface.messageBar().pushMessage( "Incorrect conversion value", "The conversion value must be a number greater than 0.", QgsMessageBar.WARNING) convFactorCheck = False except: self.close() qgis.utils.iface.messageBar().pushMessage( "Incorrect conversion value", "The conversion value must be a number greater than 0.", QgsMessageBar.WARNING) convFactorCheck = False if layerFactorCheck and convFactorCheck: addAbundDict, addFeatIDList = cluz_functions1.makeVecAddAbundDict( setupObject, layerList, idFieldName, convFactor) existingIDSet = set(addFeatIDList).intersection( set(setupObject.targetDict.keys())) if len(existingIDSet) > 0: self.close() listText = "" for aID in existingIDSet: listText += str(aID) + ", " finalListText = listText[0:-2] qgis.utils.iface.messageBar().pushMessage( "Existing features", "The abundance table already contains features with ID values of " + finalListText + ". This process will terminate without adding the new values.", QgsMessageBar.WARNING) else: if setupObject.abundPUKeyDict == "blank": setupObject.abundPUKeyDict = cluz_setup.makeAbundancePUKeyDict( setupObject) cluz_functions1.addFeaturesToPuvspr2File( setupObject, addAbundDict) setupObject.abundPUKeyDict = cluz_setup.makeAbundancePUKeyDict( setupObject) cluz_setup.makeSporderDatFile(setupObject) cluz_functions1.addFeaturesToTargetCsvFile( setupObject, addAbundDict, addFeatIDList) setupObject.targetDict = cluz_setup.makeTargetDict(setupObject) self.close()