def get_route(self, from_point, to_point, barrier_points=[]): # get edges start_edge_id = self.get_nearest_edge_id(from_point) if not start_edge_id: raise Exception("Start point is too far from road!") end_edge_id = self.get_nearest_edge_id(to_point) if not end_edge_id: raise Exception("End point is too far from road!") # get barriers edges barrier_edge_ids = [] for bar_point in barrier_points: bar_edge_id = self.get_nearest_edge_id(bar_point) barrier_edge_ids.append(bar_edge_id) position = 0.5 # TODO: add proportion getter # request pgr_trsp = select( ["id2"], from_obj=func.pgr_trsp( self.get_net_query(), start_edge_id, position, end_edge_id, position, True, True, self.get_restrict_query(barrier_edge_ids), ), ).alias("trsp") try: route = ( self._session.query(Way.gid, Way.name, Way.osm_id, Way.length, Way.the_geom.ST_AsGeoJSON()) .select_from(pgr_trsp) .join(Way, text("trsp.id2") == Way.gid) .all() ) except InternalError, err: exc_desc = str(err) if "Path Not Found" in exc_desc: raise Exception("Path Not Found") else: raise
def get_route(self, from_point, to_point): #get edges start_edge_id = self.get_nearest_edge_id(from_point) if not start_edge_id: raise Exception('Start point is too far from road!') end_edge_id = self.get_nearest_edge_id(to_point) if not end_edge_id: raise Exception('End point is too far from road!') position = 0.5 # TODO: add proportion getter #request pgr_trsp = select(['id2'], from_obj=func.pgr_trsp(self.get_net_query(), start_edge_id, position, end_edge_id, position, False, False)).alias('trsp') try: route = self._session.query(SimpleRoad.id, SimpleRoad.name, SimpleRoad.name_short, SimpleRoad.road_no, SimpleRoad.road_uid, SimpleRoad.the_geom.ST_AsGeoJSON()).select_from(pgr_trsp).join(SimpleRoad, text('trsp.id2') == SimpleRoad.id).all() except InternalError, err: exc_desc = str(err) if 'Path Not Found' in exc_desc: raise Exception('Path Not Found') else: raise