Example #1
0
    def test_getTileFromCoords1 (self):

        '''
        Too simple really...

        '''
        
        t = Tile (-1,2)
        self.failUnless ( t == Locator.getTileFromCoords ( -1, 2 ) )

        t = Tile (1,-2)
        self.failUnless ( t == Locator.getTileFromCoords ( 1, -2 ) )
Example #2
0
    def test_getTileBoundingSet (self):

        '''
        test a range of positive and negative co-ordinates
        '''

        tileList = Locator.getTileBoundingSet ( 1,1, 2,2 ) 

        y =  [ x.getID() for x in tileList ] 

        print y
        tileList = Locator.getTileBoundingSet ( -2, 2, 3, 1 ) 

        y =  [ x.getID() for x in tileList ] 
        print y
Example #3
0
    def test_locateEdgeInGraph (self):

        '''
        
        '''

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

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

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

        G =  {'a':{ 'b': e1, 'c': e2 }, 
              'b':{ 'a': e3 }
             }

        self.failUnless ( e1 == Locator.closestEdgeInGraph ( 3, 4, G ) )
Example #4
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 #5
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)