本代码主要做备份使用
未添加到代码中
scipy缺点,执行速度没有sklearn速度快
原因:sklearn.cKDtree是使用的C语言
scipy的KDtree使用的是python语言
5D时执行效率cKDtree是KDtree的12倍左右。
sklearn.cKDtree 更改为scipy.KDtree时使用。
if len(road_obstacles_nodes_list) > 1:
self.road_obstacles_with_id_dict = road_obstacles_with_id_dict
# self.osm_road_obstacles_node_tree = spatial.cKDTree(road_obstacles_nodes_list)
self.osm_road_obstacles_node_tree = KDTree(road_obstacles_nodes_list)
if len(road_marks_nodes_list) > 1:
self.road_marks_with_id_dict = road_marks_with_id_dict
# self.osm_road_marks_node_tree = spatial.cKDTree(road_marks_nodes_list)
self.osm_road_marks_node_tree = KDTree(road_marks_nodes_list)
road_mark匹配(原来使用的是sklearn.cKDtree 现在改为scipy.KDtree)
mdm_osm_road_mark_matches = {}
for tile_id, tile in mdm_road_mark_data_dict.items():
for road_mark_id, mdm_road_mark in tile.items():
mdm_id = '{}-{}'.format(tile_id, road_mark_id)
way_common = -1 #存储首尾坐标点的交集
# mdm_coords = []
# osm_coords = []
# flag1 = True
# flag2 = True
way_list1 = [] # 存储shape首点对应的way_id
way_list2 = [] # 存储sahpe尾点对应的way_id
common_list = []
# way_list3 = [] # 存储shape中间点node对应的way_id
# step1 : 找到首尾点对应的way_list1,way_list2,,取交集存入common_list
points = mdm_road_mark['points']
# find matched way-id to the first node
point = points[0]
point_not_match_start = (point['lat'], point['lon'])
point = self.lla2ecef((point['lon'], point['lat'], point['alt']))
indexes1 = self.osm_road_marks_node_tree.query_radius([point], r=0.00001).tolist()
indexes1 = indexes1[0]
for index in indexes1:
way_list1.extend(self.road_marks_with_id_dict[index][1])
# find matched way-id to the last node
mdm_point = points[len(points) - 1]
mdm_point = (mdm_point['lon'], mdm_point['lat'], mdm_point['alt'])
mdm_point = self.lla2ecef(mdm_point)
indexes2 = self.osm_road_marks_node_tree.query_radius([mdm_point], r=0.00001).tolist()
indexes2 = indexes2[0]
for index in indexes2:
way_list2.extend(self.road_marks_with_id_dict[index][1])
# find the common way-ids of the first and the last nodes
for way1 in way_list1:
if way1 in way_list2:
common_list.append(way1)
common_list = list(set(common_list))
# step2:
# 如果一个mdm 的shape内的point匹配多个way对象,则进行属性sub_type匹配,来获取正确的road_mark
if len(common_list) == 2 or len(common_list) == 1:
if len(common_list) == 1:
final_common_list = [0]
messages = [[]]
else:
final_common_list = [0, 1]
messages = [[], []]
for i in range(len(common_list)):
common_road_mark = common_list[i]
osm_road_mark = self.get_way_by_id(common_road_mark)
# sub_type
if mdm_road_mark['sub_type'] in mdm_road_mark_type.values():
if self.get_tags(osm_road_mark, 'SUB_TYPE_NAME') in osm_road_mark_type:
if(self.get_tags(osm_road_mark, 'SUB_TYPE_NAME'), mdm_road_mark['sub_type']) not in osm_mdm_type.items():
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': common_list[0],
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'RoadMark 的 type 在 mxf 中是: {}, 在 mdm 中是: {}'.format(self.get_tags(osm_road_mark, 'SUB_TYPE_NAME'), mdm_road_mark['sub_type'])}
self.output_info(message)
try:
final_common_list.remove(i)
except:
pass
else:
message = {'check_type': 'match',
'feature_attribute_name': 'RoadMark',
'mdm_id': 'xxx',
'mxf_id': common_list[0],
'latitude': 'xxx',
'longitude': 'xxx',
'status': 'xxx',
'other_info': 'RoadMark 的 type 在 mxf 中是: {} , 在 mdm 中是: {}'.format(osm_road_mark['sub_type'], mdm_road_mark['sub_type'])}
messages.append(message)
# print(common_list,final_common_list)
if len(common_list) == 1 and len(final_common_list) == 0:
self.output_info(message[0])
elif len(common_list) == 2 and len(final_common_list) == 0:
message = {'check_type': 'match',
'feature_attribute_name': 'RoadMark',
'mdm_id': 'xxx',
'mxf_id': common_list[0],
'latitude': 'xxx',
'longitude': 'xxx',
'status': 'xxx',
'other_info': 'mxf-id 是{} 的 RoadMark 同时对应2条way属性均无法匹配'.format(common_list)}
self.output_info(message)
elif len(common_list) == 2 and len(final_common_list) == 2:
#看中间点对应的way 是否和首尾点对应的way一致,均相同,则可随机选择(默认取第一个)
way_list_ = []
way_list = []
for i in range(len(points)):
if i != 0 and i != len(points) - 1:
point = self.lla2ecef((points[i]['lon'], points[i]['lat'],points[i]['alt']))
indexes = self.osm_road_marks_node_tree.query_radius([point], r=0.00001).tolist()[0]
for index in indexes:
way_list_.extend(self.road_marks_with_id_dict[index][1])
way_list = list(set(way_list_))
if sorted(common_list) == sorted(way_list): # 如果首尾点交集common_list和中间点交集way_list 均相同,选择第一个进行匹配
osm_id = common_list[final_common_list[0]]
osm_road_mark = osm_road_mark_data_dict[osm_id]
if mdm_id not in mdm_osm_road_mark_matches.keys():
mdm_osm_road_mark_matches[mdm_id] = []
mdm_osm_road_mark_matches[mdm_id].append(osm_id)
# sub_type
if(osm_road_mark['sub_type'], mdm_road_mark['sub_type']) not in osm_mdm_type.items():
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'RoadMark 的 type 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_road_mark['sub_type'], mdm_road_mark['sub_type'])}
self.output_info(message)
# direction
osm_direction = None
if len(osm_road_mark['direction'].split(',')) < 2:
osm_direction = [osm_road_mark['direction']]
else:
osm_direction = osm_road_mark['direction'].split(',')
if osm_road_mark['sub_type'] == 'GuideArrow':
if len(osm_direction) == len(mdm_road_mark['direction']) and len(osm_direction) < 2:
if (osm_road_mark['direction'],mdm_road_mark['direction'][0]) not in osm_mdm_arrow.items():
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'RoadMark 的 direction 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_road_mark['direction'], mdm_road_mark['direction'])}
self.output_info(message)
elif len(osm_direction) == len(mdm_road_mark['direction']) and len(osm_direction) >= 2:
for i in range(len(osm_direction)):
if (osm_direction[i],mdm_road_mark['direction'][i]) not in osm_mdm_arrow.items():
# dircetion mxf列表['TurnRight', 'GoStraight']中的箭头位置和mdm列表['GO_STRAIGHT', 'TURN_LEFT']位置不是一一对应,则需做下列判断
if osm_direction[i] not in osm_mdm_arrow.keys() or osm_mdm_arrow[osm_direction[i]] not in mdm_road_mark['direction']:
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'RoadMark 的 direction 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_direction, mdm_road_mark['direction'])}
self.output_info(message)
break
elif len(osm_direction) != len(mdm_road_mark['direction']):
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'RoadMark 的 direction 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_direction, mdm_road_mark['direction'])}
self.output_info(message)
#ref
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
mdm_refs = mdm_road_mark['ref']
osm_refs_relation = self.find_way_relations(osm_id)
osm_ref_filted = []
for ref in osm_refs_relation:
if self.get_tags(ref, 'SUB_TYPE') == 'RoadMarkImpact':
osm_ref_filted.append(ref)
osm_refs = []
if osm_ref_filted:
for ref in osm_ref_filted:
impacteds = self.get_members_from_relation(ref, role='impacted')
if impacteds:
for member in impacteds:
osm_refs.append(member[1])
if len(osm_refs) != len(mdm_refs):
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'ref成员个数 在 mxf 中是: {}, 在 mdm 中是: {}'.format(len(osm_refs), len(mdm_refs))}
self.output_info(message)
else:
for ref in mdm_refs:
mdm_ref_id = ref.lane_id
mdm_ref_id = '{}-{}-{}'.format(mdm_ref_id.lane_group_id.road_id.tile_id.id, mdm_ref_id.lane_group_id.road_id.count, mdm_ref_id.index)
osm_ref_id = self.mdm_osm_lane_id_match.get(mdm_ref_id)
if mdm_ref_id == '0-0-0':
mdm_ref_id = ref.road_id
mdm_ref_id = '{}-{}'.format(mdm_ref_id.tile_id.id, mdm_ref_id.count)
osm_ref_id = self.mdm_osm_road_matches.get(mdm_ref_id)
if osm_ref_id is None:
osm_ref_id = '空'
if 'osm_ref_id' in locals() and osm_ref_id:
if osm_ref_id not in osm_refs:
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_ref_id,
'mxf_id': 'xxx',
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'ref成员不一致 在 mdm 中是: {}, 对应的 mxf 是: {}, 但与实际的 mxf ref成员不匹配'.format(mdm_ref_id, osm_ref_id)}
self.output_info(message)
else:
message = {'check_type': 'match',
'feature_attribute_name': 'RoadMark',
'mdm_id': 'xxx',
'mxf_id': common_list,
'latitude': 'xxx',
'longitude': 'xxx',
'status': 'xxx',
'other_info': 'mxf-id 是{} 对应2个 RoadMark ,和 mdm RoadMark shape的首尾点一致,属性一致,中间点未匹配成功'.format(common_list)}
self.output_info(message)
else:# 从common_list中的2个way里面找出1个最终属性匹配的way
way_common = common_list[final_common_list[0]]
osm_id = way_common
osm_road_mark = osm_road_mark_data_dict[osm_id]
if mdm_id not in mdm_osm_road_mark_matches.keys():
mdm_osm_road_mark_matches[mdm_id] = []
mdm_osm_road_mark_matches[mdm_id].append(osm_id)
# sub_type
if(osm_road_mark['sub_type'], mdm_road_mark['sub_type']) not in osm_mdm_type.items():
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'RoadMark 的 type 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_road_mark['sub_type'], mdm_road_mark['sub_type'])}
self.output_info(message)
# direction
osm_direction = None
if len(osm_road_mark['direction'].split(',')) < 2:
osm_direction = [osm_road_mark['direction']]
else:
osm_direction = osm_road_mark['direction'].split(',')
if osm_road_mark['sub_type'] == 'GuideArrow':
if len(osm_direction) == len(mdm_road_mark['direction']) and len(osm_direction) < 2:
if (osm_road_mark['direction'],mdm_road_mark['direction'][0]) not in osm_mdm_arrow.items():
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'RoadMark 的 direction 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_road_mark['direction'], mdm_road_mark['direction'])}
self.output_info(message)
elif len(osm_direction) == len(mdm_road_mark['direction']) and len(osm_direction) >= 2:
for i in range(len(osm_direction)):
if (osm_direction[i],mdm_road_mark['direction'][i]) not in osm_mdm_arrow.items():
# dircetion mxf列表['TurnRight', 'GoStraight']中的箭头位置和mdm列表['GO_STRAIGHT', 'TURN_LEFT']位置不是一一对应,则需做下列判断
if osm_direction[i] not in osm_mdm_arrow.keys() or osm_mdm_arrow[osm_direction[i]] not in mdm_road_mark['direction']:
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'RoadMark 的 direction 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_direction, mdm_road_mark['direction'])}
self.output_info(message)
break
elif len(osm_direction) != len(mdm_road_mark['direction']):
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'RoadMark 的 direction 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_direction, mdm_road_mark['direction'])}
self.output_info(message)
#ref
lon = osm_road_mark_data_dict[osm_id]['points'][0]['lon']
lat = osm_road_mark_data_dict[osm_id]['points'][0]['lat']
mdm_refs = mdm_road_mark['ref']
osm_refs_relation = self.find_way_relations(osm_id)
osm_ref_filted = []
for ref in osm_refs_relation:
if self.get_tags(ref, 'SUB_TYPE') == 'RoadMarkImpact':
osm_ref_filted.append(ref)
osm_refs = []
if osm_ref_filted:
for ref in osm_ref_filted:
impacteds = self.get_members_from_relation(ref, role='impacted')
if impacteds:
for member in impacteds:
osm_refs.append(member[1])
if len(osm_refs) != len(mdm_refs):
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'ref成员个数 在 mxf 中是: {}, 在 mdm 中是: {}'.format(len(osm_refs), len(mdm_refs))}
self.output_info(message)
else:
for ref in mdm_refs:
mdm_ref_id = ref.lane_id
mdm_ref_id = '{}-{}-{}'.format(mdm_ref_id.lane_group_id.road_id.tile_id.id, mdm_ref_id.lane_group_id.road_id.count, mdm_ref_id.index)
osm_ref_id = self.mdm_osm_lane_id_match.get(mdm_ref_id)
if mdm_ref_id == '0-0-0':
mdm_ref_id = ref.road_id
mdm_ref_id = '{}-{}'.format(mdm_ref_id.tile_id.id, mdm_ref_id.count)
osm_ref_id = self.mdm_osm_road_matches.get(mdm_ref_id)
if osm_ref_id is None:
osm_ref_id = '空'
if 'osm_ref_id' in locals() and osm_ref_id:
if osm_ref_id not in osm_refs:
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadMark',
'mdm_id': mdm_ref_id,
'mxf_id': 'xxx',
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'ref成员不一致 在 mdm 中是: {}, 对应的 mxf 是: {}, 但与实际的 mxf ref成员不匹配'.format(mdm_ref_id, osm_ref_id)}
self.output_info(message)
上面为改动后的代码
for mdm_road_mark in mdm_road_marks:
tile_id = mdm_road_mark.id.tile_id.id
road_mark_id = mdm_road_mark.id.count
road_mark_id_new = '{}-{}'.format(tile_id, road_mark_id)
if road_mark_id_new not in mdm_osm_road_mark_matches.keys():
lat = mdm_road_mark_data_dict[tile_id][road_mark_id]['points'][0]['lat']
lon = mdm_road_mark_data_dict[tile_id][road_mark_id]['points'][0]['lon']
message = {'check_type': 'match',
'feature_attribute_name': 'RoadMark',
'mdm_id': road_mark_id_new,
'mxf_id': 'xxx',
'latitude': lat,
'longitude': lon,
'status': 'xxx',
'other_info': 'mdm_id 是: {} 的 RoadMark 在 mxf 中找不到对应的要素'.format(road_mark_id_new)}
self.output_info(message)
road_obstacle匹配同上
mdm_osm_road_obstacle_matches = {}
for tile_id, tile in mdm_road_obstacle_data_dict.items():
for road_obstacle_id, mdm_road_obstacle in tile.items():
mdm_id = '{}-{}'.format(tile_id, road_obstacle_id)
way_list1 = [] # 存储shape首点对应的way_id
way_list2 = [] # 存储sahpe尾点node对应的way_id
way_common = [] # mdm整个shape点对应的way交集
common_list = []
# step1 : 找到首尾点对应的way_list1,way_list2,,取交集存入common_list
points = mdm_road_obstacle['point']
# find matched way-id to the first node
point = points[0]
point = self.lla2ecef((point.longitude, point.latitude, point.altitude))
indexes1 = self.osm_road_obstacles_node_tree.query_radius([point], r=0.00001).tolist()
indexes1 = indexes1[0]
for index in indexes1:
way_list1.extend(self.road_obstacles_with_id_dict[index][1])
# find matched way-id to the last node
mdm_point = points[len(points) - 1]
mdm_point = (mdm_point.longitude, mdm_point.latitude, mdm_point.altitude)
mdm_point = self.lla2ecef(mdm_point)
indexes2 = self.osm_road_obstacles_node_tree.query_radius([mdm_point], r=0.00001).tolist()
indexes2 = indexes2[0]
for index in indexes2:
way_list2.extend(self.road_obstacles_with_id_dict[index][1])
# find the common way-ids of the first and the last nodes
for way1 in way_list1:
if way1 in way_list2:
common_list.append(way1)
common_list = list(set(common_list))
# step2 : 如果一个mdm 的shape内的point匹配多个way,进行属性sub_type匹配,来获取正确的road_obstacle
if len(common_list) == 2 or len(common_list) == 1:
if len(common_list) == 1:
final_common_list = [0]
messages = [[]]
else:
final_common_list = [0, 1]
messages = [[], []]
for i in range(len(common_list)):
common_road_obstacle = common_list[i]
osm_id = common_road_obstacle
osm_road_obstacle = osm_road_obstacle_data_dict[osm_id]
# osm_road_obstacle = self.get_way_by_id(osm_id)
# sub_type
if str(mdm_road_obstacle['sub_type']) in mdm_road_obstacle_type.keys():
if osm_road_obstacle['sub_type'] in osm_road_obstacle_type:
if(osm_road_obstacle['sub_type'], mdm_road_obstacle_type[str(mdm_road_obstacle['sub_type'])]) not in osm_mdm_type.items():
osm_nodes = osm_road_obstacle_data_dict[osm_id]['nodes']
other_info = 'RoadObstacle 的 road_obstacle_type 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_road_obstacle['sub_type']\
, mdm_road_obstacle_type.get(str(mdm_road_obstacle['sub_type'])))
if osm_road_obstacle['sub_type'] == 'LackOfSubType':
other_info = 'RoadObstacle 的 road_obstacle_type 在 mxf中缺少 SUB_TYPE_NAME 字段, 在 mdm 中是: {}'.format(mdm_road_obstacle_type.get(str(mdm_road_obstacle['sub_type'])))
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadObstacle',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': osm_nodes[1]['lat'],
'longitude': osm_nodes[1]['lon'],
'status': 'xxx',
'other_info': other_info}
self.output_info(message)
try:
final_common_list.remove(i)
except:
pass
else:
message = {'check_type': 'match',
'feature_attribute_name': 'RoadObstacle',
'mdm_id': 'xxx',
'mxf_id': common_list[0],
'latitude': 'xxx',
'longitude': 'xxx',
'status': 'xxx',
'other_info': 'RoadObstacle 的 type 在 mxf 中是: {} , 在 mdm 中是: {}'.format(osm_road_obstacle['sub_type'], mdm_road_obstacle_type.get(str(mdm_road_obstacle['sub_type'])))}
messages.append(message)
if len(common_list) == 1 and len(final_common_list) == 0:
self.output_info(message[0])
elif len(common_list) == 2 and len(final_common_list) == 0:
message = {'check_type': 'match',
'feature_attribute_name': 'RoadObstacle',
'mdm_id': 'xxx',
'mxf_id': common_list[0],
'latitude': 'xxx',
'longitude': 'xxx',
'status': 'xxx',
'other_info': 'mxf-id 是{} 的 RoadObstacle 同时对应2条way属性均无法匹配'.format(common_list)}
self.output_info(message)
elif len(common_list) == 2 and len(final_common_list) == 2:
#首尾点对应的way相同,且way的type属性一致,看中间点和首尾点对应的way有交集。有则取交集,交集为多个时,则默认取第一个;无则报出
way_list_ = []
way_list = []
for i in range(len(points)):
if i != 0 and i != len(points) - 1:
mdm_point_new = (points[i].latitude, points[i].longitude)
point = self.lla2ecef((points[i].longitude, points[i].latitude,points[i].altitude))
# index = self.osm_road_facilities_node_tree.query([point])[1][0][0]
indexes = self.osm_road_obstacles_node_tree.query_radius([point], r=0.00001).tolist()[0]
for index in indexes:
way_list_.extend(self.road_obstacles_with_id_dict[index][1])
way_list = list(set(way_list_))
way_common = list(set(common_list).intersection(set(way_list)))
# print(way_common)
if len(way_common): # 如果首尾点和中间点交集way_common不为空,选择第一个进行匹配(osm可能存在多个重复的way,默认选择一个)
osm_id = way_common[0]
if mdm_id not in mdm_osm_road_obstacle_matches.keys():
mdm_osm_road_obstacle_matches[mdm_id] = []
mdm_osm_road_obstacle_matches[mdm_id].append(osm_id)
# sub_type
if(osm_road_obstacle['sub_type'], mdm_road_obstacle_type[str(mdm_road_obstacle['sub_type'])]) not in osm_mdm_type.items():
osm_nodes = osm_road_obstacle_data_dict[osm_id]['nodes']
other_info = 'RoadObstacle 的 road_obstacle_type 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_road_obstacle['sub_type']\
, mdm_road_obstacle_type.get(str(mdm_road_obstacle['sub_type'])))
if osm_road_obstacle['sub_type'] == 'LackOfSubType':
other_info = 'RoadObstacle 的 road_obstacle_type 在 mxf中缺少 SUB_TYPE_NAME 字段, 在 mdm 中是: {}'.format(mdm_road_obstacle_type.get(str(mdm_road_obstacle['sub_type'])))
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadObstacle',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': osm_nodes[1]['lat'],
'longitude': osm_nodes[1]['lon'],
'status': 'xxx',
'other_info': other_info}
self.output_info(message)
#ref
mdm_refs = mdm_road_obstacle['ref']
osm_refs_relation = self.find_way_relations(osm_id)
osm_ref_filted = []
for ref in osm_refs_relation:
if self.get_tags(ref, 'SUB_TYPE') == 'StaticBlockImpact':
osm_ref_filted.append(ref)
osm_refs = []
if osm_ref_filted:
for ref in osm_ref_filted:
impacteds = self.get_members_from_relation(ref, role='impacted')
if impacteds:
for member in impacteds:
osm_refs.append(member[1])
if len(osm_refs) != len(mdm_refs):
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadObstacle',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': osm_nodes[1]['lat'],
'longitude': osm_nodes[1]['lon'],
'status': 'xxx',
'other_info': 'ref成员个数 在 mxf 中是: {}, 在 mdm 中是: {}'.format(len(osm_refs), len(mdm_refs))}
self.output_info(message)
else:
for ref in mdm_refs:
mdm_ref_id = ref.lane_id
mdm_ref_id = '{}-{}-{}'.format(mdm_ref_id.lane_group_id.road_id.tile_id.id, mdm_ref_id.lane_group_id.road_id.count, mdm_ref_id.index)
osm_ref_id = self.mdm_osm_lane_id_match.get(mdm_ref_id)
if mdm_ref_id == '0-0-0':
mdm_ref_id = ref.road_id
mdm_ref_id = '{}-{}'.format(mdm_ref_id.tile_id.id, mdm_ref_id.count)
osm_ref_id = self.mdm_osm_road_matches.get(mdm_ref_id)
if osm_ref_id is None:
osm_ref_id = '空'
if 'osm_ref_id' in locals() and osm_ref_id:
if osm_ref_id not in osm_refs:
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadObstacle',
'mdm_id': mdm_ref_id,
'mxf_id': 'xxx',
'latitude': osm_nodes[1]['lat'],
'longitude': osm_nodes[1]['lon'],
'status': 'xxx',
'other_info': 'ref成员不一致 在 mdm 中是: {}, 对应的 mxf 是: {}, 但与实际的 mxf ref成员不匹配'.format(mdm_ref_id, osm_ref_id)}
self.output_info(message)
else:
print(common_list,way_list)
message = {'check_type': 'match',
'feature_attribute_name': 'RoadObstacle',
'mdm_id': 'xxx',
'mxf_id': common_list,
'latitude': 'xxx',
'longitude': 'xxx',
'status': 'xxx',
'other_info': 'mxf-id 是{} shape的首尾点一致,属性一致 ,有相同的中间点导致未匹配成功'.format(common_list)}
self.output_info(message)
elif len(common_list) == 1 and len(final_common_list) == 1:
way_common = common_list[0]
osm_id = way_common
osm_road_obstacle = osm_road_obstacle_data_dict[osm_id]
if mdm_id not in mdm_osm_road_obstacle_matches.keys():
mdm_osm_road_obstacle_matches[mdm_id] = []
mdm_osm_road_obstacle_matches[mdm_id].append(osm_id)
# sub_type
if(osm_road_obstacle['sub_type'], mdm_road_obstacle_type[str(mdm_road_obstacle['sub_type'])]) not in osm_mdm_type.items():
osm_nodes = osm_road_obstacle_data_dict[osm_id]['nodes']
other_info = 'RoadObstacle 的 road_obstacle_type 在 mxf 中是: {}, 在 mdm 中是: {}'.format(osm_road_obstacle['sub_type']\
, mdm_road_obstacle_type.get(str(mdm_road_obstacle['sub_type'])))
if osm_road_obstacle['sub_type'] == 'LackOfSubType':
other_info = 'RoadObstacle 的 road_obstacle_type 在 mxf中缺少 SUB_TYPE_NAME 字段, 在 mdm 中是: {}'.format(mdm_road_obstacle_type.get(str(mdm_road_obstacle['sub_type'])))
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadObstacle',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': osm_nodes[1]['lat'],
'longitude': osm_nodes[1]['lon'],
'status': 'xxx',
'other_info': other_info}
self.output_info(message)
#ref
mdm_refs = mdm_road_obstacle['ref']
osm_refs_relation = self.find_way_relations(osm_id)
osm_ref_filted = []
for ref in osm_refs_relation:
if self.get_tags(ref, 'SUB_TYPE') == 'StaticBlockImpact':
osm_ref_filted.append(ref)
osm_refs = []
if osm_ref_filted:
for ref in osm_ref_filted:
impacteds = self.get_members_from_relation(ref, role='impacted')
if impacteds:
for member in impacteds:
osm_refs.append(member[1])
if len(osm_refs) != len(mdm_refs):
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadObstacle',
'mdm_id': mdm_id,
'mxf_id': osm_id,
'latitude': osm_nodes[1]['lat'],
'longitude': osm_nodes[1]['lon'],
'status': 'xxx',
'other_info': 'ref成员个数 在 mxf 中是: {}, 在 mdm 中是: {}'.format(len(osm_refs), len(mdm_refs))}
self.output_info(message)
else:
for ref in mdm_refs:
mdm_ref_id = ref.lane_id
mdm_ref_id = '{}-{}-{}'.format(mdm_ref_id.lane_group_id.road_id.tile_id.id, mdm_ref_id.lane_group_id.road_id.count, mdm_ref_id.index)
osm_ref_id = self.mdm_osm_lane_id_match.get(mdm_ref_id)
if mdm_ref_id == '0-0-0':
mdm_ref_id = ref.road_id
mdm_ref_id = '{}-{}'.format(mdm_ref_id.tile_id.id, mdm_ref_id.count)
osm_ref_id = self.mdm_osm_road_matches.get(mdm_ref_id)
if osm_ref_id is None:
osm_ref_id = '空'
if 'osm_ref_id' in locals() and osm_ref_id:
if osm_ref_id not in osm_refs:
message = {'check_type': 'value_diff',
'feature_attribute_name': 'RoadObstacle',
'mdm_id': mdm_ref_id,
'mxf_id': 'xxx',
'latitude': osm_nodes[1]['lat'],
'longitude': osm_nodes[1]['lon'],
'status': 'xxx',
'other_info': 'ref成员不一致 在 mdm 中是: {}, 对应的 mxf 是: {}, 但与实际的 mxf ref成员不匹配'.format(mdm_ref_id, osm_ref_id)}
self.output_info(message)