Beispiel #1
0
    def __init__(self, iface, parent=None):
        super(AddCellUI, self).__init__()
        self.iface = iface
        self.parent = parent
        # 获取工程所在路径
        self.project_dir = getProjectDir(self.iface)

        self.initUI()
Beispiel #2
0
 def __init__(self, iface, parnet):
     super(ModifyAzimuthUI, self).__init__()
     self.iface = iface
     self.parent = parnet
     # 获取工程所在路径
     self.project_dir = getProjectDir(self.iface)
     # 获取小区图层对象
     self.cellLayer = getLayerByName(u'小区', self.iface)
     self.initUI()
Beispiel #3
0
    def __init__(self, iface, parent=None):
        super(AddSiteUI, self).__init__()
        self.iface = iface
        self.parent = parent
        # 获取项目路径
        self.project_dir = getProjectDir(self.iface)
        # 绑定鼠标单击操作
        self.mapTool = MapTool(self.iface.mapCanvas())
        self.mapTool.canvasClicked.connect(self.mouseClicked)
        self.iface.mapCanvas().setMapTool(self.mapTool)
        self.crsXform = QgsCoordinateTransform()
        self.crsXform.setDestCRS(QgsCoordinateReferenceSystem(4326))

        self.initUI()
Beispiel #4
0
    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"自动规划基站失败!")
Beispiel #5
0
 def __init__(self, iface, parent=None):
     super(MoveSiteUI, self).__init__()
     self.iface = iface
     self.parent = parent
     # 获取工程所在路径
     self.project_dir = getProjectDir(self.iface)
     # 获取操作图层对象
     self.sitelayer = getLayerByName(u'基站', self.iface)
     self.celllayer = getLayerByName(u'小区', self.iface)
     self.selectedSiteFeatures = self.sitelayer.selectedFeatures()
     self.allCellFeatures = self.celllayer.getFeatures()
     # 初始化鼠标点选事件
     self.mapTool = MapTool(self.iface.mapCanvas())
     self.mapTool.canvasClicked.connect(self.mouseClicked)
     self.iface.mapCanvas().setMapTool(self.mapTool)
     self.iface.mapCanvas().mapToolSet[QgsMapTool, QgsMapTool].connect(
         self.mapToolChanged)
     self.crsXform = QgsCoordinateTransform()
     self.crsXform.setDestCRS(QgsCoordinateReferenceSystem(4326))
     self.pos = None
     '''self.cellutils = FeatureUtils(u'小区', self.iface)
     self.siteutils = FeatureUtils(u'基站', self.iface)'''
     self.initUI()
Beispiel #6
0
    def createNodeLayer(self):
        project_dir = getProjectDir(self.iface, u"基站")
        if not project_dir:
            QMessageBox.critical(self, u"错误", u"基站图层不存在!")
            return False
        else:
            project = QgsProject.instance()
            VoronoiName = u"泰森多边形"
            NodesName = u"泰森结点"
            # 若已存在泰森多边形和泰森结点图层,则先移除图层再删除shape文件
            voronoi_layer = getLayerByName(VoronoiName, self.iface)
            if voronoi_layer:
                QgsMapLayerRegistry.instance().removeMapLayer(voronoi_layer)
            else:
                deleteShapefile(project_dir, VoronoiName)
            nodes_layer = getLayerByName(NodesName, self.iface)
            if nodes_layer:
                QgsMapLayerRegistry.instance().removeMapLayer(nodes_layer)
            else:
                deleteShapefile(project_dir, NodesName)

            if (voronoi_layer) or (nodes_layer):
                project.write()
                QMessageBox.critical(self, u"错误", u"相应文件已被占用,请重启QGIS软件!")
                return False

            site_layer = getLayerByName(u'基站', self.iface)
            # 生成泰森多边形
            VoronoiFile = os.path.join(project_dir, VoronoiName + u".shp")
            Vor = processing.runalg("qgis:voronoipolygons", site_layer, 0, VoronoiFile)
            Voronoi = processing.load(Vor['OUTPUT'], VoronoiName)
            # 生成泰森结点
            NodesFile = os.path.join(project_dir, NodesName + u".shp")
            Nod = processing.runalg("qgis:extractnodes", Voronoi, NodesFile)
            Nodes = processing.load(Nod['OUTPUT'], NodesName)

            return Nodes
 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