Ejemplo n.º 1
0
 def _nearestVertex(self, wktPoint):
     distance = functions.distance(RoutingEdge.the_geom, wktPoint).label('dist')
     edge = Session.query(RoutingEdge.source, RoutingEdge.target).add_column(distance) \
             .add_column(RoutingEdge.x1).add_column(RoutingEdge.y1).add_column(RoutingEdge.x2).add_column(RoutingEdge.y2) \
             .order_by('dist').limit(1).first()
     point = wkt.loads(wktPoint)
     source = Point(edge.x1, edge.y1)
     target = Point(edge.x2, edge.y2)
     if point.distance(source) < point.distance(target) :
         return edge.source
     else:
         return edge.target
Ejemplo n.º 2
0
 def _nearestVertex(self, wktPoint):
     distance = functions.distance(RoutingEdge.the_geom,
                                   wktPoint).label('dist')
     edge = Session.query(RoutingEdge.source, RoutingEdge.target).add_column(distance) \
             .add_column(RoutingEdge.x1).add_column(RoutingEdge.y1).add_column(RoutingEdge.x2).add_column(RoutingEdge.y2) \
             .order_by('dist').limit(1).first()
     point = wkt.loads(wktPoint)
     source = Point(edge.x1, edge.y1)
     target = Point(edge.x2, edge.y2)
     if point.distance(source) < point.distance(target):
         return edge.source
     else:
         return edge.target
Ejemplo n.º 3
0
    def _shortestPath(self, start, end, options={}):
        """ returns an ordered array of nodes """

        steps = shortest_path_astar(Session, "SELECT * FROM edges", start, end, True, True)

        edge_ids = []
        costs = []
        for step in steps:
            edge_ids.append(step.edge_id)
            costs.append(step.cost)
            
        # gets only name highway altitide diff length
        edges = Session.query(RoutingEdge.id, RoutingEdge.name, RoutingEdge.highway, RoutingEdge.length, RoutingEdge.altitude_diff, RoutingEdge.the_geom).filter(RoutingEdge.id.in_(edge_ids)).all()

        # reorder edges list according to edge_ids
        order_map = dict([(v,k) for (k,v) in enumerate(edge_ids)])
        edges.sort(key=lambda v: order_map[v.id])

        return (edges, costs, steps.rowcount)
Ejemplo n.º 4
0
    def _shortestPath(self, start, end, options={}):
        """ returns an ordered array of nodes """

        steps = shortest_path_astar(Session, "SELECT * FROM edges", start, end,
                                    True, True)

        edge_ids = []
        costs = []
        for step in steps:
            edge_ids.append(step.edge_id)
            costs.append(step.cost)

        # gets only name highway altitide diff length
        edges = Session.query(RoutingEdge.id, RoutingEdge.name,
                              RoutingEdge.highway, RoutingEdge.length,
                              RoutingEdge.altitude_diff,
                              RoutingEdge.the_geom).filter(
                                  RoutingEdge.id.in_(edge_ids)).all()

        # reorder edges list according to edge_ids
        order_map = dict([(v, k) for (k, v) in enumerate(edge_ids)])
        edges.sort(key=lambda v: order_map[v.id])

        return (edges, costs, steps.rowcount)