Example #1
0
def center_merge(road0, road1):
    """
    检查端点是否重合
    :return:
    """
    MERGE_DIST = 1000
    r0s0, r0s1 = road0.seg_list[0], road0.seg_list[-1]
    r1s0, r1s1 = road1.seg_list[0], road1.seg_list[-1]
    r0_bp, r0_ep = road0.point_list[0], road0.point_list[-1]
    r1_bp, r1_ep = road1.point_list[0], road1.point_list[-1]
    if get_dist(r0_bp, r1_ep) < MERGE_DIST and calc_include_angle2(r0s0,
                                                                   r1s1) > 0.8:
        # 头尾相接,并且平行,说明是在同一条道路里面
        road1.add_point(r0_bp)
        road1.gene_segment()
        road1.es, road0.bs = 1, 1
    elif get_dist(r1_bp, r0_ep) < MERGE_DIST and calc_include_angle2(
            r1s0, r0s1) > 0.8:
        road0.add_point(r1_bp)
        road0.gene_segment()
        road0.es, road1.bs = 1, 1
    elif get_dist(r0_bp, r1_bp) < MERGE_DIST and calc_include_angle2(
            r0s0, r1s0) > 0.8:
        # 有时遇到单芯线
        new_point_list = [r1_bp]
        for pt in road0.point_list:
            new_point_list.append(pt)
        road0.set_point_list(new_point_list)
        road0.gene_segment()
        road0.bs, road1.es = 1, 1
    elif get_dist(r0_ep, r1_ep) < MERGE_DIST and calc_include_angle2(
            r0s1, r1s1) > 0.8:
        road0.add_point(r1_ep)
        road0.gene_segment()
        road0.es, road1.bs = 1, 1
Example #2
0
def center_divide(road0, road1):
    bp0, ep0, bp1, ep1 = road0.point_list[0], road0.point_list[
        -1], road1.point_list[0], road1.point_list[-1]
    if bp0 == bp1 or bp0 == ep1 or ep0 == bp1 or ep0 == ep1:
        return
    for i, seg0 in enumerate(road0.seg_list):
        for j, seg1 in enumerate(road1.seg_list):
            if calc_include_angle2(
                    seg0, seg1) < math.sqrt(3) / 2 and is_segment_cross(
                        seg0, seg1):
                _, px, py = get_cross_point(seg0, seg1)
                if px is None:
                    print 'None'
                cr0 = Point(px, py)
                cr0.cross, cr0.cross_name, cr0.cross_other_seg = 1, road1.name, j
                cr0.cross_seg = i
                bp, ep = seg0.begin_point, seg0.end_point
                w0, w1 = get_dist(cr0, bp), get_dist(cr0, ep)
                if w0 > 1e-5 and w1 > 1e-5:
                    road0.cross_list.append(cr0)

                cr1 = Point(px, py)
                cr1.cross, cr1.cross_name, cr1.cross_other_seg = 1, road0.name, i
                cr1.cross_seg = j
                bp, ep = seg1.begin_point, seg1.end_point
                w0, w1 = get_dist(cr1, bp), get_dist(cr1, ep)
                if w0 > 1e-5 and w1 > 1e-5:
                    road1.cross_list.append(cr1)
                return
Example #3
0
def center_cross(road0, road1):
    """
    检查道路与其他道路的交叉,并且合并交叉点
    只有在道路尽头才会发生,因此和其他道路如有merge,应该不进行操作
    :param road0: Road
    :param road1: Road
    :return:
    """
    bp, ep = road0.point_list[0], road0.point_list[-1]
    min_dist = 1e10
    sel_seg = None
    for seg in road1.seg_list:
        dist = point2segment2(bp, seg)
        if dist < min_dist:
            min_dist, sel_seg = dist, seg
    if min_dist < 50:
        if road0.bs == 1:
            return
        if is_segment_cross(road0.seg_list[0], sel_seg) or calc_include_angle2(
                road0.seg_list[0], sel_seg) > 0.8:
            return
        _, px, py = get_cross_point(road0.seg_list[0], sel_seg)
        new_point_list = [Point(px, py)]
        for pt in road0.point_list:
            new_point_list.append(pt)
        road0.set_point_list(new_point_list)
        road0.gene_segment()
        return

    min_dist = 1e10
    sel_seg = None
    for seg in road1.seg_list:
        dist = point2segment2(ep, seg)
        if dist < min_dist:
            min_dist, sel_seg = dist, seg
    if min_dist < 50:
        if road0.es == 1:
            return
        if is_segment_cross(road0.seg_list[-1],
                            sel_seg) or calc_include_angle2(
                                road0.seg_list[-1], sel_seg) > 0.8:
            return
        _, px, py = get_cross_point(road0.seg_list[-1], sel_seg)
        road0.add_point(Point(px, py))
        road0.gene_segment()
