Example #1
0
    def testShortestPath1 (self):

        '''
        Simple routing test

        '''
        e_A_B= GISEdge  (edgeID = 'A-B',   sourceNode = 'A', 
                        targetNode = 'B',  WKT = None,        
                        lengthKM = 1,      edgeCost = 1, 
                        centroidWKT = "POINT(0.2 0.2)",  
                        isToll = False )

        e_B_A= GISEdge  (edgeID = 'B-A',   sourceNode = 'B', 
                        targetNode = 'A',  WKT = None,        
                        lengthKM = 1,      edgeCost = 1, 
                        centroidWKT = "POINT(0.2 0.2)",  
                        isToll = False )

        e_A_C= GISEdge  (edgeID = 'A-C',   sourceNode = 'A', 
                        targetNode = 'C',  WKT = None,        
                        lengthKM = 1,      edgeCost = 1, 
                        centroidWKT = "POINT(0.2 0.2)",  
                        isToll = False )

        e_C_A= GISEdge  (edgeID = 'C-A',   sourceNode = 'C', 
                        targetNode = 'A',  WKT = None,        
                        lengthKM = 1,      edgeCost = 1, 
                        centroidWKT = "POINT(0.2 0.2)",  
                        isToll = False )

        e_C_D= GISEdge  (edgeID = 'C-D',   sourceNode = 'C', 
                        targetNode = 'D',  WKT = None,        
                        lengthKM = 1,      edgeCost = 1, 
                        centroidWKT = "POINT(0.2 0.2)",  
                        isToll = False )

        e_D_C= GISEdge  (edgeID = 'D-C',   sourceNode = 'D', 
                        targetNode = 'C',  WKT = None,        
                        lengthKM = 1,      edgeCost = 1, 
                        centroidWKT = "POINT(0.2 0.2)",  
                        isToll = False )

        print e_A_B

        anEdge = EdgeCost (1)
        graph_1_1 =  {'a':{ 'b': e_A_B, 'c': e_A_C }, 
                      'b':{ 'a': e_B_A },
                      'c':{ 'a': e_C_A }
                     }

        graph_2_2 =  {'c':{ 'a': e_C_A, 'd': e_C_D }, 
                      'd':{ 'c': e_D_C },
                      'a':{ 'c': e_A_C }
                      }

        t1 = Tile ( 1, 0 ) 
        t2 = Tile ( 1, 1 ) 
        
        GR = GraphRepository ([])

        GR[t1] = graph_1_1
        GR[t2] = graph_2_2

        CG = CompositeGraph ( GR )

        edgeList= shortestPath2 ( CG, 'b', 'd' )
        self.failUnless ( len (edgeList) == 3 ) 
        print ( list ( [str(x) for x in edgeList] ))
