def _get_link_tile_id(self, node_id, link_id, tile_id_14):
     if tile_id_14:
         return convert_tile_id(tile_id_14)
     hwy_data = HwyDataMng.instance()
     G = hwy_data.get_graph()
     if node_id not in G:
         return None
     tile_id_14 = G.get_out_link_tile(node_id, link_id)
     if not tile_id_14:
         tile_id_14 = G.get_in_link_tile(node_id, link_id)
     return convert_tile_id(tile_id_14)
Beispiel #2
0
 def _make_service_road_mapping(self):
     '''高速/收费 辅路(link_type=6, road_code无)'''
     road_no = INVALID_ROAD_NO
     road_kind = ROAD_ATTR_NONE
     for link_info in self._get_service_road():
         link_id, s_node, e_node = link_info[0:3]
         one_way, display_class, tile_id = link_info[3:6]
         tile_id = convert_tile_id(tile_id)  # 14层tile转成高层tile
         bwd_ics, fwd_ics = self._get_sv_link_bwd_fwd_ic(
             link_id, s_node, e_node, one_way)
         # 取得道路情报
         road_kind, road_no = self._get_sv_link_road_info(
             link_id, s_node, e_node, one_way)
         path_type = PATH_TYPE_SR  # 辅路
         ic_count = len(bwd_ics)
         # 删除旧的记录
         if self._is_in_hwy_mapping(link_id):
             self.__delete_mapping(link_id)
         link_maps = []
         for bwd_ic, fwd_ic in zip(bwd_ics, fwd_ics):
             if not bwd_ic and not fwd_ic:
                 self.log.error(
                     'No Backward/Forward IC for Service link=%s' % link_id)
                 continue
             # print link_id, road_kind, road_no, fwd_ic, bwd_ic
             link_map = HwyLinkMapping(road_kind, ic_count, road_no,
                                       display_class, link_id, fwd_ic,
                                       bwd_ic, path_type, tile_id)
             link_maps.append(link_map)
         self._insert_mapping(link_maps)
     self.pg.commit1()
 def _make_main_link_mapping(self):
     '''本线link的Mapping'''
     self.log.info('Start Making Main Link Mapping.')
     file_obj = cache_file.open('temp_highway_mapping_main')  # 创建临时文件
     self.pg.connect1()
     for road_code, updown, path in self.data_mng.get_road_code_path():
         bwd_ic_nos = []  # 后方(车流方向)
         fwd_ic_nos = []  # 前方(车流方向)
         bwd_ic_no = None
         fwd_ic_no = None
         road_maps = []  # 整条线路的Link
         section_maps = []  # 两个相邻的设施之间所有link
         for u, v in zip(path[:-1], path[1:]):
             link_id = self.G.get_linkid(u, v)
             displayclass = self.G.get_disp_class(u, v)
             road_no = self.data_mng.get_road_no(road_code)
             tile_id_14 = self.G.get_tile_id(u, v)
             tile_id = convert_tile_id(tile_id_14)  # 14层tile转成高层tile
             road_kind = updown
             if(self.G.is_hwy_node(u) or
                self.data_mng.is_boundary_node(u)):
                 # 取得后方设施
                 if fwd_ic_nos:
                     bwd_ic_nos = fwd_ic_nos
                 else:
                     bwd_ic_nos = self.data_mng.get_ic_nos_by_node(u,
                                                                   road_code
                                                                   )
                 fwd_ic_nos = []
                 fwd_ic_no = None
             # 取得前方设施
             if(self.G.is_hwy_node(v) or
                self.data_mng.is_boundary_node(v)):
                 fwd_ic_nos = self.data_mng.get_ic_nos_by_node(v, road_code)
             if bwd_ic_nos:
                 bwd_ic_no = max(bwd_ic_nos)
             else:
                 self.log.error('Backward ic_no is null. road_code=%s,'
                                'link_id=%s.' % (road_code, link_id))
                 bwd_ic_no = 0
             if fwd_ic_nos:
                 fwd_ic_no = min(fwd_ic_nos)
             link_map = HwyLinkMapping(road_kind, 1, road_no,
                                       displayclass, link_id,
                                       None, bwd_ic_no,  # fwd_ic先设成空
                                       HWY_PATH_TYPE_MAIN, tile_id)
             section_maps.append(link_map)
             if fwd_ic_no:
                 for link_map in section_maps:
                     link_map.forward_ic_no = fwd_ic_no
                     road_maps.append(link_map)
                 section_maps = []
         if not fwd_ic_no:  # 最后一段线路有没有前方设施
             self.log.error('Main_road: No Forward IC. road_code=%s'
                            % road_code)
         self._insert_mapping(road_maps, file_obj)  # 保存整条线路的Link的Mapping情报
     self._store_hwy_mapping(file_obj)
     self.CreateIndex2('highway_mapping_link_id_idx')
     self.log.info('End Making Main Link Mapping.')
