예제 #1
0
def center_1():
    """
    某些道路制作过度,center1线出现折返情况
    按照最左点为第一个点
    :return: 
    """
    road_data = load_model('./road/center1.txt')
    mod_road = {
        39, 32 / 2, 58 / 2, 62 / 2, 196 / 2, 234 / 2, 292 / 2, 1016 / 2,
        1112 / 2
    }
    new_road_data = []
    # 修改
    for road in road_data:
        polyline = road['polyline']
        name = road['name']
        rid = road['rid']
        if rid not in mod_road:
            new_road_data.append(road)
            continue
        xy_list = polyline2xylist(polyline)
        new_xy_list = []

        # 对每个点找出最接近的那个点
        min_x = 1e10
        for x, y in xy_list:
            if x < min_x:
                min_x, last_xy = x, [x, y]
        # last_xy = xy_list[0]
        # new_xy_list.append(last_xy)
        # del xy_list[0]
        len_list = len(xy_list)
        for i in range(len_list):
            min_dist, sel = 1e10, -1
            for j, xy in enumerate(xy_list):
                dist = calc_dist(last_xy, xy)
                if dist < min_dist:
                    min_dist, sel = dist, j
            last_xy = xy_list[sel]
            new_xy_list.append(last_xy)
            del xy_list[sel]
        new_xy_list = reversed(new_xy_list)
        # 去重
        temp_list = []
        last_xy = [0, 0]
        for x, y in new_xy_list:
            if x == last_xy[0] and y == last_xy[1]:
                print 'duplicated', name
                continue
            temp_list.append([x, y])
            last_xy = [x, y]
        new_xy_list = temp_list
        road['polyline'] = xylist2polyline(new_xy_list)
        new_road_data.append(road)

    save_model('./road/center1.txt', new_road_data)
예제 #2
0
def center():
    road_data = load_model('./road/merge.txt')
    road_dict = {}
    for road_info in road_data:
        name = road_info['name']
        try:
            road_dict[name].append(road_info)
        except KeyError:
            road_dict[name] = [road_info]

    temp_list = load_model('./road/center.txt')
    exist_road = []
    for road_info in temp_list:
        name = road_info['name']
        exist_road.append(name)
    road_center_list = temp_list
    for name, road_list in road_dict.iteritems():
        if name in exist_road:
            continue
        xy_list = grid_center_line(name, road_list)
        polyline = xylist2polyline(xy_list)
        center_line = {'name': name, 'polyline': polyline}
        road_center_list.append(center_line)
    save_model('./road/center.txt', road_center_list)
예제 #3
0
def center_5():
    """
    修正曲折道路
    """
    road_data = load_model('./road/center.txt')
    mod_road = {51}
    new_road_data = []
    for road in road_data:
        polyline = road['polyline']
        name = road['name']
        rid = int(road['rid'])
        if rid in mod_road:
            print name, rid, 'modified'
        else:
            new_road_data.append(road)
            continue
        xy_list = polyline2xylist(polyline)
        new_xy_list = []
        # 和2的不同是,确定最后一个点是正确的点
        # 一旦越界,则不再继续
        last_xy, final_xy = xy_list[0], xy_list[-1]
        first_xy = last_xy[:]
        final_dist = calc_dist(last_xy, final_xy)
        new_xy_list.append(last_xy)
        del xy_list[0]
        del xy_list[-1]
        len_list = len(xy_list)
        for i in range(len_list - 1):
            min_dist, sel = 1e10, -1
            for j, xy in enumerate(xy_list):
                dist = calc_dist(last_xy, xy)
                if dist < min_dist:
                    min_dist, sel = dist, j
            off_dist = calc_dist(xy_list[sel], first_xy)
            if off_dist > final_dist:
                break
            last_xy = xy_list[sel]
            new_xy_list.append(last_xy)
            del xy_list[sel]
        del new_xy_list[7]
        new_xy_list.append(final_xy)

        road['polyline'] = xylist2polyline(new_xy_list)
        new_road_data.append(road)

    save_model('./road/center_.txt', new_road_data)
예제 #4
0
def main():
    raw_data = load_model('./road/raw.txt')
    road_set = set()
    for road in raw_data:
        road_set.add(road['name'].encode('utf-8'))
    print len(road_set)
    fp0 = open('./road/road_name.txt')
    road_list = []
    for line in fp0.readlines():
        road_name = line.strip('\n')
        if road_name not in road_set:
            road_list.append(road_name)

    fp = open('./road/raw.txt', 'w')
    for road_name in road_list:
        res = process_traffic_status(road_name)
        if res is not None:
            raw_data.extend(res)
    js = json.dumps(raw_data, ensure_ascii=False).encode('utf-8')
    fp.write(js)
    fp.write('\n')
    fp.close()
예제 #5
0
def center_6():
    """
    删除道路上的某个点
    """
    road_data = load_model('./road/center.txt')
    mod_road = {51}
    new_road_data = []
    for road in road_data:
        polyline = road['polyline']
        name = road['name']
        rid = int(road['rid'])
        if rid in mod_road:
            print name, rid, 'modified'
        else:
            new_road_data.append(road)
            continue
        xy_list = polyline2xylist(polyline)
        del xy_list[11]
        road['polyline'] = xylist2polyline(xy_list)
        new_road_data.append(road)

    save_model('./road/center_.txt', new_road_data)
예제 #6
0
def center_2():
    """
    修正曲折道路
    最后再去除重复点
    :return: 
    """
    road_data = load_model('./road_new/center1.txt')
    # mod_road = {54}
    new_road_data = []
    for road in road_data:
        polyline = road['polyline']
        name = road['name']
        # rid = int(road['rid'])
        xy_list = polyline2xylist(polyline)
        new_xy_list = []

        # 先找出最接近的那个点
        last_xy = xy_list[0]
        new_xy_list.append(last_xy)
        del xy_list[0]
        len_list = len(xy_list)
        for i in range(len_list):
            min_dist, sel = 1e10, -1
            for j, xy in enumerate(xy_list):
                dist = calc_dist(last_xy, xy)
                if dist < min_dist:
                    min_dist, sel = dist, j
            last_xy = xy_list[sel]
            new_xy_list.append(last_xy)
            del xy_list[sel]
        new_xy_list = reversed(new_xy_list)
        # 去重
        temp_list = []
        last_xy = [0, 0]
        for x, y in new_xy_list:
            if x == last_xy[0] and y == last_xy[1]:
                print 'duplicated', name
                continue
            temp_list.append([x, y])
            last_xy = [x, y]
        new_xy_list = temp_list
        xy_list = new_xy_list[:]
        new_xy_list = []

        # 再来一遍
        last_xy = xy_list[0]
        new_xy_list.append(last_xy)
        del xy_list[0]
        len_list = len(xy_list)
        for i in range(len_list):
            min_dist, sel = 1e10, -1
            for j, xy in enumerate(xy_list):
                dist = calc_dist(last_xy, xy)
                if dist < min_dist:
                    min_dist, sel = dist, j
            last_xy = xy_list[sel]
            new_xy_list.append(last_xy)
            del xy_list[sel]
        new_xy_list = reversed(new_xy_list)
        # 去重
        temp_list = []
        last_xy = [0, 0]
        for x, y in new_xy_list:
            if x == last_xy[0] and y == last_xy[1]:
                print 'duplicated', name
                continue
            temp_list.append([x, y])
            last_xy = [x, y]
        new_xy_list = temp_list

        road['polyline'] = xylist2polyline(new_xy_list)
        new_road_data.append(road)

    save_model('./road_new/center1.txt', new_road_data)