def updateResByLine(self,
                        fPoint,
                        tPoint,
                        fromGid,
                        toGid,
                        direction,
                        speed,
                        type='all'):
        self.singleDirectionCount += 1

        # 处理方向与网格间的相交点
        fGidIPoint, tGidIPoint = self.getGridIntersection(
            fPoint, tPoint, fromGid, toGid, direction)
        fGidIPointStr = "%.6f,%.6f" % (fGidIPoint[0], fGidIPoint[1])
        tGidIPointStr = "%.6f,%.6f" % (tGidIPoint[0], tGidIPoint[1])

        # 分方向结果字符串
        # [lng, lat, gid, from/to, speed, direction]
        fromVecStr = "%s,%d,from,%f,%s" % (fGidIPointStr, fromGid, speed,
                                           direction)
        toVecStr = "%s,%d,to,%f,%s" % (tGidIPointStr, toGid, speed, direction)

        # 处理一:分方向的旅途元数据存储
        if type == 'all' or type == 'from':
            if fromGid in self.resByDir[direction].keys():
                self.resByDir[direction][fromGid].append(fromVecStr)
            else:
                self.resByDir[direction][fromGid] = [fromVecStr]

        if type == 'all' or type == 'to':
            if toGid in self.resByDir[direction].keys():
                self.resByDir[direction][toGid].append(toVecStr)
            else:
                self.resByDir[direction][toGid] = [toVecStr]
        # END

        # 处理二:分出入的旅途元数据(归一化向量)存储

        # fX = fPoint[1] - fGidIPoint[1]
        # fY = fPoint[0] - fGidIPoint[0]
        # tX = tPoint[1] - tGidIPoint[1]
        # tY = tPoint[0] - tGidIPoint[0]
        # fiDis = sqrt(pow(fX, 2) + pow(fY, 2))
        # tiDis = sqrt(pow(tX, 2) + pow(tY, 2))

        # 计算边方向及其绝对距�?
        vecX = tPoint[0] - fPoint[0]
        vecY = tPoint[1] - fPoint[1]
        vecDis = sqrt(pow(vecY, 2) + pow(vecX, 2))

        angleLng = vecX / vecDis
        angleLat = vecY / vecDis

        if type == 'all' or type == 'from':

            fPointStr = "%.6f,%.6f" % (fPoint[0], fPoint[1])
            fangle = acos(angleLng) * 180 / pi
            if angleLat < 0 and fangle > 0.1:
                fangle = 360 - fangle

            # where we can put map-matching code

            fromCVecStr = "%s,%d,from,%f,%s,%.1f,1" % (
                fPointStr, fromGid, speed, direction, fangle)

            # if fromGid == 59670:
            # 	print(fPoint, tPoint, fromGid, toGid, direction, speed)
            # 	print(fromCVecStr)
            if fromGid in self.resByCate['from'].keys():
                self.resByCate['from'][fromGid].append(fromCVecStr)
            else:
                self.resByCate['from'][fromGid] = [fromCVecStr]

            # KDE 处理 from 相邻24个小格方向问�?
            if self.delta > 0:
                for x in xrange(-2, 3):
                    for y in xrange(-2, 3):
                        if x == 0 and y == 0:
                            continue

                        newGID = getGIDByIndex(fromGid, x, y, self.LngSPLIT,
                                               self.LatSPLIT, self.locs)
                        newStrength = pow(math.e,
                                          -(x * x + y * y) / self.delta)
                        fromCVecStr = "%s,%d,from,%f,%s,%.1f,%f" % (
                            fPointStr, newGID, speed, direction, fangle,
                            newStrength)

                        if newGID in self.resByCate['from'].keys():
                            self.resByCate['from'][newGID].append(fromCVecStr)
                        else:
                            self.resByCate['from'][newGID] = [fromCVecStr]
            # KDE END

        if type == 'all' or type == 'to':

            tPointStr = "%.6f,%.6f" % (tPoint[0], tPoint[1])
            tangle = acos(angleLng) * 180 / pi
            if angleLat < 0 and tangle > 0.1:
                tangle = 360 - tangle

            # where we can put map-matching code

            toCVecStr = "%s,%d,to,%f,%s,%.1f,1" % (tPointStr, toGid, speed,
                                                   direction, tangle)

            # if toGid == 59670:
            # 	print(fPoint, tPoint, fromGid, toGid, direction, speed)
            # 	print(toCVecStr)
            if toGid in self.resByCate['to'].keys():
                self.resByCate['to'][toGid].append(toCVecStr)
            else:
                self.resByCate['to'][toGid] = [toCVecStr]

            # if toGid == 59670:
            # 	print("to:")
            # 	print(self.resByCate['to'][toGid])
            #
            # if fromGid == 59670:
            # 	print("from:")
            # 	print(self.resByCate['from'][fromGid])

            # KDE 处理 to 相邻24个小格方向问�?
            if self.delta > 0:
                for x in xrange(-2, 3):
                    for y in xrange(-2, 3):
                        if x == 0 and y == 0:
                            continue

                        newGID = getGIDByIndex(toGid, x, y, self.LngSPLIT,
                                               self.LatSPLIT, self.locs)
                        newStrength = pow(math.e,
                                          -(x * x + y * y) / self.delta)
                        toCVecStr = "%s,%d,to,%f,%s,%.1f,%f" % (
                            tPointStr, newGID, speed, direction, tangle,
                            newStrength)

                        if newGID in self.resByCate['to'].keys():
                            self.resByCate['to'][newGID].append(toCVecStr)
                        else:
                            self.resByCate['to'][newGID] = [toCVecStr]
            # KDE END
            # END

        return 0
