def populateLayers( self ): layers = ftools_utils.getLayerNames([QGis.Line]) self.inPoint.clear() self.inPoint.addItems(layers) layers = ftools_utils.getLayerNames([QGis.Polygon]) self.inPolygon.clear() self.inPolygon.addItems(layers)
def manageGui(self): if self.myFunction == 2: # List unique values self.setWindowTitle(self.tr("List unique values")) self.label_2.setText(self.tr("Unique values")) self.label_4.setText(self.tr("Total unique values")) self.useSelected.setVisible(False) elif self.myFunction == 3: # Basic statistics self.setWindowTitle(self.tr("Basics statistics")) self.label_2.setText(self.tr("Statistics output")) self.label_4.setVisible(False) self.lstCount.setVisible(False) self.resize(381, 400) elif self.myFunction == 4: # Nearest neighbour analysis self.setWindowTitle(self.tr("Nearest neighbour analysis")) self.cmbField.setVisible(False) self.label.setVisible(False) self.useSelected.setVisible(False) self.label_2.setText(self.tr("Nearest neighbour statistics")) self.label_4.setVisible(False) self.lstCount.setVisible(False) self.resize(381, 200) self.inShape.clear() if self.myFunction == 4: myList = ftools_utils.getLayerNames([QGis.Point]) else: myList = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inShape.addItems(myList) return
def __init__(self, iface): QDialog.__init__(self) self.iface = iface # Set up the user interface from Designer. self.setupUi(self) QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile) self.setWindowTitle(self.tr("Sum line lengths")) self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok ) # populate layer list self.progressBar.setValue(0) mapCanvas = self.iface.mapCanvas() layers = ftools_utils.getLayerNames([QGis.Line]) self.inPoint.addItems(layers) layers = ftools_utils.getLayerNames([QGis.Polygon]) self.inPolygon.addItems(layers)
def __init__(self, iface): QDialog.__init__(self) self.iface = iface self.setupUi(self) self.setModal(False) # we want to be able to interact with the featuresmc.extent().width() # adjust user interface self.setWindowTitle( self.tr( "Check geometry validity" ) ) self.cmbField.setVisible( False ) self.label.setVisible( False ) self.useSelected.setVisible( True ) self.label_2.setText( self.tr( "Geometry errors" ) ) self.label_4.setText( self.tr( "Total encountered errors" ) ) self.partProgressBar.setVisible( False ) self.tblUnique.setSelectionMode(QAbstractItemView.SingleSelection) self.tblUnique.setSelectionBehavior(QAbstractItemView.SelectRows) # populate list of available layers myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] ) self.connect(self.tblUnique, SIGNAL("currentItemChanged(QTableWidgetItem*, QTableWidgetItem*)" ), self.zoomToError) self.inShape.addItems( myList ) self.cancel_close = self.buttonBox_2.button(QDialogButtonBox.Close) self.buttonOk = self.buttonBox_2.button(QDialogButtonBox.Ok) self.progressBar.setValue(0) self.storedScale = self.iface.mapCanvas().scale() # create marker for error self.marker = MarkerErrorGeometry(self.iface.mapCanvas())
def __init__(self, iface): QDialog.__init__(self, iface.mainWindow()) self.iface = iface self.setupUi(self) # self.setModal(False) # we want to be able to interact with the featuresmc.extent().width() # self.setWindowFlags( Qt.SubWindow ) # adjust user interface self.setWindowTitle( self.tr( "Check geometry validity" ) ) self.cmbField.setVisible( False ) self.label.setVisible( False ) self.useSelected.setVisible( True ) self.label_2.setText( self.tr( "Geometry errors" ) ) self.label_4.setText( self.tr( "Total encountered errors" ) ) self.partProgressBar.setVisible( False ) self.tblUnique.setSelectionMode(QAbstractItemView.SingleSelection) self.tblUnique.setSelectionBehavior(QAbstractItemView.SelectRows) # populate list of available layers myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] ) self.connect(self.tblUnique, SIGNAL("currentItemChanged(QTableWidgetItem*, QTableWidgetItem*)" ), self.zoomToError) self.inShape.addItems( myList ) self.buttonBox_2.setOrientation(Qt.Horizontal) self.cancel_close = self.buttonBox_2.button(QDialogButtonBox.Close) self.buttonOk = self.buttonBox_2.button(QDialogButtonBox.Ok) self.progressBar.setValue(0) self.storedScale = self.iface.mapCanvas().scale() # create marker for error self.marker = MarkerErrorGeometry(self.iface.mapCanvas()) settings = QSettings() self.restoreGeometry( settings.value("/fTools/ValidateDialog/geometry").toByteArray() ) QObject.connect( self.browseShpError, SIGNAL( "clicked()" ), self.outFile ) QObject.connect( self.ckBoxShpError, SIGNAL( "stateChanged( int )" ), self.updateGui ) self.updateGui()
def __init__(self, iface): QDialog.__init__(self) self.iface = iface # Set up the user interface from Designer. self.setupUi(self) QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile) QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.iupdate) QObject.connect(self.joinShape, SIGNAL("currentIndexChanged(QString)"), self.jupdate) QObject.connect(self.toolTable, SIGNAL("clicked()"), self.inFile) QObject.connect(self.rdoTable, SIGNAL("clicked()"), self.updateTableFields) QObject.connect(self.rdoVector, SIGNAL("clicked()"), self.jupdate) QObject.connect(self.cmbEncoding, SIGNAL("currentIndexChanged(QString)"), self.updateTableFields) self.setWindowTitle( self.tr("Join attributes") ) self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok ) # populate layer list self.progressBar.setValue(0) mapCanvas = self.iface.mapCanvas() layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) encodings = QgsVectorDataProvider.availableEncodings() self.cmbEncoding.addItems(encodings) id = encodings.indexOf(QSettings().value( "/UI/encoding", "System").toString()) if id < 0: id = len(encodings)-1 self.cmbEncoding.setCurrentIndex(id) self.inShape.addItems(layers) self.joinShape.addItems(layers)
def __init__(self, iface): self.iface = iface self.searchDir = '.' # Import required plugins and if missing show the plugin's name ftPath = os.path.join(str(QtCore.QFileInfo(QgsApplication.qgisUserDbFilePath()).path()), 'python/plugins/fTools') if not ftPath in sys.path: sys.path.append(ftPath) req_plugin = "ftools 0.5.10" try: import ftools_utils except: QtGui.QMessageBox.information(self, self.tr("Missing Plugins"), self.tr("Missing plugin: %s" % req_plugin)) QtGui.QDialog.__init__(self) # Set up the user interface from Designer. self.ui = Ui_qm_import() self.ui.setupUi(self) self.setFixedSize(465,398) self.setWindowTitle(self.tr("Import Marxan Results")) layers = ftools_utils.getLayerNames([QGis.Polygon]) self.ui.cbxPlanningGrid.addItems(layers) self.setFields(self.ui.cbxPlanningGrid.currentText()) self.setOutputField() self.ui.buttonOk = self.ui.buttonBox.button( QtGui.QDialogButtonBox.Ok ) QtCore.QObject.connect(self.ui.pbInputFile, QtCore.SIGNAL("clicked()"), self.selectInputFile) # selecting measure layer QtCore.QObject.connect(self.ui.cbxPlanningGrid, QtCore.SIGNAL("currentIndexChanged(QString)"), self.setFields) # selecting field name QtCore.QObject.connect(self.ui.cbxSelectField, QtCore.SIGNAL("currentIndexChanged(QString)"), self.setOutputField)
def fillLayersList( self ): self.lstLayers.clear() layers = ftools_utils.getLayerNames( [ QGis.Line, QGis.Point, QGis.Polygon ] ) for lay in layers: source = ftools_utils.getVectorLayerByName( lay ).source() item = QListWidgetItem( lay, self.lstLayers ) item.setData( Qt.UserRole, source ) item.setData( Qt.ToolTipRole, source )
def populateLayers( self ): layers = ftools_utils.getLayerNames([QGis.Line]) self.inLine1.blockSignals( True ) self.inLine2.blockSignals( True ) self.inLine1.clear() self.inLine2.clear() self.inLine1.blockSignals( False ) self.inLine2.blockSignals( False ) self.inLine1.addItems(layers) self.inLine2.addItems(layers)
def __init__(self, iface): QDialog.__init__(self) self.iface = iface # Set up the user interface from Designer. self.setupUi(self) self.polygons = False QObject.connect(self.outTool, SIGNAL("clicked()"), self.outFile) layer_list = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inShape.addItems(layer_list)
def __init__(self, iface): QDialog.__init__(self, iface.mainWindow()) self.iface = iface # Set up the user interface from Designer. self.setupUi(self) QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update) self.setWindowTitle(self.tr("Random selection within subsets")) self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok ) # populate layer list self.progressBar.setValue(0) layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inShape.addItems(layers)
def __init__(self, iface): QDialog.__init__(self) self.iface = iface self.setupUi(self) QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile) QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update) self.progressBar.setValue(0) self.setWindowTitle(self.tr("Random Points")) self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok ) self.mapCanvas = self.iface.mapCanvas() layers = ftools_utils.getLayerNames([QGis.Polygon, "Raster"]) self.inShape.addItems(layers)
def __init__(self, iface): QDialog.__init__(self, iface.mainWindow()) self.iface = iface # Set up the user interface from Designer. self.setupUi(self) QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile) self.setWindowTitle(self.tr("Join attributes by location")) self.buttonOk = self.buttonBox_2.button(QDialogButtonBox.Ok) # populate layer list self.progressBar.setValue(0) layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inShape.addItems(layers) self.joinShape.addItems(layers)
def __init__(self, iface): QDialog.__init__(self, iface.mainWindow()) self.opFlags = 0 self.iface = iface # Set up the user interface from Designer. self.setupUi(self) self.buttonOk = self.buttonBox.button(QDialogButtonBox.Ok) # populate layer list self.progressBar.setValue(0) layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inPolygon.addItems(layers) self.inPoint.addItems(layers) self.connect(self.inPoint, SIGNAL("currentIndexChanged(QString)"), self.updateCheck) self.cmbModify.addItems([self.tr("creating new selection"), self.tr("adding to current selection"), self.tr("removing from current selection")])
def __init__(self, iface): QDialog.__init__(self) self.iface = iface # Set up the user interface from Designer. self.setupUi(self) QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile) QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update) self.setWindowTitle(self.tr("Split vector layer")) self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok ) # populate layer list self.progressBar.setValue(0) mapCanvas = self.iface.mapCanvas() layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inShape.addItems(layers)
def __init__(self, iface): QDialog.__init__(self) self.iface = iface self.setupUi(self) QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile) QObject.connect(self.btnProjection, SIGNAL("clicked()"), self.outProjFile) QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateProj1) QObject.connect(self.cmbLayer, SIGNAL("currentIndexChanged(QString)"), self.updateProj2) self.setWindowTitle( self.tr("Export to new projection") ) self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok ) self.progressBar.setValue(0) mapCanvas = self.iface.mapCanvas() layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inShape.addItems(layers) self.cmbLayer.addItems(layers)
def __init__(self, iface): QDialog.__init__(self, iface.mainWindow()) self.iface = iface # Set up the user interface from Designer. self.setupUi(self) QObject.connect(self.btnFile, SIGNAL("clicked()"), self.saveFile) QObject.connect(self.inPoint1, SIGNAL("currentIndexChanged(QString)"), self.update1) QObject.connect(self.inPoint2, SIGNAL("currentIndexChanged(QString)"), self.update2) self.buttonOk = self.buttonBox_2.button(QDialogButtonBox.Ok) # populate layer list self.setWindowTitle(self.tr("Distance matrix")) self.progressBar.setValue(0) layers = ftools_utils.getLayerNames([QGis.Point]) self.inPoint1.addItems(layers) self.inPoint2.addItems(layers)
def __init__(self, iface): QDialog.__init__(self) self.iface = iface self.setupUi(self) self.xMin.setValidator(QDoubleValidator(self.xMin)) self.xMax.setValidator(QDoubleValidator(self.xMax)) self.yMin.setValidator(QDoubleValidator(self.yMin)) self.yMax.setValidator(QDoubleValidator(self.yMax)) QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile) self.setWindowTitle( self.tr("Regular points") ) self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok ) self.progressBar.setValue(0) self.mapCanvas = self.iface.mapCanvas() layers = ftools_utils.getLayerNames("all") self.inShape.addItems(layers)
def __init__(self, iface, function): QDialog.__init__(self) self.iface = iface self.function = function self.setupUi(self) self.updateUi() QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile) QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update) self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok ) # populate layer list self.progressBar.setValue(0) mapCanvas = self.iface.mapCanvas() layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inShape.addItems(layers)
def __init__(self, iface): QtGui.QDialog.__init__(self) self.iface = iface # Set up the user interface from Designer. self.setupUi(self) QtCore.QObject.connect(self.toolOut, QtCore.SIGNAL("clicked()"), self.outFile) QtCore.QObject.connect(self.inShape, QtCore.SIGNAL("currentIndexChanged(QString)"), self.update) self.setWindowTitle(self.tr("Eliminate sliver polygons")) self.buttonOk = self.buttonBox_2.button(QtGui.QDialogButtonBox.Ok) # populate layer list self.progressBar.setValue(0) self.area.setChecked(True) layers = ftools_utils.getLayerNames([QGis.Polygon]) self.inShape.addItems(layers) if len(layers) > 0: self.update(layers[0])
def __init__(self, iface): self.iface = iface self.progress = 0 self.step = 0 self.exportCount = 0 self.outDir = "." # Import required plugins and if missing show the plugin's name ftPath = os.path.join(str(QtCore.QFileInfo(QgsApplication.qgisUserDbFilePath()).path()), 'python/plugins/fTools') if not ftPath in sys.path: sys.path.append(ftPath) req_plugin = "ftools 0.5.10" try: import ftools_utils except: QtGui.QMessageBox.information(self, self.tr("Missing Plugins"), self.tr("Missing plugin: %s" % req_plugin)) QtGui.QDialog.__init__(self) # Set up the user interface from Designer. self.ui = Ui_qm_export() self.ui.setupUi(self) self.setFixedSize(725,712) self.setWindowTitle(self.tr("Export data to Marxan Input Files")) # add input layers to select planning grid layers = ftools_utils.getLayerNames([QGis.Polygon]) self.ui.cbxPlanningGrid.addItems(layers) self.ui.cbxTolerance.addItems(['100','10','1','0.1','0.01','0.001','0.0001','0.00001']) self.ui.cbxTolerance.setCurrentIndex(2) self.setExportFields(self.ui.cbxPlanningGrid.currentText()) self.ui.buttonOk = self.ui.buttonBox.button( QtGui.QDialogButtonBox.Ok ) # enabled automatic refresh of fields window QtCore.QObject.connect(self.ui.cbxPlanningGrid, QtCore.SIGNAL("currentIndexChanged(QString)"), self.setExportFields) # enable buttons under fields window QtCore.QObject.connect(self.ui.pbSelectAll, QtCore.SIGNAL("clicked()"), self.selectAll) QtCore.QObject.connect(self.ui.pbSelectNone, QtCore.SIGNAL("clicked()"), self.selectNone) QtCore.QObject.connect(self.ui.pbInvertSelection, QtCore.SIGNAL("clicked()"), self.invertSelection) QtCore.QObject.connect(self.ui.pbReadSpecFile, QtCore.SIGNAL("clicked()"), self.readSpecFile) # enable selection of output directory QtCore.QObject.connect(self.ui.pbOutputDir, QtCore.SIGNAL("clicked()"), self.setOutputDir) # enable accessiblity of boundary cost field selection QtCore.QObject.connect(self.ui.rdoLength, QtCore.SIGNAL("clicked()"), self.disableBCF) QtCore.QObject.connect(self.ui.rdoField, QtCore.SIGNAL("clicked()"), self.enableBCF) QtCore.QObject.connect(self.ui.rdoLengthnField, QtCore.SIGNAL("clicked()"), self.enableBCF)
def __init__(self, iface): QDialog.__init__(self) self.iface = iface # Set up the user interface from Designer. self.setupUi(self) # QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile) self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok ) QObject.connect(self.comboBox, SIGNAL("clicked()"), self.contiguity_from_shapefile()) #self.setWindowTitle(self.tr("Weights from Contiguity")) #self.generateWeights = self.pushButton( QPushButton.Ok ) # populate layer list # self.progressBar.setValue(0) mapCanvas = self.iface.mapCanvas() # layers = ftools_utils.getLayerNames([QGis.Line]) # self.inPoint.addItems(layers) layers = ftools_utils.getLayerNames([QGis.Polygon]) self.comboBox.addItems(layers)
def __init__(self, iface): QDialog.__init__(self, iface.mainWindow()) self.iface = iface self.setupUi(self) self.setWindowTitle(self.tr("Split vector layer")) QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile) QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update) self.workThread = None self.btnOk = self.buttonBox_2.button( QDialogButtonBox.Ok ) self.btnClose = self.buttonBox_2.button( QDialogButtonBox.Close ) # populate layer list layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inShape.addItems(layers)
def populateLayers( self ): self.inShape.clear() if self.myFunction == 3 or self.myFunction == 6: myList = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] ) elif self.myFunction == 4 or self.myFunction == 7: myList = ftools_utils.getLayerNames( [ QGis.Polygon ] ) elif self.myFunction == 8 or self.myFunction == 10: myList = ftools_utils.getLayerNames( [ QGis.Point ] ) elif self.myFunction == 9: myList = ftools_utils.getLayerNames( "all" ) elif self.myFunction == 11: myList = ftools_utils.getLayerNames( [ QGis.Line ] ) else: myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] ) self.inShape.addItems( myList )
def __init__(self, iface): QDialog.__init__(self, iface.mainWindow()) self.iface = iface self.setupUi(self) self.toolOut.setEnabled(False) self.toolOut.setVisible(False) self.outShape.setEnabled(False) self.outShape.setVisible(False) self.label_2.setVisible(False) self.label_2.setEnabled(False) self.setWindowTitle(self.tr("Define current projection")) self.buttonOk = self.buttonBox_2.button(QDialogButtonBox.Ok) QObject.connect(self.btnProjection, SIGNAL("clicked()"), self.outProjFile) QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateProj1) QObject.connect(self.cmbLayer, SIGNAL("currentIndexChanged(QString)"), self.updateProj2) # populate layer list self.progressBar.setValue(0) layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inShape.addItems(layers) self.cmbLayer.addItems(layers) self.crs = None
def populateLayers( self ): layers = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] ) self.cmbInputLayer.clear() self.cmbInputLayer.addItems( layers )
def __init__(self, iface): self.iface = iface # Import required plugins and if missing show the plugin's name ftPath = os.path.join( str(QtCore.QFileInfo(QgsApplication.qgisUserDbFilePath()).path()), 'python/plugins/fTools') if not ftPath in sys.path: sys.path.append(ftPath) req_plugin = "ftools 0.5.10" try: import ftools_utils except: QtGui.QMessageBox.information( self, self.tr("Missing Plugins"), self.tr("Missing plugin: %s" % req_plugin)) QtGui.QDialog.__init__(self) # Set up the user interface from Designer. self.ui = Ui_qm_calc() self.ui.setupUi(self) self.setFixedSize(809, 714) # self.setWindowTitle( self.tr("Calculate Planning Grid Conservation Factor Values")) # add input layers to select planning grid self.allLayers = ftools_utils.getLayerNames( [QGis.Polygon, QGis.Line, QGis.Point]) layers = ftools_utils.getLayerNames([QGis.Polygon]) self.ui.cbxPlanningGrid.addItems(layers) self.setMeasurePoints() self.setIdAndMeasureFields(self.ui.cbxPlanningGrid.currentText()) self.setOutputField() self.ui.rdoSum.setChecked(True) self.ui.rdoMeasure.setChecked(True) # setup calculations list self.setCalculations() # connect methods to button interactions # selecting type of layer to measure QtCore.QObject.connect(self.ui.rdoPoints, QtCore.SIGNAL("clicked()"), self.setMeasurePoints) QtCore.QObject.connect(self.ui.rdoLines, QtCore.SIGNAL("clicked()"), self.setMeasureLines) QtCore.QObject.connect(self.ui.rdoAreas, QtCore.SIGNAL("clicked()"), self.setMeasurePolygons) QtCore.QObject.connect(self.ui.rdoRaster, QtCore.SIGNAL("clicked()"), self.setMeasureRasters) # selecting measure layer QtCore.QObject.connect(self.ui.cbxPlanningGrid, QtCore.SIGNAL("currentIndexChanged(QString)"), self.setIdAndMeasureFields) # select single or multiple variale output QtCore.QObject.connect(self.ui.rdoCalcSingle, QtCore.SIGNAL("clicked()"), self.setSingle) QtCore.QObject.connect(self.ui.rdoCalcMulti, QtCore.SIGNAL("clicked()"), self.setMulti) # selecting measure or calculation QtCore.QObject.connect(self.ui.rdoMeasure, QtCore.SIGNAL("clicked()"), self.setMeasure) QtCore.QObject.connect(self.ui.rdoCalculate, QtCore.SIGNAL("clicked()"), self.setCalculate) QtCore.QObject.connect(self.ui.rdoPresence, QtCore.SIGNAL("clicked()"), self.setPresence) QtCore.QObject.connect(self.ui.cbxMeasureLayer, QtCore.SIGNAL("currentIndexChanged(QString)"), self.setCalcFields) # selecting field name QtCore.QObject.connect(self.ui.cbxSelectField, QtCore.SIGNAL("currentIndexChanged(QString)"), self.setOutputField) # calculation list actions QtCore.QObject.connect(self.ui.twCalculations, QtCore.SIGNAL("itemSelectionChanged()"), self.selectCalcForEdit) QtCore.QObject.connect(self.ui.pbCancel, QtCore.SIGNAL('clicked()'), self.cancelCalcEdit) QtCore.QObject.connect(self.ui.pbNew, QtCore.SIGNAL('clicked()'), self.newCalculation) QtCore.QObject.connect(self.ui.pbDelete, QtCore.SIGNAL('clicked()'), self.deleteCalculation) QtCore.QObject.connect(self.ui.pbSave, QtCore.SIGNAL('clicked()'), self.saveCalculation) # set main form buttons QtCore.QObject.connect(self.ui.pbOpenList, QtCore.SIGNAL('clicked()'), self.loadCalculationList) QtCore.QObject.connect(self.ui.pbSaveList, QtCore.SIGNAL('clicked()'), self.saveCalculationList) QtCore.QObject.connect(self.ui.pbClose, QtCore.SIGNAL('clicked()'), self.close) QtCore.QObject.connect(self.ui.pbRun, QtCore.SIGNAL('clicked()'), self.doCalculations)
def loadCalculation(self): import ftools_utils message = '' selected = self.ui.twCalculations.selectedItems() for item in selected: iText = str(item.text()) if item.column() == 0: layerList = ftools_utils.getLayerNames([QGis.Polygon]) cbIndex = -1 for lName in layerList: cLyr = ftools_utils.getVectorLayerByName(lName) if cLyr.source() == iText: cbIndex = self.ui.cbxPlanningGrid.findText(cLyr.name()) if cbIndex > -1: self.ui.cbxPlanningGrid.setCurrentIndex(cbIndex) else: self.ui.cbxPlanningGrid.setCurrentIndex(0) elif item.column() == 1: fldIndex = self.ui.cbxPuId.findText(iText) if fldIndex > -1: self.ui.cbxPuId.setCurrentIndex(fldIndex) elif item.column() == 2: self.setMeasurePoints() self.ui.rdoPoints.setChecked(True) layerList = ftools_utils.getLayerNames([QGis.Point]) cbIndex = -1 for lName in layerList: cLyr = ftools_utils.getVectorLayerByName(lName) if cLyr.source() == iText: cbIndex = self.ui.cbxMeasureLayer.findText(cLyr.name()) if cbIndex > -1: self.ui.cbxMeasureLayer.setCurrentIndex(cbIndex) else: self.setMeasureLines() self.ui.rdoLines.setChecked(True) layerList = ftools_utils.getLayerNames([QGis.Line]) cbIndex = -1 for lName in layerList: cLyr = ftools_utils.getVectorLayerByName(lName) if cLyr.source() == iText: cbIndex = self.ui.cbxMeasureLayer.findText( cLyr.name()) if cbIndex > -1: self.ui.cbxMeasureLayer.setCurrentIndex(cbIndex) else: self.setMeasurePolygons() self.ui.rdoAreas.setChecked(True) layerList = ftools_utils.getLayerNames([QGis.Polygon]) cbIndex = -1 for lName in layerList: cLyr = ftools_utils.getVectorLayerByName(lName) if cLyr.source() == iText: cbIndex = self.ui.cbxMeasureLayer.findText( cLyr.name()) if cbIndex > -1: self.ui.cbxMeasureLayer.setCurrentIndex(cbIndex) else: self.setMeasureRasters() self.ui.rdoRaster.setChecked(True) layerList = [] layers = [] for key, value in QgsMapLayerRegistry.instance( ).mapLayers().iteritems(): if 'raster' in str(value.__class__).lower(): layerList.append(str(value.name())) layers.append(value) cbIndex = -1 for q in range(len(layers)): if layers[q] == iText: cbIndex = self.ui.cbxMeasureLayer.findText( layerList[q]) if cbIndex > -1: self.ui.cbxMeasureLayer.setCurrentIndex( cbIndex) elif item.column() == 3: if iText == 'single': self.ui.rdoCalcSingle.setChecked(True) self.setSingle() else: self.ui.rdoCalcMulti.setChecked(True) self.setMulti() elif item.column() == 4: if iText == 'measure': self.ui.rdoMeasure.setChecked(True) self.setMeasure() elif iText == 'calculate': self.ui.rdoCalculate.setChecked(True) self.setCalculate() else: self.ui.rdoPresence.setChecked(True) self.setPresence() elif item.column() == 5: if self.ui.rdoMeasure.isChecked() == False: fldIndex = self.ui.cbxCalcField.findText(iText) if fldIndex > -1: self.ui.cbxCalcField.setCurrentIndex(fldIndex) elif item.column() == 6: if iText == 'sum': self.ui.rdoSum.setChecked(True) elif iText == 'mean': self.ui.rdoMean.setChecked(True) elif iText == 'max': self.ui.rdoMax.setChecked(True) elif iText == 'min': self.ui.rdoMin.setChecked(True) elif iText == 'count': self.ui.rdoCount.setChecked(True) elif item.column() == 7: outIndex = self.ui.cbxSelectField.findText(iText) if outIndex > -1: self.ui.cbxSelectField.setCurrentIndex(outIndex) self.ui.leNewField.setText('') else: self.ui.cbxSelectField.setCurrentIndex(0) self.ui.leNewField.setText(iText)
def loadCalculationList(self): import ftools_utils newLayersLoaded = False message = '' cFile = "" cFile = QtGui.QFileDialog.getOpenFileName( self, self.tr("Select calculations file"), '.', "*.csv") if cFile != "": tf = open(cFile, 'rU') calcData = tf.readlines() tf.close() rCnt = self.ui.twCalculations.rowCount() for i in range(rCnt): self.ui.twCalculations.removeRow(i) warnUser = False for i in range(len(calcData)): loadError = 0 fields = calcData[i].strip().split(',') if i == 0: if not fields[0] == 'pu_layer': return elif len(fields) == 8: # grid layer check # remove extra quotation marks fGText = fields[0].replace("'", '').replace("'", '') # get polygon layers layerList = ftools_utils.getLayerNames([QGis.Polygon]) cbIndex = -1 glName = '' for lName in layerList: cLyr = ftools_utils.getVectorLayerByName(lName) if cLyr.source() == fGText: glName = cLyr.name() if glName == '': # get default layer name glName = os.path.splitext(os.path.basename(fGText))[0] srcLyr = QgsVectorLayer(fGText, glName, 'ogr') if srcLyr.isValid(): if srcLyr.geometryType() == QGis.Polygon: self.allLayers.append(glName) QgsMapLayerRegistry.instance().addMapLayer( srcLyr) newLayersLoaded = True else: message = message + '%s is not an area layer and can not be used a PU layer%s' % ( glName, os.linesep) loadError += 1 warnUser = True else: message = message + '%s failed to load%s' % ( glName, os.linesep) loadError += 1 warnUser = True # measure layer check # remove extra quotation marks fMText = fields[2].replace("'", '').replace("'", '') # get all vector layers layerList = ftools_utils.getLayerNames( [QGis.Polygon, QGis.Line, QGis.Point]) cbIndex = -1 mlName = '' for lName in layerList: cLyr = ftools_utils.getVectorLayerByName(lName) if cLyr.source() == fMText: mlName = cLyr.name() if mlName == '': # get layer name from path extension = os.path.splitext( os.path.basename(fMText))[1] if extension == '.shp': mlName = os.path.splitext( os.path.basename(fMText))[0] srcLyr = QgsVectorLayer(fMText, mlName, 'ogr') if srcLyr.isValid(): #self.allLayers.append(mlName) QgsMapLayerRegistry.instance().addMapLayer( srcLyr) newLayersLoaded = True else: message = message + '%s failed to load%s' % ( mlName, os.linesep) loadError += 1 warnUser = True else: # measure raster layer check layerList = [] layers = [] for key, value in QgsMapLayerRegistry.instance( ).mapLayers().iteritems(): if 'raster' in str(value.__class__).lower(): layerList.append(str(value.name())) layers.append(value) for q in range(len(layers)): if layers[q] == fMText: mlName = layerList[q] if mlName == '': # get layer name from path mlName = os.path.splitext( os.path.basename(fMText))[0] srcLyr = QgsRasterLayer(fMText, mlName) if srcLyr.isValid(): self.allLayers.append(mlName) QgsMapLayerRegistry.instance().addMapLayer( srcLyr) newLayersLoaded = True else: message = message + '%s failed to load%s' % ( mlName, os.linesep) loadError += 1 warnUser = True if loadError == 0: # create row and populate it self.newCalculation() self.ui.twCalculations.item(i - 1, 0).setText(fGText) self.ui.twCalculations.item(i - 1, 1).setText( fields[1].replace("'", '').replace("'", '')) self.ui.twCalculations.item(i - 1, 2).setText(fMText) self.ui.twCalculations.item(i - 1, 3).setText( fields[3].replace("'", '').replace("'", '')) self.ui.twCalculations.item(i - 1, 4).setText( fields[4].replace("'", '').replace("'", '')) self.ui.twCalculations.item(i - 1, 5).setText( fields[5].replace("'", '').replace("'", '')) self.ui.twCalculations.item(i - 1, 6).setText( fields[6].replace("'", '').replace("'", '')) self.ui.twCalculations.item(i - 1, 7).setText( fields[7].replace("'", '').replace("'", '')) # check for weird rows rCnt = self.ui.twCalculations.rowCount() for i in range(rCnt): if self.ui.twCalculations.item(i, 0).text() == '': self.ui.twCalculations.removeRow(i) if warnUser: QtGui.QMessageBox.warning(self, self.tr("Load Error"), self.tr(message)) if newLayersLoaded: layers = ftools_utils.getLayerNames([QGis.Polygon]) self.ui.cbxPlanningGrid.addItems(layers) self.ui.pbRun.setEnabled(True) self.cancelCalcEdit()
def populateLayers( self ): layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) QObject.disconnect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update) self.inShape.clear() self.inShape.addItems(layers) QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
def populateLayers(self): layers = ftools_utils.getLayerNames("all") self.inShape.clear() self.inShape.addItems(layers)
def setMeasureLines(self): import ftools_utils layers = ftools_utils.getLayerNames([QGis.Line]) self.updateMeasureLayer(layers) self.setSingle()
def populateLayers(self): layers = ftools_utils.getLayerNames([QGis.Line]) self.inLine1.clear() self.inLine2.clear() self.inLine1.addItems(layers) self.inLine2.addItems(layers)
def populateLayers( self ): layers = ftools_utils.getLayerNames([QGis.Polygon, "Raster"]) QObject.disconnect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update) self.inShape.clear() self.inShape.addItems(layers) QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
def populateLayers( self ): layers = ftools_utils.getLayerNames("all") self.inShape.clear() self.inShape.addItems(layers)
def populateLayers( self ): layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon]) self.inShape.blockSignals(True) self.inShape.clear() self.inShape.blockSignals(False) self.inShape.addItems(layers)
def populateLayers( self ): layers = ftools_utils.getLayerNames([QGis.Polygon, "Raster"]) self.inShape.blockSignals(True) self.inShape.clear() self.inShape.blockSignals(False) self.inShape.addItems(layers)
def manageGui( self ): layers = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] ) self.cmbInputLayer.clear() self.cmbInputLayer.addItems( layers )
def manageGui(self): if self.myFunction == 1: # Singleparts to multipart self.setWindowTitle( self.tr( "Singleparts to multipart" ) ) self.lineEdit.setVisible(False) self.label.setVisible(False) self.label_2.setText( self.tr( "Output shapefile" ) ) self.cmbField.setVisible(True) self.field_label.setVisible(True) elif self.myFunction == 2: # Multipart to singleparts self.setWindowTitle( self.tr( "Multipart to singleparts" ) ) self.lineEdit.setVisible(False) self.label.setVisible(False) self.label_2.setText(self.tr( "Output shapefile" ) ) self.cmbField.setVisible(False) self.field_label.setVisible(False) elif self.myFunction == 3: # Extract nodes self.setWindowTitle( self.tr( "Extract nodes" ) ) self.lineEdit.setVisible(False) self.label.setVisible(False) self.cmbField.setVisible(False) self.field_label.setVisible(False) elif self.myFunction == 4: # Polygons to lines self.setWindowTitle( self.tr( "Polygons to lines" ) ) self.label_2.setText( self.tr( "Output shapefile" ) ) self.label_3.setText( self.tr( "Input polygon vector layer" ) ) self.label.setVisible(False) self.lineEdit.setVisible(False) self.cmbField.setVisible(False) self.field_label.setVisible(False) elif self.myFunction == 5: # Export/Add geometry columns self.setWindowTitle( self.tr( "Export/Add geometry columns" ) ) self.label_2.setText( self.tr( "Output shapefile" ) ) self.label_3.setText( self.tr( "Input vector layer" ) ) self.label.setVisible(False) self.lineEdit.setVisible(False) self.cmbField.setVisible(False) self.field_label.setVisible(False) elif self.myFunction == 7: # Polygon centroids self.setWindowTitle( self.tr( "Polygon centroids" ) ) self.label_2.setText( self.tr( "Output point shapefile" ) ) self.label_3.setText( self.tr( "Input polygon vector layer" ) ) self.label.setVisible( False ) self.lineEdit.setVisible( False ) self.cmbField.setVisible( False ) self.field_label.setVisible( False ) else: if self.myFunction == 8: # Delaunay triangulation self.setWindowTitle( self.tr( "Delaunay triangulation" ) ) self.label_3.setText( self.tr( "Input point vector layer" ) ) self.label.setVisible( False ) self.lineEdit.setVisible( False ) elif self.myFunction == 10: # Voronoi Polygons self.setWindowTitle( self.tr( "Voronoi polygon" ) ) self.label_3.setText( self.tr( "Input point vector layer" ) ) self.label.setText( self.tr( "Buffer region" ) ) self.lineEdit.setSuffix(" %") self.lineEdit.setRange(0, 100) self.lineEdit.setSingleStep(5) self.lineEdit.setValue(0) elif self.myFunction == 11: #Lines to polygons self.setWindowTitle( self.tr( "Lines to polygons" ) ) self.label_2.setText( self.tr( "Output shapefile" ) ) self.label_3.setText( self.tr( "Input line vector layer" ) ) self.label.setVisible(False) self.lineEdit.setVisible(False) self.cmbField.setVisible(False) self.field_label.setVisible(False) else: # Polygon from layer extent self.setWindowTitle( self.tr( "Polygon from layer extent" ) ) self.label_3.setText( self.tr( "Input layer" ) ) self.label.setVisible( False ) self.lineEdit.setVisible( False ) self.label_2.setText( self.tr( "Output polygon shapefile" ) ) self.cmbField.setVisible( False ) self.field_label.setVisible( False ) self.resize( 381, 100 ) myList = [] self.inShape.clear() if self.myFunction == 3 or self.myFunction == 6: myList = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] ) elif self.myFunction == 4 or self.myFunction == 7: myList = ftools_utils.getLayerNames( [ QGis.Polygon ] ) elif self.myFunction == 8 or self.myFunction == 10: myList = ftools_utils.getLayerNames( [ QGis.Point ] ) elif self.myFunction == 9: myList = ftools_utils.getLayerNames( "all" ) elif self.myFunction == 11: myList = ftools_utils.getLayerNames( [ QGis.Line ] ) else: myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] ) self.inShape.addItems( myList ) return