Beispiel #4
0
 def _make_main_link_mapping(self):
     hwy_data = HwyDataMng.instance()
     data = self.__get_main_path()
     self.pg.connect1()
     for info in data:
         road_code = info[0]
         updown = info[1]
         node_lid = info[2]
         link_lid = info[3]
         dispcls = info[4]
         min_ic_nos = info[5]  # 点上的最小设施号
         max_ic_nos = info[6]  # 点上的最大设施号
         cycle_flag = info[7]
         tile_ids = info[8]
         road_kind = hwy_data.get_road_kind(road_code, updown)
         road_no = hwy_data.get_road_no(road_code)
         backward_ic = None  # 后方
         forward_ic = None  # 前方
         section_maps = []  # 上个设施到下个设施之间的link
         road_maps = []  # 整条道路的Link
         for node, link, displayclass, min_ic, max_ic, tile_id in \
         zip(node_lid, link_lid, dispcls, min_ic_nos, max_ic_nos, tile_ids):
             tile_id = convert_tile_id(tile_id)  # 14层tile转成高层tile
             if min_ic and section_maps and not backward_ic:
                 self.log.error('在第一个设施后方有本线link. roadcode=%s' % road_code)
             if min_ic and backward_ic:
                 # 环形的最后一个设施(JCT OUT)到第一个设施(JCT IN), 之间的Link, 不收录
                 # 因为,后面的IC link会收录。
                 if cycle_flag and node == node_lid[0]:
                     # print road_code, len(section_maps)
                     section_maps = []
                     break
                 forward_ic = min_ic
                 link_map = HwyLinkMapping(road_kind, 1, road_no,
                                           displayclass, link, None,
                                           backward_ic, PATH_TYPE_MAIN,
                                           tile_id)
                 section_maps.append(link_map)
                 for link_map in section_maps:
                     link_map.forward_ic_no = forward_ic
                     road_maps.append(link_map)
                 section_maps = []
                 if max_ic:
                     backward_ic = max_ic
                 else:
                     print 'Error'
                 continue
             if max_ic:
                 backward_ic = max_ic
             if link:
                 link_map = HwyLinkMapping(road_kind, 1, road_no,
                                           displayclass, link, None,
                                           backward_ic, PATH_TYPE_MAIN,
                                           tile_id)
                 section_maps.append(link_map)
         self.__insert_mapping(road_maps)
     self.pg.commit1()
Beispiel #5
0
 def is_hwy_tile_boundary(self, node_id, roadcode):
     '''判断是不是第十层边界: 进入本线link的TileId与出去本线link的TielId不同。'''
     G = self.data_mng.get_graph()
     in_tile, out_tile = None, None
     in_tiles = G.get_in_tile(node_id, roadcode)
     if in_tiles:
         if len(in_tiles) > 1:
             self.log.warning('Main InTile > 1,boundary_node=%s' % node_id)
         in_tile = convert_tile_id(in_tiles[0])
     out_tiles = G.get_out_tile(node_id, roadcode)
     if out_tiles:
         if len(out_tiles) > 1:
             self.log.warning('Main OutTile > 1,boundary_node=%s' % node_id)
         out_tile = convert_tile_id(out_tiles[0])
     if not in_tile or not out_tile:
         self.log.warning('No InTile or No OutTile. boundary_node=%s' %
                          node_id)
         return False
     return in_tile != out_tile
