def importSCellData(self): try: # 导入相邻小区数据 features = [] total = len(self.data_list) progess = Progess(self.parent, total, u"数据导入中") progess.show() for itm in self.data_list: feat = createASCellFeature(itm) if feat == False: progess.kill() break else: features.append(feat) progess.count() scellLayer = getLayerByName(u"相邻小区", self.iface) res = importFeaturesToLayer(scellLayer, features) if res is False: scellLayer.destroyEditCommand() return False else: scellLayer.endEditCommand() # 事务提交 return True except Exception: raise Exception, traceback.format_exc()
def setResultLayer(self, result_list): layerName = u'规划基站结果' layerType = QGis.WKBPoint project_dir = getProjectDir(self.iface) # 先判断是否已存在规划基站结果图层 result_layer = getLayerByName(layerName, self.iface) if result_layer: #清空数据 delAllFeatures(result_layer) else: # 删除原有图层文件 deleteShapefile(project_dir, layerName) shapPath = os.path.join(project_dir, layerName + u".shp") # 生成图层 fileds = self.createFields() # 创建出Shap文件 # 数据源编码模式为GBK2312(否则中文字段会乱码) wr = QgsVectorFileWriter(shapPath, "GBK2312", fileds, layerType, None, "ESRI Shapefile") # 如果保存的时候没有错误 if wr.hasError() == QgsVectorFileWriter.NoError: pass else: print wr.hasError() raise Exception, wr.errorMessage() # 发生错误,抛出异常交给外面的方法处理异常 del wr # 使添加的字段生效 result_layer = QgsVectorLayer(shapPath, layerName, 'ogr') QgsMapLayerRegistry.instance().addMapLayer(result_layer) # 添加数据 features_list = [] for result in result_list: feature = createABasicPointFeature(QgsPoint(float(result[1]),float(result[2])), result) features_list.append(feature) importFeaturesToLayer(result_layer, features_list) # 合并站点 mergeNSite = OptimizateNewSite(result_layer, self.parent) if mergeNSite.run(): QMessageBox.information(self.parent, u"自动规划基站", u"自动规划基站成功!") else: QMessageBox.critical(self.parent, u"自动规划基站", u"自动规划基站失败!")
def run(self): d = QgsDistanceArea() self.jlist = self.getNewSites() maxDistance = self.tlist[1] # 最大搜索范围 feature_list = [] existed_name_list = self.getResultNodesNames() for (jindex, jsite) in enumerate(self.jlist): # 遍历结点 perList = [] # 临时列表,用于转化子字典 jnaminDis1, jnaminDis2, jnaminDis3, jnaminDis4, jnaminDis5, jnaminDis6 = [ self.tlist[1] for i in range(6) ] asite1, asite2, asite3, asite4, asite5, asite6 = [ None for i in range(6) ] if jsite[7] == u'农村': minDis = float(self.tlist[2]) elif jsite[7] == u'郊区乡镇': minDis = float(self.tlist[3]) elif jsite[7] == u'密集市区': minDis = float(self.tlist[5]) else: # 区域类型的结点的最小辐射范围 # 默认jsite[7]==u'普通市区' minDis = float(self.tlist[4]) jpoint = jsite.geometry().asPoint() # 先找到结点附近设置搜索范围内的所有基站 area = createARectangleByCenterPoint(jpoint, maxDistance) siteFeatures_list = getFeaturesListByArea(self.siteLayer, area) for asite in siteFeatures_list: # #遍历找到的基站 jnaDis = d.convertMeasurement(d.measureLine(jpoint, \ QgsPoint(asite[4], asite[5])), 2, 0, False)[0] jnaAngle = math.atan2(asite[5] - jpoint.y(), asite[4] - jpoint.x()) jnaAngle = 90.0 - 180 / math.pi * jnaAngle # 弧度转角度(90-方位角,可转为以正北为0度角) if jnaDis <= jnaminDis1 and 0 < jnaAngle <= 60: jnaminDis1 = float('%0.4f' % jnaDis) # 保留四位小数 asite1 = asite elif jnaDis <= jnaminDis2 and 60 < jnaAngle <= 120: jnaminDis2 = float('%0.4f' % jnaDis) # 保留四位小数 asite2 = asite elif jnaDis <= jnaminDis3 and 120 < jnaAngle <= 180: jnaminDis3 = float('%0.4f' % jnaDis) # 保留四位小数 asite3 = asite elif jnaDis <= jnaminDis4 and -180 < jnaAngle <= -120: jnaminDis4 = float('%0.4f' % jnaDis) # 保留四位小数 asite4 = asite elif jnaDis <= jnaminDis5 and -120 < jnaAngle <= -60: jnaminDis5 = float('%0.4f' % jnaDis) # 保留四位小数 asite5 = asite elif jnaDis <= jnaminDis6 and -60 < jnaAngle <= 0: jnaminDis6 = float('%0.4f' % jnaDis) # 保留四位小数 asite6 = asite if jnaminDis1 and asite1: perList.append([jnaminDis1, asite1]) if jnaminDis2 and asite2: perList.append([jnaminDis2, asite2]) if jnaminDis3 and asite3: perList.append([jnaminDis3, asite3]) if jnaminDis4 and asite4: perList.append([jnaminDis4, asite4]) if jnaminDis5 and asite5: perList.append([jnaminDis5, asite5]) if jnaminDis6 and asite6: perList.append([jnaminDis6, asite6]) # 判断是否至少找到一个符合的基站 if len(perList) < 6: for i in range(6 - len(perList)): perList.append(None) # 若数量不足,给列表补None值 NewSiteName = "0" while True: if NewSiteName in existed_name_list: NewSiteName = str(int(NewSiteName) + 1) else: existed_name_list.append(NewSiteName) break tempList1 = [ NewSiteName, str(jpoint.x()), str(jpoint.y()), jsite[7] ] tempList2 = [] tolDistance = 0 suit_site_dict = { } # 用于记录符合基站的基站名和距离 (key: SiteName, value: distance) for L in perList: if isinstance(L, list): # 判断是否为列表类型 tolDistance = tolDistance + L[0] psite = L[1] tempList2.append(psite[2]) # 基站名 tempList2.append(str(L[0])) # 距离 tempList2.append(str(psite[4])) # 经度 tempList2.append(str(psite[5])) # 纬度 suit_site_dict[psite[2]] = L[0] else: tempList2.append('NULL') tempList2.append('NULL') # 没有基站,设为None值 tempList2.append('NULL') tempList2.append('NULL') if ((tolDistance != 0) and (len(suit_site_dict) != 0)): avgDistance = ("%.4f" % (tolDistance / len(suit_site_dict))) # 将符合要求的站点按距离从小到大排序 sorted_list = sorted(suit_site_dict.iteritems(), key=lambda d: d[1], reverse=False) # tempList1后追加最近基站名称,最近基站距离,平均距离 tempList1.extend([ sorted_list[0][0], str(sorted_list[0][1]), str(avgDistance) ]) else: # tempList1后追加最近基站名称,最近基站距离,平均距离 tempList1.extend(["NULL", "NULL", "0"]) NewSite_datas = (tempList1 + tempList2) feature_list.append(createABasicPointFeature( jpoint, NewSite_datas)) if importFeaturesToLayer(self.nsiteLayer, feature_list): self.iface.actionDraw().trigger() return True else: return False
def importSiteAndCellData(self): cell_features = [] site_features = [] site_dict = {} try: # 先生成小区feature再生成基站feature for itm in self.data_list: # 创建小区feature # 当有小区ID和小区名时才导入信息 cell_id = itm[2] cell_name = itm[3] if cell_id and cell_name: cell = [] for (index, i) in enumerate(itm): # 小区表中没有站点地址(48)和基站ID2(51) if index not in [48, 51]: cell.append(i) # 获取小区图形设置\ setting = self.getCellGraphicParam() if not setting: return # 处理小区图形参数 if setting["type"] == 0: # 按运营商 operator = itm[18] if operator == u'移动': angle = setting[u"移动"][0] length = setting[u"移动"][1] elif operator == u'联通': angle = setting[u"联通"][0] length = setting[u"联通"][1] elif operator == u'电信': angle = setting[u"电信"][0] length = setting[u"电信"][1] else: angle = setting[u"铁塔"][0] length = setting[u"铁塔"][1] else: # 自定义 system = itm[10] frequency = itm[12] # 获取默认设置 angle = self.setting[u"默认"][0] length = self.setting[u"默认"][1] # 获取分类 case_list = self.setting["case_list"] for (c_system, c_frequency, c_angle, c_length) in case_list: if c_system and (not c_frequency): if system == c_system: angle = c_angle length = c_length elif (not c_system) and c_frequency: if frequency == c_frequency: angle = c_angle length = c_length elif c_system and c_frequency: if (system == c_system) and (frequency == c_frequency): angle = c_angle length = c_length # 根据小区类型生成相应的geometry if itm[5] == u"室分": circle = createCircle(QgsPoint(float(itm[8]), float(itm[9])), length / 2, self.iface, True, 64) cell_feat = createACellFeature(circle, cell) cell_features.append(cell_feat) else: sector = createSector(QgsPoint(float(itm[8]), float(itm[9])), length, self.iface, True, itm[7], angle) cell_feat = createACellFeature(sector, cell) cell_features.append(cell_feat) # 创建基站feature site = [ itm[0], # 基站ID itm[1], # 基站名 itm[6], # RNC-BSC itm[8], # 经度 itm[9], # 纬度 itm[10], # 网络制式 itm[11], # 典型环境 itm[17], # 区域 itm[18], # 运营商 itm[19], # 簇 itm[20], # 基站英文名 itm[22], # 基站类型 itm[48], # 站点地址 itm[49], # MCC itm[50], # MNC itm[51], # 基站ID2 itm[52], # 话务量 itm[53], # 投诉量 itm[54], # Polygon itm[55] # 其他 ] site_id = itm[0] site_name = itm[1] rnc_bsc = itm[6] lon = itm[8] lat = itm[9] site_key = (site_id, site_name, rnc_bsc, lon, lat) if site_dict.has_key(site_key): continue else: site_dict[site_key] = True site_feat = createASiteFeature(QgsPoint(float(itm[8]), float(itm[9])), site) site_features.append(site_feat) # 导入数据 siteLayer = getLayerByName(u"基站",self.iface) site_result = importFeaturesToLayer(siteLayer, site_features) cellLayer = getLayerByName(u"小区", self.iface) cell_result = importFeaturesToLayer(cellLayer, cell_features) if (site_result is False) or (cell_result is False): siteLayer.destroyEditCommand() cellLayer.destroyEditCommand() return False else: siteLayer.endEditCommand() cellLayer.endEditCommand() return True except Exception: raise Exception, traceback.format_exc()
def createLayer(self, datas): layerName = self.save_layer_name # 图层名称 layerType = QGis.WKBPoint # 图层类型 shapPath = os.path.join(getProjectDir(self.iface), layerName + u".shp") # 创建图层字段 field_names = [u"名称", u"类别", u"地址", u"经度", u"纬度"] field_types = [ QVariant.String, QVariant.String, QVariant.String, QVariant.Double, QVariant.Double ] field_lengs = [50, 50, 100, 20, 20] field_precs = [0, 0, 0, 7, 7] fields = QgsFields() for (i, itm) in enumerate(field_names): cuType = field_types[i] if cuType == QVariant.Int: mtype = 'Integer' elif cuType == QVariant.Double: mtype = 'Real' else: mtype = 'String' field = QgsField(itm, cuType, mtype, field_lengs[i], field_precs[i]) fields.append(field) # 创建出Shap文件 # 数据源编码模式为GBK2312(否则中文字段会乱码) wr = QgsVectorFileWriter(shapPath, "GBK2312", fields, layerType, None, "ESRI Shapefile") # 如果保存的时候没有错误 if wr.hasError() == QgsVectorFileWriter.NoError: pass else: print wr.hasError() raise Exception, wr.errorMessage() # 发生错误,抛出异常交给外面的方法处理异常 del wr # 使添加的字段生效 layer = QgsVectorLayer(shapPath, layerName, 'ogr') # 新生成的搜索结果图层 QgsMapLayerRegistry.instance().addMapLayer(layer) # 更新图层 self.iface.actionDraw().trigger() # 写入数据 features_list = [] selected_polygons = [] for polygon in self.selectedLayer.selectedFeatures(): selected_polygons.append(polygon) for data in datas: feature = createABasicPointFeature( QgsPoint(float(data[3]), float(data[4])), data) point_gemo = feature.geometry() if self.searchType == 0: for polygon in selected_polygons: if point_gemo.intersects(polygon.geometry()): features_list.append(feature) break else: features_list.append(feature) # 把新建的features导入图层 result = importFeaturesToLayer(layer, features_list) if result: # 更新图层 self.iface.actionDraw().trigger() return layer else: return None
def NewAngle(self): # 获取小区大小和长度设置 setting = getCellGraphicParam(self.iface) # 判断是否读取到参数设置 if not setting: QMessageBox.critical(self, u"错误", u"无法获取小区图形参数设置") return newangle = self.titleEdit.text().strip() selection = self.cellLayer.selectedFeatures() ilist = [] cellfeatures = [] # 判断是否填入了角度 if not newangle: QMessageBox.critical(self, u"提醒", u"请输入数值!") return False # 判断是否选中了要修改的小区 if len(selection) == 0: QMessageBox.critical(self, u"错误", u"<b>请选择要修改的小区<\b>!") return False # 根据输入值创建新的扇区feature for f in selection: ilist.append(f.id()) cellAttrs = f.attributes() del cellAttrs[0] cellAttrs[7] = int(newangle) operator = cellAttrs[18] # 识别图形设置 if setting["type"] == 0: if operator == u'移动': szAngle = setting[u"移动"][0] szLength = setting[u"移动"][1] elif operator == u'联通': szAngle = setting[u"联通"][0] szLength = setting[u"联通"][1] elif operator == u'电信': szAngle = setting[u"电信"][0] szLength = setting[u"电信"][1] else: szAngle = setting[u"铁塔"][0] szLength = setting[u"铁塔"][1] else: # 自定义 system = cellAttrs[10] frequency = cellAttrs[12] # 获取默认设置 szAngle = setting[u"默认"][0] szLength = setting[u"默认"][1] # 获取分类 case_list = setting["case_list"] for (c_system, c_frequency, c_angle, c_length) in case_list: if c_system and (not c_frequency): if system == c_system: szAngle = c_angle szLength = c_length elif (not c_system) and c_frequency: if frequency == c_frequency: szAngle = c_angle szLength = c_length elif c_system and c_frequency: if (system == c_system) and (frequency == c_frequency): szAngle = c_angle szLength = c_length # 生成小区扇形geometry cellGeometry = createSector( QgsPoint(float(cellAttrs[8]), float(cellAttrs[9])), szLength, self.iface, True, cellAttrs[7], szAngle) cellFeature = createACellFeature(cellGeometry, cellAttrs) cellfeatures.append(cellFeature) break else: QMessageBox.critical(self, u"提醒", u"请选择至少一个扇区!") return False button = QMessageBox.question(self, "Question", u"修改后将无法撤回,是否继续?", QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Ok) if button == QMessageBox.Ok: # 删除原角度扇区feature delRessult = delFeatures(self.cellLayer, ilist) if delRessult: impResult = importFeaturesToLayer(self.cellLayer, cellfeatures) if impResult: QMessageBox.information(self, u"修改小区方向角", u"修改小区方向角成功!") else: QMessageBox.critical(self, u"修改小区方向角", u"修改小区方向角失败!") self.close() return else: QMessageBox.critical(self, u"修改小区方向角", u"修改小区方向角失败!") self.close() return self.iface.actionDraw().trigger() else: return False self.accept()
def add(self): # 获取并处理填写的信息 site_id = self.site_id.text().strip() # 基站ID(新建基站ID前自动添加N) site_name = self.site_name.text().strip() # 基站名字 rnc_bsc = self.rnc_bsc.text().strip() # RNC-BSC operator = self.operator.currentText().strip() # 运营商 region = self.region.currentText().strip() # 区域类型 system = self.system.currentText().strip() # 网络制式 frequency = self.frequency.currentText().strip() # 频段 system_flag = u"W" # 默认 W if system == u"900": system_flag = u"G" elif system == u"1800": system_flag = u"D" elif system == u"CDMA": system_flag = u"C" elif system == u"WCDMA": system_flag = u"W" elif system == u"TD-LTE": system_flag = u"T" elif system == u"FDD-LTE": system_flag = u"F" elif system == u"TDSCDMA": system_flag = u"TDS" lon = self.lon.text().strip() # 经度 lat = self.lat.text().strip() # 纬度 azimuth_1 = self.azimuth_1.text().strip() tilt_1 = self.tilt_1.text().strip() etilt_1 = self.etilt_1.text().strip() mtilt_1 = self.mtilt_1.text().strip() azimuth_2 = self.azimuth_2.text().strip() tilt_2 = self.tilt_2.text().strip() etilt_2 = self.etilt_2.text().strip() mtilt_2 = self.mtilt_2.text().strip() azimuth_3 = self.azimuth_3.text().strip() tilt_3 = self.tilt_3.text().strip() etilt_3 = self.etilt_3.text().strip() mtilt_3 = self.mtilt_3.text().strip() azimuth_4 = self.azimuth_4.text().strip() tilt_4 = self.tilt_4.text().strip() etilt_4 = self.etilt_4.text().strip() mtilt_4 = self.mtilt_4.text().strip() # 判断必填项是否已填 if site_name == "": QMessageBox.critical(self, u"提示", u"请填写基站名字!") return False if site_id == "": QMessageBox.critical(self, u"提示", u"请填写基站ID!") return False if rnc_bsc == "": # 赋值随机数 rnc_bsc = str(random.randint(1, 9999)) if (lon == "") or (lat == ""): QMessageBox.critical(self, u"提示", u"请填写经纬度,或通过点击画布选择坐标!") return False # 先添加基站 # 检查ID和名字是否重复 self.sitelayer = getLayerByName(u'基站', self.iface) # 基站图层 allsite = self.sitelayer.getFeatures() for site in allsite: if site_name == site[u'基站名']: QMessageBox.critical(self, u"提示", u"所填写的基站名与项目中的数据有重复,请更改!") return False if site_id == site[u'基站ID']: QMessageBox.critical(self, u"提示", u"所填写的基站ID与项目中的数据有重复,请更改!") return False siteFeatureAttrs = ['NULL'] * 20 siteFeatureAttrs[0] = site_id siteFeatureAttrs[1] = site_name siteFeatureAttrs[2] = rnc_bsc siteFeatureAttrs[3] = lon siteFeatureAttrs[4] = lat siteFeatureAttrs[5] = system_flag siteFeatureAttrs[6] = region siteFeatureAttrs[8] = operator # 生成基站Feature add_site_list = [] siteFeature = createASiteFeature(QgsPoint(float(lon), float(lat)), siteFeatureAttrs) add_site_list.append(siteFeature) # 判断是否需要顺带添加小区 azimuth_list = [] if azimuth_1 != "": if not tilt_1: tilt_1 = None if not etilt_1: etilt_1 = None if not mtilt_1: mtilt_1 = None azimuth_1_info = (int(azimuth_1), tilt_1, etilt_1, mtilt_1) azimuth_list.append(azimuth_1_info) if azimuth_2 != "": if not tilt_2: tilt_2 = None if not etilt_2: etilt_2 = None if not mtilt_2: mtilt_2 = None azimuth_2_info = (int(azimuth_2), tilt_2, etilt_2, mtilt_2) azimuth_list.append(azimuth_2_info) if azimuth_3 != "": if not tilt_3: tilt_3 = None if not etilt_3: etilt_3 = None if not mtilt_3: mtilt_3 = None azimuth_3_info = (int(azimuth_3), tilt_3, etilt_3, mtilt_3) azimuth_list.append(azimuth_3_info) if azimuth_4 != "": if not tilt_4: tilt_4 = None if not etilt_4: etilt_4 = None if not mtilt_4: mtilt_4 = None azimuth_4_info = (int(azimuth_4), tilt_4, etilt_4, mtilt_4) azimuth_list.append(azimuth_4_info) if len(azimuth_list) != 0: # 获取小区大小和长度设置 setting = getCellGraphicParam(self.iface) # 判断是否读取到参数设置 if not setting: QMessageBox.Critical(self.parent, u"错误", u"无法获取小区图形参数设置") return add_cell_list = [] # 要添加的小区list # 若填写了小区 for index, azimuth_info in enumerate(azimuth_list): cell_feature = ['NULL'] * 54 cell_feature[0] = site_id # 基站ID cell_feature[1] = site_name # 所属基站名字 cell_id = u"%s%s" % (site_id, str(index + 1)) # 小区ID cell_feature[2] = cell_id # 小区ID cell_name = u"%s-%s" % (site_name, str(index + 1)) # # 小区名字 cell_feature[3] = cell_name cell_feature[4] = index # Sector ID cell_feature[6] = rnc_bsc cell_feature[7] = azimuth_info[0] # Azimuth cell_feature[8] = lon cell_feature[9] = lat cell_feature[10] = system_flag cell_feature[11] = region # 典型环境 cell_feature[12] = frequency # 频段 cell_feature[13] = azimuth_info[1] cell_feature[14] = azimuth_info[2] cell_feature[15] = azimuth_info[3] cell_feature[18] = operator # 识别图形设置 if setting["type"] == 0: if operator == u'移动': szAngle = setting[u"移动"][0] szLength = setting[u"移动"][1] elif operator == u'联通': szAngle = setting[u"联通"][0] szLength = setting[u"联通"][1] elif operator == u'电信': szAngle = setting[u"电信"][0] szLength = setting[u"电信"][1] elif operator == u'铁塔': szAngle = setting[u"铁塔"][0] szLength = setting[u"铁塔"][1] else: # 自定义 system = cell_feature[10] frequency = cell_feature[12] # 获取默认设置 szAngle = setting[u"默认"][0] szLength = setting[u"默认"][1] # 获取分类 case_list = setting["case_list"] for (c_system, c_frequency, c_angle, c_length) in case_list: if c_system and (not c_frequency): if system == c_system: szAngle = c_angle szLength = c_length elif (not c_system) and c_frequency: if frequency == c_frequency: szAngle = c_angle szLength = c_length elif c_system and c_frequency: if (system == c_system) and (frequency == c_frequency): szAngle = c_angle szLength = c_length # 生成小区扇形geometry cellGeometry = createSector(QgsPoint(float(lon), float(lat)), szLength, self.iface, True, cell_feature[7], szAngle) # 判断小区名字和小区ID是否已于现有数据中 self.celllayer = getLayerByName(u'小区', self.iface) # 小区图层 # 检查是否已勾选了小图特曾 if not self.celllayer: QMessageBox.critical(self.parent, u"错误", u"没有找到小区图层!") return False allcell = self.celllayer.getFeatures() for cell in allcell: if cell_name == cell[u'小区名']: QMessageBox.critical( self.parent, u"提示", u"生成的小区名: " + cell_name + u" 与项目中的数据有重复,请更改!") return False if cell_id == cell[u"小区ID"]: QMessageBox.critical( self.parent, u"提示", u"生成的小区ID: " + cell_id + u" 与项目中的数据有重复,请更改!") return False # 生成小区feature并添加到list中 cell = createACellFeature(cellGeometry, cell_feature) add_cell_list.append(cell) button = QMessageBox.question(self, "Question", u"添加后将无法撤回,是否继续?", QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Ok) if button == QMessageBox.Ok: # 向图层中导入新增的数据 if len(add_site_list) != 0: siteLayer = getLayerByName(u"基站", self.iface) result1 = importFeaturesToLayer(siteLayer, add_site_list) if len(add_cell_list) != 0 and result1: cellLayer = getLayerByName(u"小区", self.iface) result2 = importFeaturesToLayer(cellLayer, add_cell_list) if not result2: QMessageBox.critical(self, u"添加基站", u"添加基站数据失败!") self.accept() return elif not result1: QMessageBox.critical(self, u"添加基站", u"添加基站数据失败!") self.accept() return self.iface.actionDraw().trigger() # 刷新地图 else: return if result1 or result2: QMessageBox.information(self, u"添加基站", u"添加基站数据成功!") self.accept()
def add(self): # 获取并处理填写的信息 site_id = self.site_id.text().strip() # 基站ID(新建基站ID前自动添加N) site_name = self.site_name.text().strip() # 基站名字 rnc_bsc = self.rnc_bsc.text().strip() # RNC-BSC operator = self.operator.currentText().strip() # 运营商 region = self.region.currentText().strip() # 区域类型 lon = self.lon.text().strip() # 经度 lat = self.lat.text().strip() # 纬度 system = self.system.currentText().strip() # 网络制式 system_flag = u"W" # 默认 W if system == u"900": system_flag = u"G" elif system == u"1800": system_flag = u"D" elif system == u"CDMA": system_flag = u"C" elif system == u"WCDMA": system_flag = u"W" elif system == u"TD-LTE": system_flag = u"T" elif system == u"FDD-LTE": system_flag = u"F" elif system == u"TDSCDMA": system_flag = u"TDS" frequency = self.frequency.currentText().strip() # 频段 azimuth_1 = self.azimuth_1.text().strip() tilt_1 = self.tilt_1.text().strip() etilt_1 = self.etilt_1.text().strip() mtilt_1 = self.mtilt_1.text().strip() azimuth_2 = self.azimuth_2.text().strip() tilt_2 = self.tilt_2.text().strip() etilt_2 = self.etilt_2.text().strip() mtilt_2 = self.mtilt_2.text().strip() azimuth_3 = self.azimuth_3.text().strip() tilt_3 = self.tilt_3.text().strip() etilt_3 = self.etilt_3.text().strip() mtilt_3 = self.mtilt_3.text().strip() azimuth_4 = self.azimuth_4.text().strip() tilt_4 = self.tilt_4.text().strip() etilt_4 = self.etilt_4.text().strip() mtilt_4 = self.mtilt_4.text().strip() # 判断必填项是否已填 if site_name == "": QMessageBox.critical(self, u"提示", u"请填写基站名字!") return False if site_id == "": QMessageBox.critical(self, u"提示", u"请填写基站ID!") return False if rnc_bsc == "": # 赋值随机数 rnc_bsc = range(1, 9999) if (lon == "") or (lat == ""): QMessageBox.critical(self, u"提示", u"请填写经纬度,或通过点击画布选择坐标!") return False # 获取填写的小区信息 azimuth_list = [] if azimuth_1 != "": if not tilt_1: tilt_1 = None if not etilt_1: etilt_1 = None if not mtilt_1: mtilt_1 = None azimuth_1_info = (int(azimuth_1), tilt_1, etilt_1, mtilt_1) azimuth_list.append(azimuth_1_info) if azimuth_2 != "": if not tilt_2: tilt_2 = None if not etilt_2: etilt_2 = None if not mtilt_2: mtilt_2 = None azimuth_2_info = (int(azimuth_2), tilt_2, etilt_2, mtilt_2) azimuth_list.append(azimuth_2_info) if azimuth_3 != "": if not tilt_3: tilt_3 = None if not etilt_3: etilt_3 = None if not mtilt_3: mtilt_3 = None azimuth_3_info = (int(azimuth_3), tilt_3, etilt_3, mtilt_3) azimuth_list.append(azimuth_3_info) if azimuth_4 != "": if not tilt_4: tilt_4 = None if not etilt_4: etilt_4 = None if not mtilt_4: mtilt_4 = None azimuth_4_info = (int(azimuth_4), tilt_4, etilt_4, mtilt_4) azimuth_list.append(azimuth_4_info) # 如果添加的小区没有填写的话则提示错误 if len(azimuth_list) == 0: QMessageBox.critical(self, u"提示", u"请填写要添加的小区角度!") return False # 获取小区大小和长度设置 setting = getCellGraphicParam(self.iface) # 判断是否读取到参数设置 if not setting: QMessageBox.critical(self, u"错误", u"无法获取小区图形参数设置") return # 在小区表中寻找已有的小区信息 existing_cell_list = getCellListBySite(self.iface, site_id, rnc_bsc, operator) # 判断是否该基站还能够添加小区(最多九个) if len(existing_cell_list) + len(azimuth_list) > 9: QMessageBox.critical( self, u"提示", u"所设置的基站已有" + str(len(existing_cell_list)) + u"个小区, 最多只能再添加" + str(9 - len(existing_cell_list)) + u"个小区") return False else: existing_cell_id_list = [] existing_cell_name_list = [] existing_cell_sectorId_list = [] for existing_cell in existing_cell_list: existing_cell_id_list.append(existing_cell[u'小区ID']) existing_cell_name_list.append(existing_cell[u'小区名']) existing_cell_sectorId_list.append(existing_cell[u"扇区ID"]) if len(azimuth_list) != 0: # 生成要添加的小区feature add_cell_list = [] add_cell_id_list = [] add_cell_name_list = [] for index, azimuth_info in enumerate(azimuth_list): cell_feature = ['NULL'] * 54 cell_id = u"%s%s" % (site_id, str(index + 1)) # 小区ID # 判断 cell_id 是否会与现存的冲突,若冲突则自动改变 cel_id 命名 while (cell_id in existing_cell_id_list) or (cell_id in add_cell_id_list): cell_id = list(cell_id) cell_id[-1] = str(int(cell_id[-1]) + 1) if int(cell_id[-1]) > 9: QMessageBox.critical(self, u"错误", u"生成的小区ID与现有的信息冲突") return False else: temp = ''.join(cell_id) del temp cell_feature[2] = cell_id # 小区ID # 分配 Sector Id sector_id_range = [i for i in range(0, 9)] # 取值范围为0~8 for sector_id in sector_id_range: if sector_id not in existing_cell_sectorId_list: cell_feature[4] = sector_id existing_cell_sectorId_list.append(sector_id) break cell_feature[7] = azimuth_info[0] # Azimuth cell_feature[8] = lon cell_feature[9] = lat cell_feature[0] = site_id # 基站ID cell_feature[1] = site_name # 所属基站名字 cell_feature[18] = operator cell_name = u"%s-%s" % (site_name, str(index + 1)) # # 小区名字 # 判断 cell_name 是否会与现存的冲突,若冲突则自动改变 cell_name 命名 while (cell_name in existing_cell_name_list) or (cell_id in add_cell_name_list): cell_name = list(cell_name) cell_name[-1] = str(int(cell_name[-1]) + 1) if int(cell_name[-1]) > 9: QMessageBox.critical(self, u"错误", u"生成的小区名字与现有的信息冲突") return False else: temp = ''.join(cell_name) del temp cell_feature[3] = cell_name cell_feature[11] = region # 典型环境 cell_feature[6] = rnc_bsc cell_feature[10] = system_flag # 网络制式 cell_feature[12] = frequency # 频段 cell_feature[13] = azimuth_info[1] cell_feature[14] = azimuth_info[2] cell_feature[15] = azimuth_info[3] # 识别图形设置 if setting["type"] == 0: if operator == u'移动': szAngle = setting[u"移动"][0] szLength = setting[u"移动"][1] elif operator == u'联通': szAngle = setting[u"联通"][0] szLength = setting[u"联通"][1] elif operator == u'电信': szAngle = setting[u"电信"][0] szLength = setting[u"电信"][1] elif operator == u'铁塔': szAngle = setting[u"铁塔"][0] szLength = setting[u"铁塔"][1] else: # 自定义 system = cell_feature[10] frequency = cell_feature[12] # 获取默认设置 szAngle = setting[u"默认"][0] szLength = setting[u"默认"][1] # 获取分类 case_list = setting["case_list"] for (c_system, c_frequency, c_angle, c_length) in case_list: if c_system and (not c_frequency): if system == c_system: szAngle = c_angle szLength = c_length elif (not c_system) and c_frequency: if frequency == c_frequency: szAngle = c_angle szLength = c_length elif c_system and c_frequency: if (system == c_system) and (frequency == c_frequency): szAngle = c_angle szLength = c_length #生成小区扇形geometry cellGeometry = createSector(QgsPoint(float(lon), float(lat)), szLength, self.iface, True, cell_feature[7], szAngle) # 生成小区feature并添加到list中 cell = createACellFeature(cellGeometry, cell_feature) add_cell_list.append(cell) button = QMessageBox.question(self, "Question", u"添加后将无法撤回,是否继续?", QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Ok) if button == QMessageBox.Ok: if len(add_cell_list) != 0: cellLayer = getLayerByName(u"小区", self.iface) result = importFeaturesToLayer(cellLayer, add_cell_list) if result: self.iface.actionDraw().trigger() # 刷新地图 QMessageBox.information(self, u"添加小区", u"添加小区数据成功!") else: QMessageBox.critical(self, u"添加小区", u"添加小区数据失败!") else: return False self.accept()
def moveTo(self): # 获取小区大小和长度设置 setting = getCellGraphicParam(self.iface) # 判断是否读取到参数设置 if not setting: QMessageBox.critical(self, u"错误", u"无法获取小区图形参数设置") self.accept() return oldsitelist = [] sitefeatures = [] cellfeatures = [] if len(self.selectedSiteFeatures) == 1: for f in self.selectedSiteFeatures: oldsitelist.append(f.id()) siteAttrs = f.attributes() del siteAttrs[0] siteAttrs[3] = self.lon_edit.text() siteAttrs[4] = self.lat_edit.text() self.titleEdit1.setText(unicode(siteAttrs[1])) siteFeature = createASiteFeature( QgsPoint(float(siteAttrs[3]), float(siteAttrs[4])), siteAttrs) sitefeatures.append(siteFeature) for c in self.selectedCellFeatures: cellAttrs = c.attributes() del cellAttrs[0] # 删除唯一标识符,创建新feature后会重新生成,避免重复 cellAttrs[8] = self.lon_edit.text() cellAttrs[9] = self.lat_edit.text() # 识别图形设置 operator = cellAttrs[18] if setting["type"] == 0: if operator == u'移动': szAngle = setting[u"移动"][0] szLength = setting[u"移动"][1] elif operator == u'联通': szAngle = setting[u"联通"][0] szLength = setting[u"联通"][1] elif operator == u'电信': szAngle = setting[u"电信"][0] szLength = setting[u"电信"][1] else: szAngle = setting[u"铁塔"][0] szLength = setting[u"铁塔"][1] else: # 自定义 system = cellAttrs[10] frequency = cellAttrs[12] # 获取默认设置 szAngle = setting[u"默认"][0] szLength = setting[u"默认"][1] # 获取分类 case_list = setting["case_list"] for (c_system, c_frequency, c_angle, c_length) in case_list: if c_system and (not c_frequency): if system == c_system: szAngle = c_angle szLength = c_length elif (not c_system) and c_frequency: if frequency == c_frequency: szAngle = c_angle szLength = c_length elif c_system and c_frequency: if (system == c_system) and (frequency == c_frequency): szAngle = c_angle szLength = c_length # 生成小区扇形geometry cellGeometry = createSector( QgsPoint(float(cellAttrs[8]), float(cellAttrs[9])), szLength, self.iface, True, cellAttrs[7], szAngle) cellFeature = createACellFeature(cellGeometry, cellAttrs) cellfeatures.append(cellFeature) else: QMessageBox.critical(self, u"提醒", u"需且仅需选择一个基站!") self.accept() return False button = QMessageBox.question(self, "Question", u"移动后将无法撤回,是否继续?", QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Ok) if button == QMessageBox.Ok: # 先删除旧features再往图层上添加新features delFeatures(self.sitelayer, oldsitelist) importFeaturesToLayer(self.sitelayer, sitefeatures) delFeatures(self.celllayer, self.oldcelllist) importFeaturesToLayer(self.celllayer, cellfeatures) self.iface.actionDraw().trigger() self.selectedSiteFeatures = [] self.selectedCellFeatures = [] self.sitelayer.selectAll() self.sitelayer.invertSelection() else: return False self.accept()