Example #2
0
def findRoute ( X1, Y1, X2, Y2 ):

    '''

    Find a route between Two Points.  This involves:  

    1. Find the closest road to start/end locations
    2. Ensure that there is a complete network between
       the two points
    3. Do a routing search
    4  Return Distance, Time, GIS route (MULTILINESTRING)
       (as  JSON)

    '''

    X1 = float (X1)
    Y2 = float (Y2)

    Y1 = float (Y1)
    X2 = float (X2)

 
    print ".. Find route from %s, %s " %(X1, Y1)
    print ".. Find route to %s, %s " %(X2, Y2)

    graphRepositoryRef = GraphRepository.getGraphRepository ()
    dataStore = AWS_S3DataStore ()
    # identify the roads 
    fromTile = Locator.getTileFromCoords ( X1, Y1 )
  
    print "from tile %s" %(fromTile.getID()  )

    if fromTile.getID() not in graphRepositoryRef:
        print "Getting From Tile %s" %(fromTile.getID())
        fromTileGraph = dataStore.loadEdgeGraphForTile ( fromTile ) 
        graphRepositoryRef [fromTile] = fromTileGraph

    fromEdge = Locator.closestEdgeInGraph ( X1, Y1, graphRepositoryRef[fromTile]   )

    toTile = Locator.getTileFromCoords ( X2, Y2 )

    print ".. TO tile %s" %(toTile.getID()  )

    if toTile.getID() not in graphRepositoryRef:
        print "Getting From Tile %s" %(toTile.getID())

        toTileGraph = dataStore.loadEdgeGraphForTile ( toTile ) 
        graphRepositoryRef [toTile] = toTileGraph

    toEdge = Locator.closestEdgeInGraph ( X2, Y2, graphRepositoryRef[toTile]   )

    print "loading tileset"

    tileSet = Locator.getTileBoundingSet ( X1, Y1, X2,Y2)

    lstTilesNeeded = _missingTiles ( graphRepositoryRef, tileSet )

    if len ( lstTilesNeeded ) + len ( graphRepositoryRef ) > 20:
        print "Memory allowance exceeded"
        #TODO 
        return 

    for aTile in tileSet:
        if  aTile.getID() not in graphRepositoryRef:
            print "getting tile: %s" %(aTile.getID() )
            G = dataStore.loadEdgeGraphForTile ( aTile )
            graphRepositoryRef [aTile] = G
    
    cg = CompositeGraph ( graphRepositoryRef )

    print "do shortest path"
    resList = shortestPath2 ( cg , fromEdge.sourceNode, toEdge.sourceNode)


    return  _getJSONResultFromNodesList ( resList )
Example #3
0
def findRoute(X1, Y1, X2, Y2):
    '''

    Find a route between Two Points.  This involves:  

    1. Find the closest road to start/end locations
    2. Ensure that there is a complete network between
       the two points
    3. Do a routing search
    4  Return Distance, Time, GIS route (MULTILINESTRING)
       (as  JSON)

    '''

    X1 = float(X1)
    Y2 = float(Y2)

    Y1 = float(Y1)
    X2 = float(X2)

    print ".. Find route from %s, %s " % (X1, Y1)
    print ".. Find route to %s, %s " % (X2, Y2)

    graphRepositoryRef = GraphRepository.getGraphRepository()
    dataStore = AWS_S3DataStore()
    # identify the roads
    fromTile = Locator.getTileFromCoords(X1, Y1)

    print "from tile %s" % (fromTile.getID())

    if fromTile.getID() not in graphRepositoryRef:
        print "Getting From Tile %s" % (fromTile.getID())
        fromTileGraph = dataStore.loadEdgeGraphForTile(fromTile)
        graphRepositoryRef[fromTile] = fromTileGraph

    fromEdge = Locator.closestEdgeInGraph(X1, Y1, graphRepositoryRef[fromTile])

    toTile = Locator.getTileFromCoords(X2, Y2)

    print ".. TO tile %s" % (toTile.getID())

    if toTile.getID() not in graphRepositoryRef:
        print "Getting From Tile %s" % (toTile.getID())

        toTileGraph = dataStore.loadEdgeGraphForTile(toTile)
        graphRepositoryRef[toTile] = toTileGraph

    toEdge = Locator.closestEdgeInGraph(X2, Y2, graphRepositoryRef[toTile])

    print "loading tileset"

    tileSet = Locator.getTileBoundingSet(X1, Y1, X2, Y2)

    lstTilesNeeded = _missingTiles(graphRepositoryRef, tileSet)

    if len(lstTilesNeeded) + len(graphRepositoryRef) > 20:
        print "Memory allowance exceeded"
        #TODO
        return

    for aTile in tileSet:
        if aTile.getID() not in graphRepositoryRef:
            print "getting tile: %s" % (aTile.getID())
            G = dataStore.loadEdgeGraphForTile(aTile)
            graphRepositoryRef[aTile] = G

    cg = CompositeGraph(graphRepositoryRef)

    print "do shortest path"
    resList = shortestPath2(cg, fromEdge.sourceNode, toEdge.sourceNode)

    return _getJSONResultFromNodesList(resList)