Beispiel #1
0
    def LoadNetworkFile(self):
        self.ResetNetwork_Scene()
        filePath = QtGui.QFileDialog.getOpenFileName(
            self, "Load Network", "", "Networkfile data files (*.txt)")
        if filePath == "":
            return
        try:
            f = open(filePath)
        except:
            f = open(filePath)
            return False
        self.graph = snap.TUNGraph.New()
        endofFile = False
        line = f.readline()
        strs = line.split("#")
        self.numNodes = int(strs[1])
        numEdges = int(strs[3])
        index = 0

        for i in range(self.numNodes):
            line = f.readline().rstrip("\n").split("#")
            self.graph.AddNode(index)
            self.graphLabelToId[line[0]] = index
            self.nodesLatLonPostion[index] = [line[1], line[2]]
            if len(line) > 1:
                left, top, right, bottom, ratio = Utility.GetLTRB(
                    self.bbox, self.GraphicsScene)
                point = ShapefileReader.Point(float(line[1]), float(line[2]))
                x, y = Utility.ConvertPostion(point, ratio, left, bottom,
                                              self.bbox[0], self.bbox[1])
                self.nodesPosition[index] = (x, y)
            index += 1
        for i in range(numEdges):
            line = f.readline().rstrip("\n")
            strs = line.split(",")
            self.graph.AddEdge(self.graphLabelToId[strs[0]],
                               self.graphLabelToId[strs[1]])
        self.DrawGraph(self.graph, self.nodesPosition)
Beispiel #2
0
    def ViewBaseMap(self):
        if self.bbox is None:
            Utility.SystemWarning(
                "Please select basemap shapefile before clicking this button!")
            return
        left, top, right, bottom, ratio = Utility.GetLTRB(
            self.bbox, self.GraphicsScene)
        self.polyBorderDict = {}

        for polygon in self.shapes:
            for i in range(polygon.partsNum):
                points = []
                xList = []
                yList = []
                ployF = QtGui.QPolygonF()
                startIndex = polygon.partsIndex[i]
                if i == polygon.partsNum - 1:
                    endIndex = len(polygon.points)
                else:
                    endIndex = polygon.partsIndex[i + 1]
                for point in polygon.points[startIndex:endIndex]:
                    x, y = Utility.ConvertPostion(point, ratio, left, bottom,
                                                  self.bbox[0], self.bbox[1])
                    ployF.append(QtCore.QPointF(x, y))
                    points.append([x, y])
                    xList.append(x)
                    yList.append(y)
                self.polyBorderDict[polygon] = [[min(xList), max(xList)]]
                self.polyBorderDict[polygon].append([min(yList), max(yList)])
                self.polyBorderDict[polygon].append(points)
                polylineItem = QtGui.QGraphicsPolygonItem(ployF)
                polylineItem.setBrush(QtGui.QBrush(QtGui.QColor("skyblue")))
                self.GraphicsScene.addItem(polylineItem)
                self.polygonItemList[polygon] = polylineItem
        if len(self.shapes) > 0:
            self.baseMap = True