コード例 #1
0
def addRoute(mapOfNodes, intersections, directionIntersection, points):
    close_intersections = []
    missing_intersection = []
    school = intersectionParse.Node(-117.71747, 34.10185)
    previous_node = points[0]

    for point_node in points[1:]:
        if point_node in directionIntersection:
            directionIntersection.remove(point_node)

        #mapOfNodes[previous_node] = point_node
        if point_node in mapOfNodes:
            # Place holder for where there should already be direction to the school
            mapOfNodes[previous_node] = point_node
            print('here, place holder for nodes already in mapOfNodes')
            break

        distance_lat = abs(point_node.lat - previous_node.lat)
        distance_lng = abs(point_node.lng - previous_node.lng)

        if distance_lat > .00050 or distance_lng > .00050:
            radius = (point_node - previous_node) / 2
            midpoint = intersectionParse.Node(
                (min(point_node.lat, previous_node.lat) + distance_lat / 2),
                (min(point_node.lng, previous_node.lng) + distance_lng / 2))

            close_intersections = [
                inter for inter in intersections
                if (inter - midpoint) <= radius
            ]
            missing_intersection = getSpPoint(point_node, previous_node,
                                              close_intersections)

            distances = [(previous_node - inter, inter)
                         for inter in missing_intersection]

            distances.sort()

            for inter in distances:
                if inter[1] != previous_node:
                    mapOfNodes[previous_node] = inter[1]
                    previous_node = inter[1]
        if point_node != previous_node:
            mapOfNodes[previous_node] = point_node

        previous_node = point_node
    print("done with path")
    return mapOfNodes
コード例 #2
0
ファイル: dirProject.py プロジェクト: csxz1122/summer_2016
def main(kml_file, html_file, text_file):
    # API key
    gmaps = googlemaps.Client(key='AIzaSyDaPfA_TUTlbHLDH0K48qS-Jh2ETfCTz_0')
    #for debugging
    colors = [
        '#000000', '#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF',
        '#FF00FF'
    ]
    intersection_file = pointsFunction.kmlParse(kml_file, text_file)
    intersections = intersectionParse.createIntersections(intersection_file)

    mapOfNodes = {}
    # directionIntersections = intersections
    directionIntersections = copy.deepcopy(intersections)
    i = 0
    # the school **look into changing it into the school logo*** add polygone here ***

    while (directionIntersections):
        temp_node = directionIntersections.pop()
        start = [temp_node.lng, temp_node.lat]

        end = [34.10185, -117.71747]

        #making a call to the google maps api
        dirs = gmaps.directions(start, end, "walking")
        #points = dirs[0]["overview_polyline"]["points"]

        points = [
            intersectionParse.Node(lng, lat) for lat, lng in polyline.decode(
                dirs[0]["overview_polyline"]["points"])
        ]
        # the distance of the route will possibly be helpful in the future if I am changing the colors of the arrows
        points = addRouteToMap.snapToIntersection(points, intersections)

        mapOfNodes = addRouteToMap.addRoute(mapOfNodes, intersections,
                                            directionIntersections, points)

        i += 1
        if i > 20:
            # time.sleep(.5)
            i = 0
            break
    color_count = 0
    for key in mapOfNodes:
        if (mapOfNodes[key] is not None):
            print("Map leg: ", mapOfNodes[key], key)
            print(key.lat, key.lng)
            print(mapOfNodes[key].lat, mapOfNodes[key].lng)
            THE_MAP.addpath([key, mapOfNodes[key]], key.value,
                            colors[color_count])
            # THE_MAP.addpath([mapOfNodes[key], key], key.value, colors[color_count])
            color_count += 1
            if color_count == 6:
                color_count = 0

    THE_MAP.addpoint(34.10185, -117.71747, "#FF0000")

    THE_MAP.draw(html_file)
コード例 #3
0
def getSpPoint(A, B, close_intersections):
    print("In get SP point")
    missing_intersection = []
    for C in close_intersections:
        x1 = A.lat
        y1 = A.lng
        x2 = B.lat
        y2 = B.lng
        x3 = C.lat
        y3 = C.lng
        px = x2 - x1
        py = y2 - y1
        dAB = px * px + py * py
        u = ((x3 - x1) * px + (y3 - y1) * py) / dAB
        x = x1 + u * px
        y = y1 + u * py

        currNode = intersectionParse.Node(x, y)

        if currNode - C < THRESHOLD:
            missing_intersection.append(currNode)
    return missing_intersection
コード例 #4
0
def main(kml_file, html_file, text_file):

    # API key
    gmaps = googlemaps.Client(key='AIzaSyDaPfA_TUTlbHLDH0K48qS-Jh2ETfCTz_0')

    #possible arrow colors
    colors = ['#ff99ff', '#ff00ff', '#660066']
    color_count = 0

    #get intersection data
    intersection_file = pointsFunction.kmlParse(kml_file, text_file)
    intersections = intersectionParse.createIntersections(intersection_file)
    directionIntersections = copy.deepcopy(intersections)

    #create an empty dict for the nodes
    mapOfNodes = {}

    #iterate through intersections
    while (directionIntersections):

        #get our node from the intersection data
        temp_node = directionIntersections.pop()

        #find the arrow endpoints
        start = [temp_node.lng, temp_node.lat]
        end = [LAT, LNG]  # WHERE IS THIS FROM?

        #making a call to the google maps api
        dirs = gmaps.directions(start, end, "walking")
        points = [
            intersectionParse.Node(lng, lat) for lat, lng in polyline.decode(
                dirs[0]["overview_polyline"]["points"])
        ]
        # Note from Erin: the distance of the route will possibly be helpful in the future if I am changing the colors of the arrows
        points = addRouteToMap.snapToIntersection(points, intersections)

        #add to map
        mapOfNodes = addRouteToMap.addRoute(mapOfNodes, intersections,
                                            directionIntersections, points)

    # iterate through arrows
    for key in mapOfNodes:
        if (mapOfNodes[key] is not None):

            markerLAT = LNG
            markerLNG = LAT

            dist = math.sqrt((abs((markerLAT - key.lat) *
                                  (markerLAT - key.lat))) +
                             (abs((markerLNG - key.lng) *
                                  (markerLNG - key.lng))))

            if (dist <= 0.00477071646):
                color_count = 0
            elif (dist <= 0.00954143292):
                color_count = 1
            else:
                color_count = 2

            THE_MAP.addpath([key, mapOfNodes[key]], key.value,
                            colors[color_count])

    THE_MAP.addpoint(LAT, LNG, "#FF0000")

    THE_MAP.draw(html_file)