예제 #2
0
    def updateResByLine(self, fPoint, tPoint, fromGid, toGid, direction,
                        speed):
        self.singleDirectionCount += 1

        # 处理方向与网格间的相交点
        fGidIPoint, tGidIPoint = self.getGridIntersection(
            fPoint, tPoint, fromGid, toGid, direction)
        fGidIPointStr = "%.6f,%.6f" % (fGidIPoint[0], fGidIPoint[1])
        tGidIPointStr = "%.6f,%.6f" % (tGidIPoint[0], tGidIPoint[1])

        # 分方向结果字符串
        # [lng, lat, gid, from/to, speed, direction]
        fromVecStr = "%s,%d,from,%f,%s" % (fGidIPointStr, fromGid, speed,
                                           direction)
        toVecStr = "%s,%d,to,%f,%s" % (tGidIPointStr, toGid, speed, direction)

        # 处理一:分方向的旅途元数据存储
        if fromGid in self.resByDir[direction].keys():
            self.resByDir[direction][fromGid].append(fromVecStr)
        else:
            self.resByDir[direction][fromGid] = [fromVecStr]

        if toGid in self.resByDir[direction].keys():
            self.resByDir[direction][toGid].append(toVecStr)
        else:
            self.resByDir[direction][toGid] = [toVecStr]
        # END

        # 处理二:分出入的旅途元数据(归一化向量)存储
        fX = fPoint[1] - fGidIPoint[1]
        fY = fPoint[0] - fGidIPoint[0]
        tX = tPoint[1] - tGidIPoint[1]
        tY = tPoint[0] - tGidIPoint[0]
        fiDis = sqrt(pow(fX, 2) + pow(fY, 2))
        tiDis = sqrt(pow(tX, 2) + pow(tY, 2))

        # 计算边方向及其绝对距离
        vecY = tPoint[0] - fPoint[0]
        vecX = tPoint[1] - fPoint[1]
        vecDis = sqrt(pow(vecY, 2) + pow(vecX, 2))

        angleLng = vecY / vecDis
        angleLat = vecX / vecDis
        tmpLng = fPoint[0] + angleLng
        tmpLat = fPoint[1] + angleLat
        fCircleIPointStr = "%.6f,%.6f" % (tmpLng, tmpLat)
        fangle = acos(angleLat) * 180 / pi
        if angleLng < 0 and fangle > 0.1:
            fangle = 360 - fangle

        fromCVecStr = "%s,%d,from,%f,%s,%.1f,1" % (fCircleIPointStr, fromGid,
                                                   speed, direction, fangle)

        if fromGid in self.resByCate['from'].keys():
            self.resByCate['from'][fromGid].append(fromCVecStr)
        else:
            self.resByCate['from'][fromGid] = [fromCVecStr]

        # KDE 处理 from 相邻24个小格方向问题
        if self.delta > 0:
            for x in xrange(-2, 3):
                for y in xrange(-2, 3):
                    if x == 0 and y == 0:
                        continue

                    newGID = getGIDByIndex(fromGid, x, y)
                    newStrength = pow(math.e, -(x * x + y * y) / self.delta)
                    fromCVecStr = "%s,%d,from,%f,%s,%.1f,%f" % (
                        fCircleIPointStr, newGID, speed, direction, fangle,
                        newStrength)

                    if newGID in self.resByCate['from'].keys():
                        self.resByCate['from'][newGID].append(fromCVecStr)
                    else:
                        self.resByCate['from'][newGID] = [fromCVecStr]
        # KDE END

        tmpLng = tPoint[0] + angleLng
        tmpLat = tPoint[1] + angleLat
        tCircleIPointStr = "%.6f,%.6f" % (tmpLng, tmpLat)
        tangle = acos(angleLat) * 180 / pi
        toCVecStr = "%s,%d,to,%f,%s,%.1f,1" % (tCircleIPointStr, toGid, speed,
                                               direction, tangle)

        if toGid in self.resByCate['to'].keys():
            self.resByCate['to'][toGid].append(toCVecStr)
        else:
            self.resByCate['to'][toGid] = [toCVecStr]

        # KDE 处理 to 相邻24个小格方向问题
        if self.delta > 0:
            for x in xrange(-2, 3):
                for y in xrange(-2, 3):
                    if x == 0 and y == 0:
                        continue

                    newGID = getGIDByIndex(toGid, x, y)
                    newStrength = pow(math.e, -(x * x + y * y) / self.delta)
                    toCVecStr = "%s,%d,to,%f,%s,%.1f,%f" % (
                        tCircleIPointStr, newGID, speed, direction, tangle,
                        newStrength)

                    if newGID in self.resByCate['to'].keys():
                        self.resByCate['to'][newGID].append(toCVecStr)
                    else:
                        self.resByCate['to'][newGID] = [toCVecStr]
        # KDE END
        # END

        return 0