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 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": 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 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()