Пример #1
0
    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()
Пример #2
0
    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()
Пример #3
0
    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()
Пример #4
0
    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()
Пример #5
0
    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()