Beispiel #6
0
 def _make_ic_link_mapping(self):
     '''Ramp, SAPA, JCT Link的mapping'''
     self.log.info('Start Make IC Link Mapping.')
     self.__make_ic_link_temp_mapping()
     self.pg.connect1()
     hwy_data = HwyDataMng.instance()
     G = hwy_data.get_graph()
     data = self.__get_forward_backward_ic()
     for fb_info in data:
         link_id = fb_info[0]
         bwd_ic_nos = fb_info[1]
         fwd_ic_nos = fb_info[2]
         bwd_node_ids = fb_info[3]
         fwd_node_ids = fb_info[4]
         displayclass = fb_info[5]
         tile_id = convert_tile_id(fb_info[6])
         self.link_type = fb_info[7]
         self.link_id = link_id
         if not bwd_ic_nos and not fwd_ic_nos:
             #self.log.error('1. No Backward/Forward IC for link=%s'
             #               % link_id)
             continue
         #print link_id
         bwd_ic_list, bwd_facil_list = self._get_ic_facils(
             bwd_ic_nos, bwd_node_ids)
         fwd_ic_list, fwd_facil_list = self._get_ic_facils(
             fwd_ic_nos, fwd_node_ids)
         road_code, updown = self.__get_ic_link_road_code(
             bwd_facil_list, fwd_facil_list)
         if road_code:
             road_no = hwy_data.get_road_no(road_code)
             road_kind = hwy_data.get_road_kind(road_code, updown)
         else:
             road_no = INVALID_ROAD_NO
             road_kind = ROAD_ATTR_NONE
         bwd_ics, fwd_ics = self.__get_ic_link_fb_ic(
             bwd_ic_list, fwd_ic_list)
         if not bwd_ics and not fwd_ics:
             self.log.error('2. No Backward/Forward IC for link=%s' %
                            link_id)
             continue
         link_maps = []
         for bwd_ic, fwd_ic in zip(bwd_ics, fwd_ics):
             # 前后设施都为空——通常是无料区间
             if not bwd_ic and not fwd_ic:
                 self.log.error('3. No Backward/Forward IC for link=%s' %
                                link_id)
                 continue
             link_map = HwyLinkMapping(road_kind, len(bwd_ics), road_no,
                                       displayclass, link_id, fwd_ic,
                                       bwd_ic, PATH_TYPE_IC, tile_id)
             link_maps.append(link_map)
         self._insert_mapping(link_maps)
     self.pg.commit1()
Beispiel #7
0
 def is_hwy_tile_boundary(self, node_id, roadcode, boundary_flag):
     if not boundary_flag:
         return False
     # 判断是不是第十层边界
     hwy_data = HwyDataMng.instance()
     G = hwy_data.get_graph()
     in_tile, out_tile = None, None
     in_tiles = G.get_in_tile(node_id, roadcode)
     if in_tiles:
         if len(in_tiles) > 1:
             self.log.warning('Main InTile > 1,boundary_node=%s' % node_id)
         in_tile = convert_tile_id(in_tiles[0])
     out_tiles = G.get_out_tile(node_id, roadcode)
     if out_tiles:
         if len(out_tiles) > 1:
             self.log.warning('Main OutTile > 1,boundary_node=%s' % node_id)
         out_tile = convert_tile_id(out_tiles[0])
     if not in_tile and not out_tile:
         self.log.warning('No InTile and OutTile. boundary_node=%s' %
                          node_id)
         return False
     return in_tile != out_tile
