class NetworkXDialogBuild(QtGui.QDialog, ShapeLayersToCombo, WriteNetworkShapefiles): '''Class to convert shapefiles to NetworkX format edges.shp and nodes.shp''' def __init__(self): QtGui.QDialog.__init__(self) self.ui = Ui_NetworkXBuild() self.ui.setupUi(self) self.iface = qgis.utils.iface QtCore.QObject.connect(self.ui.btnOK,QtCore.SIGNAL("clicked()"), self.buildNetwork) QtCore.QObject.connect(self.ui.btnCancel,QtCore.SIGNAL( "clicked()"),self.exit) QtCore.QObject.connect(self.ui.btnSave, QtCore.SIGNAL( "clicked()"),self.output_file) self.filelist = ["Available layers:"] self.ui.comboBoxInput.addItem(self.filelist[0]) ShapeLayersToCombo(self.ui.comboBoxInput, self.filelist, 1) def output_file(self): '''Get output directory from Qt file dialog.''' try: self.fd = str(QtGui.QFileDialog.getExistingDirectory(self, "Select Output Directory")) self.ui.lineEditSave.insert(self.fd) except IOError as e: self.ui.lineEditSave.clear() QtGui.QMessageBox.warning( self.iface.mainWindow(), "NetworkX Plugin Error", "%s" % str(e)) def buildNetwork(self): '''Method to create NetworkX nodes and edges shapefiles.''' try: layer = str(self.filelist[self.ui.comboBoxInput.currentIndex()]) if layer == "Available layers:": raise IOError, "Please specify input shapefile layer." DG1 = nx.read_shp(layer) if str(self.ui.lineEditSave.text()) == '': raise IOError, "No output directory specified." WriteNetworkShapefiles(DG1, self.fd, overwrite=True) #self.writeNetworkShapefiles(DG1) if self.ui.checkBoxAdd.isChecked(): # Get created files nodes = self.fd+"/nodes.shp" edges = self.fd+"/edges.shp" # Add to QGIS instance qgis.utils.iface.addVectorLayer(edges, "Network Edges", "ogr") qgis.utils.iface.addVectorLayer(nodes, "Network Nodes", "ogr") self.close() except (AttributeError, IOError) as e: QtGui.QMessageBox.warning( self, "NetworkX Plugin Error", "%s" % e) def exit(self): '''Method to close plugin window.''' self.close()
def __init__(self): QtGui.QDialog.__init__(self) self.ui = Ui_NetworkXBuild() self.ui.setupUi(self) self.iface = qgis.utils.iface QtCore.QObject.connect(self.ui.btnOK, QtCore.SIGNAL("clicked()"), self.buildNetwork) QtCore.QObject.connect(self.ui.btnCancel, QtCore.SIGNAL("clicked()"), self.exit) QtCore.QObject.connect(self.ui.btnSave, QtCore.SIGNAL("clicked()"), self.output_file) self.filelist = ["Available layers:"] self.ui.comboBoxInput.addItem(self.filelist[0]) ShapeLayersToCombo(self.ui.comboBoxInput, self.filelist, 1)
def __init__(self): QtGui.QDialog.__init__(self) self.ui = Ui_NetworkXBuild() self.ui.setupUi(self) self.iface = qgis.utils.iface QtCore.QObject.connect(self.ui.btnOK,QtCore.SIGNAL("clicked()"), self.buildNetwork) QtCore.QObject.connect(self.ui.btnCancel,QtCore.SIGNAL( "clicked()"),self.exit) QtCore.QObject.connect(self.ui.btnSave, QtCore.SIGNAL( "clicked()"),self.output_file) self.filelist = ["Available layers:"] self.ui.comboBoxInput.addItem(self.filelist[0]) ShapeLayersToCombo(self.ui.comboBoxInput, self.filelist, 1)
class NetworkXDialogBuild(QtGui.QDialog, ShapeLayersToCombo, WriteNetworkShapefiles): '''Class to convert shapefiles to NetworkX format edges.shp and nodes.shp''' def __init__(self): QtGui.QDialog.__init__(self) self.ui = Ui_NetworkXBuild() self.ui.setupUi(self) self.iface = qgis.utils.iface QtCore.QObject.connect(self.ui.btnOK, QtCore.SIGNAL("clicked()"), self.buildNetwork) QtCore.QObject.connect(self.ui.btnCancel, QtCore.SIGNAL("clicked()"), self.exit) QtCore.QObject.connect(self.ui.btnSave, QtCore.SIGNAL("clicked()"), self.output_file) self.filelist = ["Available layers:"] self.ui.comboBoxInput.addItem(self.filelist[0]) ShapeLayersToCombo(self.ui.comboBoxInput, self.filelist, 1) def output_file(self): '''Get output directory from Qt file dialog.''' try: self.fd = str( QtGui.QFileDialog.getExistingDirectory( self, "Select Output Directory")) self.ui.lineEditSave.insert(self.fd) except IOError as e: self.ui.lineEditSave.clear() QtGui.QMessageBox.warning(self.iface.mainWindow(), "NetworkX Plugin Error", "%s" % str(e)) def buildNetwork(self): '''Method to create NetworkX nodes and edges shapefiles.''' try: layer = str(self.filelist[self.ui.comboBoxInput.currentIndex()]) if layer == "Available layers:": raise IOError, "Please specify input shapefile layer." DG1 = nx.read_shp(layer) if str(self.ui.lineEditSave.text()) == '': raise IOError, "No output directory specified." WriteNetworkShapefiles(DG1, self.fd, overwrite=True) #self.writeNetworkShapefiles(DG1) if self.ui.checkBoxAdd.isChecked(): # Get created files nodes = self.fd + "/nodes.shp" edges = self.fd + "/edges.shp" # Add to QGIS instance qgis.utils.iface.addVectorLayer(edges, "Network Edges", "ogr") qgis.utils.iface.addVectorLayer(nodes, "Network Nodes", "ogr") self.close() except (AttributeError, IOError) as e: QtGui.QMessageBox.warning(self, "NetworkX Plugin Error", "%s" % e) def exit(self): '''Method to close plugin window.''' self.close()