Example #1
0
def test_plot_routes():
    # cities_data_dict = {'Tver':[],'Krasnogorsk':[],'Moscow':[],'Sarov':[]}
    cities_data_dict = {
        'Tver': [],
        'Krasnogorsk': [],
        'Voskresensk': [],
        'Sarov': [],
        'Dmitrov': []
    }

    for key, data_list in cities_data_dict.iteritems():
        data_list.append(plot_routes.get_lat_lon_by_address(key))

    coords_moscow = plot_routes.get_lat_lon_by_address('Moscow')

    for key, data_list in cities_data_dict.iteritems():
        data_list.append(
            plot_routes.get_route_from_gmaps(coords_moscow, data_list[0]))

    for key, el in cities_data_dict.iteritems():
        print(key)
        print(len(el))
        print(el[-1][-1] / (60. * 60), "hours")

    sorted_routes = sorted(cities_data_dict.items(),
                           key=lambda x: x[-1][-1][-1])
    print(sorted_routes)
    for city in sorted_routes:
        print("%s, %f hours" % (city[0], city[-1][-1][-1] / (60 * 60.)))
        print(city[1][0])

    cities_coords = []
    cities_names = []
    for city in sorted_routes:
        cities_coords.append(
            plot_routes.get_pairs_list_from_dicts_list([city[1][0]])[0])
        cities_names.append(city[0])

    # print(cities_names)
    # print(cities_coords)

    plot_routes.plot_route_on_basemap(
        sorted_routes[0][1][1][0],
        sorted_routes[0][1][1][1],
        added_points_param_list=[cities_coords, cities_names])

    return True
Example #2
0
def test_plot_routes():
    # cities_data_dict = {'Tver':[],'Krasnogorsk':[],'Moscow':[],'Sarov':[]}
    cities_data_dict = {'Tver':[],'Krasnogorsk':[],'Voskresensk':[],'Sarov':[],'Dmitrov':[]}

    for key,data_list in cities_data_dict.iteritems():
        data_list.append(plot_routes.get_lat_lon_by_address(key))

    coords_moscow = plot_routes.get_lat_lon_by_address('Moscow')

    for key,data_list in cities_data_dict.iteritems():
        data_list.append(plot_routes.get_route_from_gmaps(coords_moscow,data_list[0]))

    for key,el in cities_data_dict.iteritems():
        print(key)
        print(len(el))
        print(el[-1][-1]/(60.*60),"hours")

    
    sorted_routes = sorted(cities_data_dict.items(), key=lambda x:x[-1][-1][-1])
    print(sorted_routes)
    for city in sorted_routes:
        print("%s, %f hours"%(city[0],city[-1][-1][-1]/(60*60.)))
        print(city[1][0])

    cities_coords = []
    cities_names = []
    for city in sorted_routes:
        cities_coords.append(plot_routes.get_pairs_list_from_dicts_list([city[1][0]])[0])
        cities_names.append(city[0])

    # print(cities_names)
    # print(cities_coords)

    plot_routes.plot_route_on_basemap(sorted_routes[0][1][1][0], sorted_routes[0][1][1][1],added_points_param_list=[cities_coords,cities_names])

    return True
Example #3
0
    print(s1.coords)
    # s1.coords = {'we': 21, 'wee': 23}
    # print(s1.coords)
    import tools
    print(tools.distance_straight(s1.coords,s2.coords))
    import mapm
    mo = mapm.Map(locations = [s1,s2])

    import gmaps
    cities_names = ['Moscow','Sarov','Krasnogorsk','Zelenograd','Dubna']
    sample_filename = tools.write_sample_cities_data_to_file(cities_names)
    locs_list = create_locations_list(sample_filename)
    str_lst = [loc.to_str() for loc in locs_list]
    for el in str_lst:
        print(el)

    origin = Location("Moscow",name='Moscow')
    raw_routes = []
    for location in [locn for locn in locs_list if locn.name != origin.name]:
        raw_routes.append(gmaps.get_route(origin.coords, location.coords))

        #!!! rewrite:
    from operator import itemgetter
    raw_routes.sort(key=itemgetter(-1)) # sort by duration
    from pprint import pprint as pp
    pp(raw_routes)
    import plot_routes  
    add_points_coords_list = [(point.coords['lat'],point.coords['lng']) for point in locs_list]
    add_points_annotes_list = [point.name for point in locs_list]
    plot_routes.plot_route_on_basemap(raw_routes[0][0], raw_routes[0][1], [add_points_coords_list,add_points_annotes_list]) # plots nearest route
Example #4
0
    print(s1.coords)
    # s1.coords = {'we': 21, 'wee': 23}
    # print(s1.coords)
    import tools
    print(tools.distance_straight(s1.coords,s2.coords))
    import mapm
    mo = mapm.Map(locations = [s1,s2])

    import gmaps
    cities_names = ['Moscow','Sarov','Krasnogorsk','Zelenograd','Dubna']
    sample_filename = tools.write_sample_cities_data_to_file(cities_names)
    locs_list = create_locations_list(sample_filename)
    str_lst = [loc.to_str() for loc in locs_list]
    for el in str_lst:
        print(el)

    origin = Location("Moscow",name='Moscow')
    raw_routes = []
    for location in [locn for locn in locs_list if locn.name != origin.name]:
        raw_routes.append(gmaps.get_route(origin.coords, location.coords))

        #!!! rewrite:
    from operator import itemgetter
    raw_routes.sort(key=itemgetter(-1)) # sort by duration
    from pprint import pprint as pp
    pp(raw_routes)
    import plot_routes  
    add_points_coords_list = [(point.coords['lat'],point.coords['lng']) for point in locs_list]
    add_points_annotes_list = [point.name for point in locs_list]
    plot_routes.plot_route_on_basemap(raw_routes[0][0], raw_routes[0][1], [add_points_coords_list,add_points_annotes_list]) # plots nearest route