Ejemplo n.º 1
0
def find_all_intersection(street_list):
    intersection_list = []
    tmp_street_list = street_list.copy()
    for key_main, value_main in street_list.iteritems():
        index_main = 0
        tmp_street_list.pop(key_main)
        for ponits_main in value_main:
            if index_main <= (len(value_main)-2):
                src = intersect.Point(value_main[index_main][0], value_main[index_main][1])
                dst = intersect.Point(value_main[index_main+1][0], value_main[index_main+1][1])
                index_main = index_main+1
                l1 = intersect.Line(src, dst)
                for key_sub, value_sub in tmp_street_list.iteritems():
                    index_sub = 0
                    for points_sub in value_sub:
                        if index_sub <= (len(value_sub) - 2):
                            src = intersect.Point(value_sub[index_sub][0], value_sub[index_sub][1])
                            dst = intersect.Point(value_sub[index_sub + 1][0], value_sub[index_sub + 1][1])
                            l2 = intersect.Line(src, dst)
                            intersect_point = intersect.intersect(l1,l2)
                            index_sub = index_sub + 1
                            if intersect_point != None and type(intersect_point) != list and (not check_exist_point(intersection_list,intersect_point)):
                                intersection_list.append((intersect_point.x,intersect_point.y))
                            elif intersect_point != None and type(intersect_point) == list:
                                for i in range(0, len(intersect_point)):
                                    tmp_point = intersect.Point(intersect_point[i][0],intersect_point[i][1])
                                    if not check_exist_point(intersection_list,tmp_point):
                                        intersection_list.append((tmp_point.x,tmp_point.y))
    return intersection_list
Ejemplo n.º 2
0
def creat_street(sp):
    numbers_rx = r'(-?[0-9]+)'
    text_rx = r'(\W)'
    i = 2
    vertices = []
    edges = []
    street_name = re.sub(text_rx,' ', sp[1]).lower()
    #print 'street name', street_name
    for i in range (2, len(sp)):
        cor = re.findall(numbers_rx, sp[i])
        if len(cor)==2:
            cor_x=int(cor[0])
            cor_y=int(cor[1])
            vertices.append(intersect.Point(cor_x, cor_y))
        else:
            return -1

    j = 0
    for j in range (0, len(vertices)-1):
        edges.append(intersect.Line(vertices[j], vertices[j+1]))


    street=street_object(street_name, vertices, edges)

    return street
Ejemplo n.º 3
0
def cal_street_point(street_list,intersection_list):
    tmp_street_list = street_list.copy()
    street_point_list= {}
    index = 1
    for name, lines in tmp_street_list.iteritems():
        for i in range(0, len(lines) - 1):
            tmp_street_point_list = []
            count = 0
            src = intersect.Point(lines[i][0], lines[i][1])
            dst = intersect.Point(lines[i + 1][0], lines[i + 1][1])
            line = intersect.Line(src, dst)
            for point in intersection_list:
                intersect_point = intersect.Point(point[0],point[1])
                #print(intersect_point.x, intersect_point.y)
                if point_check(intersect_point, line):
                    if count == 0:
                        tmp_street_point_list.append((src.x,src.y))
                        tmp_street_point_list.append((dst.x,dst.y))
                        count = count + 1
                    if not check_exist_point(tmp_street_point_list, intersect_point):
                        tmp_street_point_list.append((intersect_point.x,intersect_point.y))
            if len(tmp_street_point_list)> 0:
                street_point_list[index] = tmp_street_point_list
                index = index + 1
    return street_point_list
Ejemplo n.º 4
0
    def generateGraph(self):
        points_dict = {}
        #print 'street dict  ---------------------',self.street_dict
        for key in self.street_dict:
            i = 0
            point_list = []
            while i < len(self.street_dict[key]):
                point = intersect.Point(self.street_dict[key][i][0],
                                        self.street_dict[key][i][1])
                i += 1
                point_list.append(point)
            points_dict[key] = point_list

        lines_dict = {}
        complete_lines = []
        for key in points_dict:
            i = 0
            line_list = []
            while i < len(points_dict[key]) - 1:
                #print points_dict[key][i]
                #print points_dict[key][i+1]
                line = intersect.Line(points_dict[key][i],
                                      points_dict[key][i + 1])
                #print line
                #line = intersect.Line(self.street_dict[key][0],self.street_dict[key][1])
                i += 1
                line_list.append(line)
            lines_dict[key] = line_list
            complete_lines.append(line_list)

        #find intersect
        final_intersects = []
        final_edges = []
        intersection_points = []
        #print "length :"+str(len(complete_lines))
        for i in range(0, len(complete_lines)):
            for k in range(i + 1, len(complete_lines)):
                for j in range(0, len(complete_lines[i])):
                    for m in range(0, len(complete_lines[k])):
                        #print "before function call"
                        point = intersect.intersect(complete_lines[i][j],
                                                    complete_lines[k][m])
                        if (point != -1):
                            final_intersects = final_intersects + point[0]
                            final_edges = final_edges + point[1]
                            if len(point) == 3:
                                intersection_points.append(point[2])
        #print final_intersects

        intersections = []
        for i in intersection_points:
            intersections.append(i[0])

        #print final_edges

        #print "intersections ::",intersections
        new_edges = []
        for edge in final_edges:
            for vertex in intersections:
                isBetween = self.isVertexInBetween(edge[0], edge[1], vertex)
                if isBetween and edge[0] != vertex and edge[1] != vertex:
                    new_edge1 = [edge[0], vertex]
                    new_edge2 = [edge[1], vertex]
                    new_edges.append(new_edge1)
                    new_edges.append(new_edge2)

        #print "new edges   ",new_edges
        final_edges = final_edges + new_edges

        edges_remove_dup = []
        #edges_remove_dup.extend(final_edges)
        #print "edges_remove_dup before-------->",edges_remove_dup
        for a in final_edges:
            l = [a[1], a[0]]
            if a not in edges_remove_dup and l not in edges_remove_dup and l != a:
                edges_remove_dup.append(a)
        #print "edges_remove_dup after-------->",edges_remove_dup
        b_set = set(
            (map(tuple, edges_remove_dup))
        )  #need to convert the inner lists to tuples so they are hashable
        b = map(list, b_set)
        #print "intersection points :::::",intersection_points

        #final_intersects = [(0.0,0.0)]
        self.getVerticesOutput(final_intersects)
        self.getEdgesOutput(b, intersection_points,
                            list(set(final_intersects)))