Example #4
0
def par_cross(road0, road1):
    """
    类似par divide,但是要标记每个pt点的进出路口情况
    :param road0: 
    :param road1: 
    :return: 
    """
    rid0, rid1 = road0.rid, road1.rid
    rbp0, rep0, rbp1, rep1 = road0.point_list[0], road0.point_list[
        -1], road1.point_list[0], road1.point_list[-1]
    if rbp0 == rbp1 or rbp0 == rep1 or rep0 == rbp1 or rep0 == rep1:
        return
    for i, seg0 in enumerate(road0.seg_list):
        for j, seg1 in enumerate(road1.seg_list):
            if calc_include_angle2(seg0, seg1) > 0.8:  # 平行
                continue
            if is_segment_cross(seg0, seg1):
                d, px, py = get_cross_point(seg0, seg1)
                bp0, ep0 = seg0.begin_point, seg0.end_point
                bp1, ep1 = seg1.begin_point, seg1.end_point
                cr = Point(px, py)
                if bp0 == cr:
                    if cr == rep1 or cr == rbp1:
                        pass
                    else:
                        if d < 0:
                            road0.point_list[i].cross = 1
                        else:
                            road0.point_list[i].cross = 2
                elif ep0 == cr:
                    if cr == rep1 or cr == rbp1:
                        pass
                    else:
                        if d < 0 and not ():
                            road0.point_list[i + 1].cross = 1
                        else:
                            road0.point_list[i + 1].cross = 2
                if bp1 == cr:
                    if cr == rep0 or cr == rbp0:
                        pass
                    else:
                        if d < 0:
                            road1.point_list[j].cross = 2
                        else:
                            road1.point_list[j].cross = 1
                elif ep1 == cr:
                    if cr == rep0 or cr == rbp0:
                        pass
                    else:
                        if d < 0:
                            road1.point_list[j + 1].cross = 2
                        else:
                            road1.point_list[j + 1].cross = 1
                return
Example #5
0
def par_divide(road0, road1):
    """
    as center divide, divide cross point for each other
    :param road0:
    :param road1:
    :return:
    """
    bp0, ep0, bp1, ep1 = road0.point_list[0], road0.point_list[
        -1], road1.point_list[0], road1.point_list[-1]
    if bp0 == bp1:
        road0.bs, road1.bs = 1, 1
        return
    elif bp0 == ep1:
        road0.bs, road1.es = 1, 1
        return
    elif ep0 == bp1:
        road0.es, road1.bs = 1, 1
        return
    elif ep0 == ep1:
        road0.es, road1.es = 1, 1
        return
    for i, seg0 in enumerate(road0.seg_list):
        for j, seg1 in enumerate(road1.seg_list):
            if calc_include_angle2(seg0, seg1) > 0.8:  # 平行
                continue
            if is_segment_cross(seg0, seg1):
                _, px, py = get_cross_point(seg0, seg1)
                cr0 = Point(px, py)
                cr0.cross, cr0.cross_name, cr0.cross_other_seg = 1, road1.rid, j
                cr0.cross_seg = i
                bp, ep = seg0.begin_point, seg0.end_point
                w0, w1 = get_dist(cr0, bp), get_dist(cr0, ep)
                if w0 > 1e-5 and w1 > 1e-5:
                    road0.cross_list.append(cr0)

                cr1 = Point(px, py)
                cr1.cross, cr1.cross_name, cr1.cross_other_seg = 1, road0.rid, i
                cr1.cross_seg = j
                bp, ep = seg1.begin_point, seg1.end_point
                w0, w1 = get_dist(cr1, bp), get_dist(cr1, ep)
                if w0 > 1e-5 and w1 > 1e-5:
                    road1.cross_list.append(cr1)
                return
Example #6
0
def par_merge(road0, road1):
    """
    一条线段的起点与另一条(平行线段)的终点相接
    :param road0: 
    :param road1: 
    :return: road0, road1重新生成道路
    """
    THREAD = 10
    bp0, ep0, bp1, ep1 = road0.point_list[0], road0.point_list[
        -1], road1.point_list[0], road1.point_list[-1]
    try:
        if bp0 == ep1 or bp1 == ep0:
            return
    except TypeError:
        print 'par merge', road0.rid, road1.rid, 'TypeError'
        return
    # 在生成平行线后两条道路之间必然(除非是一直线上)有空隙或者交叉
    # 这个THREAD值不能太大,否则和对向车道也能查找到一起
    if get_dist(bp0, ep1) < THREAD:
        begin_seg, end_seg = road0.seg_list[0], road1.seg_list[-1]
        # 首先是平行
        if calc_include_angle2(begin_seg, end_seg) <= 0.8:
            return
        if is_segment_cross(begin_seg, end_seg):
            # 相交时cut
            _, px, py = get_cross_point(begin_seg, end_seg)
            cr = Point(px, py)
            road0.point_list[0] = cr
            road1.point_list[-1] = cr
            road0.gene_segment()
            road1.gene_segment()
        else:
            # 不相交时延长
            _, px, py = get_cross_point(begin_seg, end_seg)
            cr = Point(px, py)
            pt_list = [cr]
            pt_list.extend(road0.point_list)
            road0.point_list = pt_list
            road1.point_list.append(cr)
            road0.gene_segment()
            road1.gene_segment()
    elif get_dist(bp1, ep0) < THREAD:
        begin_seg, end_seg = road1.seg_list[0], road0.seg_list[-1]
        # 首先是平行
        if calc_include_angle2(begin_seg, end_seg) <= 0.8:
            return
        if is_segment_cross(begin_seg, end_seg):
            # 相交时cut
            _, px, py = get_cross_point(begin_seg, end_seg)
            cr = Point(px, py)
            road1.point_list[0] = cr
            road0.point_list[-1] = cr
            road0.gene_segment()
            road1.gene_segment()
        else:
            # 不相交时延长
            _, px, py = get_cross_point(begin_seg, end_seg)
            cr = Point(px, py)
            pt_list = [cr]
            pt_list.extend(road1.point_list)
            road1.point_list = pt_list
            road0.point_list.append(cr)
            road0.gene_segment()
            road1.gene_segment()