Beispiel #8
0
 def _get_toll_tile_id(self, toll_nodes):
     tile_ids = set()
     hwy_data = HwyDataMng.instance()
     G = hwy_data.get_graph()
     for nodeid in toll_nodes:
         out_tiles = G.get_out_tile(nodeid)
         if len(out_tiles) > 1:
             self.log.warning('Out Tile > 1. toll_node_id=%s' % nodeid)
         for tile_id_14 in out_tiles:
             tile_id = convert_tile_id(tile_id_14)
             tile_ids.add(tile_id)
     tile_ids = list(tile_ids)
     tile_ids.sort()
     return tile_ids
 def _make_ic_link_mapping(self):
     '''IC(SAPA, JCT, IC) Link的mapping'''
     self.log.info('Start Make IC Link Mapping.')
     file_obj = cache_file.open('temp_highway_mapping_ic')  # 创建临时文件
     # 做成每条IC Link的每个前后设施。
     self._make_ic_link_temp_mapping()
     self.pg.connect1()
     data = self._get_forward_backward_ic()  # 取得link的前后方所有设施
     for fb_info in data:
         link_id = fb_info[0]
         bwd_ic_nos = fb_info[1]
         fwd_ic_nos = fb_info[2]
         bwd_node_ids = fb_info[3]
         fwd_node_ids = fb_info[4]
         displayclass = fb_info[5]
         tile_id_14 = fb_info[6]
         tile_id = convert_tile_id(tile_id_14)
         self.link_type = fb_info[7]
         self.link_id = link_id
         one_way = fb_info[8]
         if not bwd_ic_nos and not fwd_ic_nos:
             # self.log.error('1. No Backward/Forward IC for link=%s'
             #                % link_id)
             continue
         bwd_ic_list, bwd_facil_list = self._get_ic_facils(bwd_ic_nos,
                                                           bwd_node_ids)
         fwd_ic_list, fwd_facil_list = self._get_ic_facils(fwd_ic_nos,
                                                           fwd_node_ids)
         road_code, updown = self._get_ic_link_road_code(bwd_facil_list,
                                                         fwd_facil_list)
         if road_code:
             road_no = self.data_mng.get_road_no(road_code)
             road_kind = updown
             # self.data_mng.get_road_kind(road_code, updown)
         else:
             road_no = HWY_INVALID_ROAD_NO
             road_kind = HWY_ROAD_ATTR_NONE
         bwd_ics, fwd_ics = self._get_ic_link_fb_ic(bwd_ic_list,
                                                    fwd_ic_list)
         if not bwd_ics and not fwd_ics:
             self.log.error('2. No Backward/Forward IC for link=%s'
                            % link_id)
             continue
         link_maps = []
         if one_way == ONE_WAY_BOTH:  # 双向通行
             # if road_no > HWY_INVALID_ROAD_NO:
             #    print 'Both:', link_id
             # 双向通行,不能确认前后方向,所有前后方设施都填0
             fwd_ic, bwd_ic = HWY_INVALID_IC_NO, HWY_INVALID_IC_NO
             link_map = HwyLinkMapping(road_kind, 1, road_no,
                                       displayclass, link_id,
                                       fwd_ic, bwd_ic,
                                       'IC', tile_id)
             link_maps.append(link_map)
         else:
             for bwd_ic, fwd_ic in zip(bwd_ics, fwd_ics):
                 # 前后设施都为空——通常是无料区间
                 if not bwd_ic and not fwd_ic:
                     self.log.error('3. No Backward/Forward IC for link=%s'
                                    % link_id)
                     continue
                 link_map = HwyLinkMapping(road_kind, len(bwd_ics), road_no,
                                           displayclass, link_id,
                                           fwd_ic, bwd_ic,
                                           'IC', tile_id)
                 link_maps.append(link_map)
         self._insert_mapping(link_maps, file_obj)
     self._store_hwy_mapping(file_obj)
     self.pg.commit1()
     self.log.info('End Make IC Link Mapping.')