Exemplo n.º 1
0
def is_on_line(point1, point2, lat, lon):

    #m1 = (lat - point1.lat) / (lon - point1.lon)
    #m2 = (lat - point2.lat) / (lon - point2.lon)
    #if m1 == m2:
    #    print("exacly on line")
    point12dis = Point.calc_distance(point1, point2)

    tempPoint = Point(lat, lon, -1)
    a = Point.calc_distance(point1, tempPoint) + Point.calc_distance(
        tempPoint, point2)
    if (abs(point12dis - a) < 0.00001):
        return True
    return False
Exemplo n.º 2
0
def split_to_sections(points_list, nodes_info) -> list:
    """

    :param points_list: list of points of type Point (from Section)

    :return list of sections, such that each geographical parameter is valid to all of it
    """
    sections = []

    start = points_list[0]
    info = fetch_point_info(start, nodes_info)
    sec = create_section_from_info(info)
    sections.append(sec)

    for point in points_list[1:]:
        info = fetch_point_info(point, nodes_info)
        if info:
            next_sec = create_section_from_info(info)
            if Section.check_if_dff(sec, next_sec):
                sections.append(next_sec)
            sec = next_sec

    start_sec = sections[0]
    for section in sections[1:]:
        end_sec = section
        start_sec.end_point = end_sec.start_point
        start_sec.length = Point.calc_distance(start_sec.start_point, start_sec.end_point)
        start_sec = end_sec

    return sections
Exemplo n.º 3
0
def get_points_between_two_points(point1, point2):
    (lat1, lon1), (lat2, lon2) = (point1.lat, point1.lon), (point2.lat,
                                                            point2.lon)
    url = "http://api.openstreetmap.org/api/0.6/map?bbox=%s,%s,%s,%s" % (min(
        lon1, lon2), min(lat1, lat2), max(lon1, lon2), max(lat1, lat2))
    osm_text = urllib.request.urlopen(url).read()

    soup = bs4.BeautifulSoup(osm_text, "lxml")
    print(soup)
    # print( soup")
    # print(soup)
    nodes = soup.findAll("node")
    print(len(nodes))
    points = []
    for node in nodes:  # 1184053312
        # print("next node:")
        # print(node)
        # print("\n\n\n")
        name_tag = node.find("tag")  # attrs={'k': 'name'})
        # print("name_tag",name_tag)
        if name_tag:
            lat = float(node.get("lat"))
            lon = float(node.get("lon"))
            name = name_tag.get("v")
            # print("name",name)
            # print(node.get("uid"))
            timestamp = int(time.time())
            points.append(Point(lat, lon, node.get("uid")))
    return points
Exemplo n.º 4
0
def create_points_list(points_list):
    """

    :param points_list: len >= 1
    :return:
    """
    new_points_list = []

    for point_index in range(0, len(points_list)):
        # closest_point = get_closest_node(points_list[point_index])
        new_points_list.append(Point(points_list[point_index][1], points_list[point_index][0], -1))

    return new_points_list
Exemplo n.º 5
0
def get_points_between_two_points_second_version(point1, point2):
    (lat1, lon1), (lat2, lon2) = (point1.lat, point1.lon), (point2.lat,
                                                            point2.lon)
    url = "http://api.openstreetmap.org/api/0.6/map?bbox=%s,%s,%s,%s" % (min(
        lon1, lon2), min(lat1, lat2), max(lon1, lon2), max(lat1, lat2))
    osm_text = urllib.request.urlopen(url).read()

    soup = bs4.BeautifulSoup(osm_text, "lxml")
    nodes = soup.findAll("node")
    #print("len(nodes)",len(nodes))
    points = []
    for node in nodes:  # 1184053312
        lat = float(node.get("lat"))
        lon = float(node.get("lon"))

        if is_on_line(point1, point2, lat, lon):
            points.append(Point(lat, lon, node.get("id")))
    return points
Exemplo n.º 6
0
def get_end_point():
    return Point(0, 0, 0)
Exemplo n.º 7
0
    dist = 0
    for node in nodes:
        dist = point_node_distance(point1, node)
        if (dist < max):
            max = dist
            max_node = node
    return max_node.get("uid")


# points = Section.Point.create_points_list([[32.113254, 34.802280,7404723491]])
# print(get_closest_node(points[0]))
# print(get_interesting_points(32.112123, 34.803953,20))
if __name__ == '__main__':
    first = entrance_to_gilman[1]
    second = entrance_to_gilman[2]
    firstPoint = Point(first[1], first[0], -1)
    secondPoint = Point(second[1], second[0], -1)

    res = get_points_between_two_points_second_version(firstPoint, secondPoint)
    for i in res:
        print(i.to_string())
    """
    for i in range(len(entrance_to_gilman) - 1):
        print("current i", i)
        first = entrance_to_gilman[i]
        second = entrance_to_gilman[i+1]
        firstPoint = Point(first[1], first[0], -1)
        secondPoint = Point(second[1], second[0], -1)

        res = get_points_between_two_points_second_version(firstPoint,secondPoint)
        if(len(res) > 0):
Exemplo n.º 8
0
def createOutputList(nodes, ways):
    output = []

    for i, item in enumerate(nodes):
        node_tags = {}
        start_point = Point(item.lat,item.lon,item.id)
        node_tags["start_point"] = start_point

        if "highway" in item.tags:
            node_tags["comments"] = item.tags["highway"]

        # TODO
        #if "amenity" in item.tags:
        #    node_tags["r_side_description"] = item.tags["amenity"]

        if "barrier" in item.tags:
            node_tags["barrier"] = item.tags["barrier"]

        for way in ways:
            if item.id in way.nodes:

                # write way highway-type
                if "highway" in way.tags:
                    node_tags["ground_type"] = way.tags["highway"]
                    if way.tags["highway"] == "steps":
                        node_tags["is_steps"] = True
                    else:
                        node_tags["is_steps"] = False

                # write way handrail
                if "handrail" in way.tags:
                    node_tags["rail"] = way.tags["handrail"]

                # write way step-count
                if "step_count" in way.tags:
                    node_tags["steps_num"] = way.tags["step_count"]

                # write way barrier
                if "barrier" in way.tags:
                    node_tags["barrier"] = way.tags["barrier"]

                # write way name
                if "name:en" in way.tags:
                    node_tags["name"] = way.tags["name:en"]

        output.append(node_tags)

    for way in ways:
        node_ids = way.nodes
        for id in node_ids:
            node_tags = {}
            id_in_nodes = False
            for node in nodes:
                if (node.id == id) and node.tags:
                    id_in_nodes = True
            if not id_in_nodes:
                start_point = Point(0, 0, id)  # ???
                node_tags["start_point"] = start_point

                if "highway" in way.tags:
                    node_tags["ground_type"] = way.tags["highway"]
                    if way.tags["highway"] == "steps":
                        node_tags["is_steps"] = True
                    else:
                        node_tags["is_steps"] = False

                # write way handrail
                if "handrail" in way.tags:
                    node_tags["rail"] = way.tags["handrail"]

                # write way step-count
                if "step_count" in way.tags:
                    node_tags["steps_num"] = way.tags["step_count"]

                # write way barrier
                if "barrier" in way.tags:
                    node_tags["barrier"] = way.tags["barrier"]

                # write way name

                if "name:en" in way.tags:
                    node_tags["name"] = way.tags["name:en"]
                # TODO
                #if "amenity" in way.tags:
                #    node_tags["r_side_description"] = way.tags["amenity"]
            if node_tags:
                output.append(node_tags)
    return output