def show(self): allLayerNames = getAllLayerName(self.iface) (layerName, ok) = QInputDialog.getItem(self.parent, u'导出数据', u'选择要导出的数据图层', allLayerNames) if ok and (layerName != None and layerName != ''): layer = getLayerByName(layerName, self.iface) saveFileName = QFileDialog.getSaveFileName(self.parent, u"导出数据", '/', 'Excel File (*.xls)') if saveFileName.strip() != "": exportData = ExportData(self.iface, self.parent) if exportData.exportDataToExcel(layer, saveFileName): QMessageBox.information(self.parent, u"导出数据", u"导出数据成功!") else: QMessageBox.critical(self.parent, u"导出数据", u"导出数据失败!")
def __init__(self, iface, parent=None): super(AddNSitesUI, self).__init__() self.iface = iface self.parent = parent # 判断是否存在泰森结点图层 if u"泰森结点" not in getAllLayerName(self.iface): self.accept() QMessageBox.critical(self.parent, u"错误", u"请先执行自动规划基站功能!") return False # 判断是否选中正确图层 self.layer = self.iface.activeLayer() if self.layer.name() != u"泰森结点": self.accept() QMessageBox.critical(self.parent, u"错误", u"请选择泰森结点图层!") return False self.result_layer = getLayerByName(u"规划基站结果", self.iface) if not self.result_layer: self.accept() QMessageBox.critical(self.parent, u"错误", u"找不到规划基站结果!") return False self.initUI()
def __init__(self, iface, parent=None): super(RangeByStrSettingUI, self).__init__() self.iface = iface self.parent = parent self.iface.mapCanvas().currentLayerChanged[QgsMapLayer].connect(self.LayerChanged) self.color_btn_list = [] # 保存各范围所设置的颜色按钮 self.delete_btn_list = [] # 保存各范围所设置的删除按钮 self.value_widget_list = [] self.setting_list = [] # 保存参数设置 self.setWindowTitle(u"分类显示") layer_label = QLabel(u"选择图层:") self.layer_combo = QComboBox() layers_name = getAllLayerName(self.iface) self.layer_combo.addItems(layers_name) self.layer = getLayerByName(self.layer_combo.currentText(), self.iface) self.connect(self.layer_combo, SIGNAL('currentIndexChanged(int)'), self.layerListener) field_label = QLabel(u"选择字段:") self.field_combo = QComboBox() if self.layer != None: fields_list = [] for field in self.layer.pendingFields(): fields_list.append(field.name().strip()) self.field_combo.addItems(fields_list) ok = QPushButton(u"确定") cancel = QPushButton(u"取消") self.connect(ok, SIGNAL('clicked()'), self.run) self.connect(cancel, SIGNAL('clicked()'), self.accept) # 选择图层、字段Widget source_grid = QGridLayout() source_grid.setSpacing(10) source_grid.addWidget(layer_label, 0, 1) source_grid.addWidget(self.layer_combo, 0, 2) source_grid.addWidget(field_label, 1, 1) source_grid.addWidget(self.field_combo, 1, 2) source_widget = QWidget() source_widget.setLayout(source_grid) # 参数设置窗口(带滚动条) self.setting_Widget = QWidget() self.setting_Widget.setMinimumSize(380, 800) self.scroll_vbox = QVBoxLayout() self.scroll_vbox.setSpacing(15) self.setting_vbox = QVBoxLayout() self.setting_vbox.setSpacing(5) value_widget = self.createAValue() self.setting_vbox.addWidget(value_widget) self.add_range_btn = QPushButton(u"添加") self.connect(self.add_range_btn, SIGNAL("clicked()"), self.add_value_box) self.scroll_vbox.addLayout(self.setting_vbox) self.scroll_vbox.addWidget(self.add_range_btn) self.scroll_vbox.addStretch(1) self.setting_Widget.setLayout(self.scroll_vbox) self.scroll = QScrollArea() self.scroll.setWidget(self.setting_Widget) self.scroll.setAutoFillBackground(True) self.scroll.setWidgetResizable(True) # 确定/取消 按钮 Widget btn_hbox = QHBoxLayout() btn_hbox.setSpacing(15) btn_hbox.addStretch(1) btn_hbox.addWidget(ok) btn_hbox.addWidget(cancel) btn_hbox.addStretch(1) btn_widget = QWidget() btn_widget.setLayout(btn_hbox) vbox = QVBoxLayout() vbox.setSpacing(15) vbox.addWidget(source_widget) vbox.addWidget(self.scroll) vbox.addWidget(btn_widget) self.setLayout(vbox) self.setFixedSize(430, 500)
searchRange = (bottom_left, upper_right) # 获取搜索密度 try: density = float(self.density_text.text().strip()) except TypeError, e: QMessageBox.critical(self, u"错误", u"搜索密度填写格式不正确!") return False # 获取ak码 ak = self.ak_text.text().strip() if not ak: QMessageBox.critical(self, u"错误", u"请输入百度API密钥!") return False # 获取保存图层名 save_layer_name = self.getSaveName() # 检查是否为空 if not save_layer_name: QMessageBox.critical(self, u"错误", u"请输入输出图层名称!") return False exist_layer_names = getAllLayerName(self.iface) if save_layer_name in exist_layer_names: QMessageBox.critical(self, u"错误", u"所输入的输出图层名称已存在!") return False selectedLayer = self.iface.activeLayer() self.accept() # 判断搜索模式是自定义矩形还是所选中的polygon searchType = self.getSearchType(searchRange) search = SearchPOIFromBaidu(self.iface, keywords_list, searchRange, searchType, selectedLayer, density, save_layer_name, ak, self.parent) search.run()