def heat_map(lats, lons): gmap3 = gmplot.GoogleMapPlotter(20.5937, 78.9629, 5) gmap3.heatmap(lats, lons) gmap3.scatter(lats, lons, '#FF0000', size=50, marker=False) gmap3.plot(lats, lons, 'cornflowerblue', edge_width=3.0) save_location = input(" [ + ] Введите место для сохранения файла : ") gmap3.apikey = gmap() location = save_location + "/heatmap.html" gmap3.draw(location) print("[ + ] Heatmap saved at " + location) openWeb = input(" [ + ] Открыть в web broser? (Y/N) : ") if openWeb.upper() == 'Y': webbrowser.open(url=("file:///" + location)) else: pass
def export_to_google_maps(road_map): """Plot the roadmap in Google Maps.""" import gmplot start = road_map[0] gmap = gmplot.GoogleMapPlotter(start[2], start[3], 5) gmap.plot( lats=[conn[2] for conn in road_map] + [start[2]], lngs=[conn[3] for conn in road_map] + [start[3]], color="red", edge_width=3, ) gmap.draw("cities_road_map.html")
def renderLatLong(latlongs): try: gmap = gmplot.GoogleMapPlotter(latlongs[0][0], latlongs[0][1], 10) for x in latlongs: if x[0] != '' and x[1] != '' and x[0] != '\n' and x[1] != '\n': lat = float(x[0]) print(lat) lon = float(x[1]) print(lon) gmap.marker(lat, lon, title='Crime') gmap.draw("testLatLonRender.html") file_name = 'file:///home/jlally/Chicago/gmap/' + 'testLatLonRender.html' webbrowser.open_new_tab(file_name) except IndexError: print('NO VALUES FOUND')
def google_map_plots(df,zoom_level=17): lat_list=list(df.iloc[:,0].values) lon_list=list(df.iloc[:,1].values) new_lat_list= map(lambda nll: float(nll),lat_list) new_lat_list=list(new_lat_list) new_lon_list=map(lambda nll: float(nll),lon_list) new_lon_list=list(new_lon_list) centre_x=new_lat_list[0] centre_y=new_lon_list[0] #print('lat=',new_lat_list) #print('lon=',new_lon_list) gmap = gmplot.GoogleMapPlotter(centre_x,centre_y,zoom_level) gmap.scatter(new_lat_list,new_lon_list, '#4267b2', size=5, marker=False) gmap.draw("gmap.html") webbrowser.open('file://' + os.path.realpath("gmap.html"))
def genmap(self): center_coords = self.format_gps_str(balloon_gps_raw_buffer.split("\n")[-2]) if not self.sbalvar.get(): center_coords = self.format_gps_str(base_gps_buffer.split("\n")[-1]) map = gmplot.GoogleMapPlotter(*center_coords, 13, apikey=getapikey()) if self.sbalvar.get(): [map.marker(*self.format_gps_str(balloon_gps_raw_buffer.split("\n")[idx]), "red") for idx in range(min(len(balloon_gps_raw_buffer.split("\n"))-1, int(self.gps_amnt.get())))] if self.sbasvar.get(): [map.marker(*self.format_gps_str(base_gps_buffer.split("\n")[idx]), "green") for idx in range(min(len(base_gps_buffer.split("\n"))-1, int(self.gps_amnt.get())))] map.draw("full_map.html") webbrowser.open('file://' + os.path.realpath("full_map.html"))
def draw_overlapping_trips(timeseries1, timeseries2, name): longs1 = [] lats1 = [] for point in timeseries1: longs1.append(float(point[1])) lats1.append(float(point[2])) longs2 = [] lats2 = [] for point in timeseries2: longs2.append(float(point[1])) lats2.append(float(point[2])) gmap = gmplot.GoogleMapPlotter(lats1[0], longs1[0], 12) gmap.plot(lats1, longs1, 'green', edge_width=6) gmap.plot(lats2, longs2, 'red', edge_width=3) gmap.draw('maps/overlap_' + str(name) + '.html')
def __plot_point(lat, lng, output_path, result_name): """creates, marks, and opens a google map around the given location, under the given name :param lat: latitude of location :param lng: longitude of location :param output_path: path to dump the map in :param result_name: name of map file :return: None """ g_map = gmplot.GoogleMapPlotter(lat, lng, 16, title=result_name, apikey=API_KEY) g_map.marker(lat, lng) map_path = os.path.join(output_path, 'best_map - %s.html' % result_name) g_map.draw(map_path) webbrowser.open('file://' + os.path.realpath(map_path))
def heatmaps(): #return "rahul" raw_data = pd.read_csv("data_op.csv") latitudes = raw_data['latitude'] longitudes = raw_data['longitude'] #return str(latitudes)+str(longitudes) gmap = gmplot.GoogleMapPlotter(19.0728, 72.8826, 10) gmap.heatmap(latitudes, longitudes) gmap.draw("my_heatmap.html") #return "ok" return render_template("my_heatmap.html")
def plot_map(self): gmap = gmplot.GoogleMapPlotter(self.df['SampleLongitude'].iloc[0], self.df['SampleLatitude'].iloc[0], 12) for long, lat, name, color in zip(self.df.SampleLongitude.values, self.df.SampleLatitude.values, self.df.Description.values, self.html_color_codes.keys()): try: gmap.marker(float(long), float(lat), color=color, title=name + " , " + str(long) + " , " + str(lat)) except Exception as e: print(e) gmap.draw(self.filename + '.html')
def scatter(): Charminar_top_attraction_lats, Charminar_top_attraction_lons = zip(*[ (17.3833, 78.4011),(17.4239, 78.4738),(17.3713, 78.4804),(17.3616, 78.4747), (17.3578, 78.4717),(17.3604, 78.4736),(17.2543, 78.6808),(17.4062, 78.4691), (17.3950, 78.3968),(17.3587, 78.2988),(17.4156, 78.4750)]) gmap3 = gmplot.GoogleMapPlotter(17.3616, 78.4747, 13) gmap3.scatter( Charminar_top_attraction_lats, Charminar_top_attraction_lons, '#FF0000',size = 50, marker = False ) gmap3.plot(Charminar_top_attraction_lats, Charminar_top_attraction_lons, 'cornflowerblue', edge_width = 3.0) gmap3.apikey = "API_Key" gmap3.draw(r"scatter.html")
def heat_map(lats, lons): gmap3 = gmplot.GoogleMapPlotter(20.5937, 78.9629, 5) gmap3.heatmap(lats, lons) gmap3.scatter(lats, lons, '#FF0000', size=50, marker=False) gmap3.plot(lats, lons, 'cornflowerblue', edge_width=3.0) save_location = input("Enter the location to save file : ") gmap3.apikey = gmap() location = save_location + "/heatmap.html" gmap3.draw(location) print("Heatmap saved at " + location) openWeb = input("Open Heatmap in web browser? (Y/N) : ") if openWeb.upper() == 'Y': webbrowser.open(url=("file:///" + location)) else: pass
def draw_map(portal_list, map_name="map.html"): lat_list = [] lng_list = [] name_list = [] for line in portal_list: pair = line.split("\t") name_list.append(pair[0]) lat, lng = pair[1].split(",") lat_list.append(float(lat)) lng_list.append(float(lng)) gmap = gmplot.GoogleMapPlotter(51.919396, 19.145208, 7) gmap.heatmap(lat_list, lng_list) gmap.draw(map_name)
def postman(osm_data): Settings = IngestSettings( max_distance=Distance(km=50), max_segments=300, max_concurrent=40, quality_settings=DefaultQualitySettings, location_filter=None, ) loader = OSMIngestor(Settings) loader.load_osm(osm_data, extra_links=[(885729040, 827103027)]) # s = datetime.now() # data = write_gpickle(loader.global_graph, 'test.pickle') #nx_yaml.write_yaml(loader.global_graph, 'test.yaml') # e = datetime.now() # print(e-s) # s = datetime.now() # graph = read_gpickle('test.pickle') # e = datetime.now() # print(e-s) # import pdb; pdb.set_trace() for i, network in enumerate(loader.trail_networks()): print(network.name, network.total_length().mi) print(network.trail_names()) gmap = gmplot.GoogleMapPlotter(42.385, -71.083, 13) edge_map = {} for segment in network.trail_segments(): segment.draw(gmap) edge_map[segment.id] = segment.nodes clean_name = (network.name or f'no-name-{i}').replace(' ', '').replace("\'", '') gmap.draw(f"{clean_name}-{i}.html") with open('edges.csv', 'w') as csv_file: writer = csv.DictWriter(csv_file, fieldnames=['start', 'end', 'id', 'distance']) writer.writeheader() for segment in network.trail_segments(): writer.writerow(dict(start=segment.nodes[0].id, end=segment.nodes[-1].id, id=segment.id, distance=segment.length_m())) try: s = datetime.now() circuit, graph = cpp('edges.csv') e = datetime.now() print(f'Time: {e-s}') for k, v in calculate_postman_solution_stats(circuit).items(): print(k, v) with open(f"{clean_name}-{i}.gpx", "w") as f: f.write(circuit_to_gpx(circuit, edge_map).to_xml()) except Exception as ex: print(ex)
def draw_heatmap(csv_name): """This function reads the csv with coordinates and rank of several places and then creates a heatmap which is then displayed in the user's browser""" # Here the function gets the path for the csv path = os.getcwd() + '/Data/' + csv_name + '.csv' # Here the function reads the csv into a dataframe try: places = pd.read_csv(path, encoding = 'latin1', header = 0, index_col = 0) except OSError: print("file for option not found") # Here the function defines the color gradient for different layers of the heatmap high_gradient = [(255, 255, 255,0),(255, 255, 0, 1),(255, 170, 0, 1),(255, 85, 0, 1), (255, 0, 0,1)] med_gradient = [(255, 255, 255,0), (255, 255, 0, 1), (170, 255, 0, 1), (85,255,0,1), (0,255,0,1)] low_gradient = [(255, 255, 255,0), (0,255,255,1), (0,170,255,1), (0,85,255,1), (0,0,255,1)] # Here the center point for the map is defined center_lat = 40.7128 center_long = -74.0059 # Here the map is created and the coordinates are split into groups based off of their rank the_map = gmplot.GoogleMapPlotter(center_lat, center_long, 11) try: high_coordinates, med_coordinates, low_coordinates = rank_coordinates(places) except KeyError: print("Csv that was read did not have proper name for columns") # These nex couple of lines are to make sure that no the function does no try to write any empty # groups on to the heatmap if len(high_coordinates[0]) > 0 : the_map.heatmap(high_coordinates[0],high_coordinates[1],threshold=10,radius=25, gradient=high_gradient) if len(med_coordinates[0]) > 0 : the_map.heatmap(med_coordinates[0], med_coordinates[1], threshold=10, radius=25, gradient=med_gradient) if len(low_coordinates[0]) > 0 : the_map.heatmap(low_coordinates[0], low_coordinates[1], threshold=10, radius=25, gradient=low_gradient) # The heatmap is drawn here path = os.path.abspath('Results') the_map.draw(path + '/' + csv_name + "_heatmap.html") # Here the heatmap is opened up in the user's browser link = 'file://'+ path + '/'+csv_name + "_heatmap.html" webbrowser.open_new(link)
def plot_neighbours(dic): #colors = ["red", "yellow", "blue", "green", "cyan", "black", "grey"] gmap = gmplot.GoogleMapPlotter(55.677057, 12.589111, 14) #quickfix for windows gmap.coloricon = gmap.coloricon.replace("\\", "/") amenities = set() col = "FFFFFF" for k, cliques in dic.items(): for clique in cliques: lats = [elem[0] for elem in clique] longs = [elem[1] for elem in clique] lats.append(clique[0][0]) longs.append(clique[0][1]) #for elem in v: # lats = [elem[0]] # longs = [] # lats.extend([x[0] for x in elem[1]]) #longs.extend([x[1] for x in elem[1]]) #lats.append(elem[0][0]) #longs.append(elem[0][1])# # only draw triples and more if len(lats) > 3: x = [elem[2] for elem in clique] x.sort() pattern = ".".join(x) if "bicycle_parking.cafe.restaurant" == pattern: [amenities.add(elem) for elem in clique] num = int(col, 16) col = hex(int(num - 2038)) c = "#" + str(col).upper()[2:] gmap.plot(lats, longs, color=c, edge_width=1) for amenity in amenities: color = get_color(amenity[2]) gmap.marker(amenity[0], amenity[1], color=get_marker(amenity[2]), title=amenity[2]) gmap.circle(amenity[0], amenity[1], 4, color, ew=0.3) gmap.draw("neighbour_map.html") print()
def build_map(maps, dest): try: lat_list = [float(m.lat) for m in maps] lon_list = [float(m.lon) for m in maps] center, zoom = find_center_zoom(lat_list, lon_list) print(f'Center: {center}') gmap = gmplot.GoogleMapPlotter(center[0], center[1], zoom, apikey='AIzaSyBxhQschyIWYAi9Yu3_vW-Wwb2YgK3dWO4') gmap.scatter(lat_list, lon_list, '#4DCBCC', size=30, marker=True) gmap.plot(lat_list, lon_list, '#4dcbcc', edge_width=3) print('DREW_MAP') print(dest) gmap.draw(dest) return True except Exception as e: print(e) print("ARGH")
def plot_path(path): path = np.append(path, path[0]) latitude_list = coordinates[:, 0] longitude_list = coordinates[:, 1] path_latitude = latitude_list[path] path_longitude = longitude_list[path] gmap = gmplot.GoogleMapPlotter(coordinates[39, 0], coordinates[39, 1], 7) gmap.apikey = "AIzaSyD_07xnO2NqogYSQoddVloGMufVKcx42lk" gmap.scatter(path_latitude, path_longitude, '# FF0000', size=40, marker=False) gmap.plot(path_latitude, path_longitude, 'cornflowerblue', edge_width=2.5) gmap.draw("Path Map.html") return None
def plot(): gd = {} lat = [13.080384, 13.080384, 13.080384] lon = [77.5319506, 77.5319506, 77.5319506] ref = db.collection('users') docs = ref.stream() for doc in docs: lat.append(doc.to_dict()['location']['latitude']) lon.append(doc.to_dict()['location']['longitude']) gmap1 = gmplot.GoogleMapPlotter(13.0319627, 77.5642704, 13) # print(lat) # print(lon) gmap1.heatmap(lat, lon) gmap1.draw("templates\map.html") return render_template("map.html")
def drawMap(data, mapName): longitude = [] latitude = [] for i in data: longitude.append(float(i['Longitude'])) latitude.append(float(i['Latitude'])) mediaLongitud = media(longitude) mediaLatitud = media(latitude) gmap = gmplot.GoogleMapPlotter(mediaLatitud, mediaLongitud, 8) gmap.heatmap(latitude, longitude) #gmap.scatter(latitude, longitude, '#3B0B39', size=80, marker=False) gmap.draw("maps/" + mapName.split(".")[0] + ".html")
def plotter(latitudes, longitudes): gmap = plot.GoogleMapPlotter(latitudes[0], longitudes[0], zoom=15, apikey=MAPS_JAVASCRIPT_API_KEY) # gmap.plot(latitudes, longitudes, '#C71585', edge_width=1) # markers only over places and not current location gmap.scatter(latitudes[1:], longitudes[1:], '#C71585', size=50, marker=False) # create html file gmap.draw("places.html") open_in_browser()
def plotheatmap(): #retrieving Lat and long values from the database con = sqlite3.connect('projectMal.db') cur = con.cursor() query = 'SELECT "latitude","longitude","city" FROM "Locationdata" where latitude!=""' res = pd.read_sql(query, con) latitudes = res["latitude"] longitudes = res["longitude"] city = res["city"] #initializing the focus point of the map and appending the API key gmap = gmplot.GoogleMapPlotter(0.0522, 0.2437, 3, 'AIzaSyAwZ9fVUmAd6KaquhStiFQltzWB4SkmtPs') for i in range(0, 30): #plotting the values in the map gmap.heatmap(latitudes, longitudes, 30, 10, None, 0.6, 5) gmap.draw("map.html")
def only_show_address(imgpath, detail=True): '''只显示地址信息 detail: bool, 是否显示详细的地址信息 ''' address = locate(imgpath, detail) # 用于绘制在地图上的坐标 lat, lng = address.google_latlng.split(',') gmap = gmplot.GoogleMapPlotter(float(lat), float(lng), zoom=15) gmap.heatmap([float(lat)], [float(lng)], radius=15, opacity=1) gmap.draw('imgmap.html') logging.debug('address: {}, detail: {}'.format(address, detail)) if detail: print(imgpath, address.formatted_address, address.sematic_description) else: print(imgpath, address.formatted_address)
def generate_registrant_markers_map(lgu): # Get address of registrants of LGU addresses = lgu.registrants.all().values('address', ) coordinates_lats, coordinates_long = get_coordinates(addresses) gmap = gmplot.GoogleMapPlotter(float(lgu.latitude), float(lgu.longitude), 14, apikey=GOOGLE_MAPS_API_KEY) gmap.scatter(coordinates_lats, coordinates_long, color='cornflowerblue') vaccination_sites = lgu.vaccination_sites.all().values('address', ) coordinates_lats, coordinates_long = get_coordinates(vaccination_sites) gmap.scatter(coordinates_lats, coordinates_long, color='red') html = ContentFile(gmap.get()) lgu.registrant_map.save(f'{lgu.name}Map.html', html)
def build_map(lat, long, tweet_details): # I had intended to use the map as the default but twitter is no longer returning plentiful coordinates # Place map gmap = gmplot.GoogleMapPlotter(lat, long, 8) for detail in tweet_details: # if we have been given coordinates lets render them on a map if detail['lat']: #gmplot gets flaky with unicode, so we decode the text gmap.marker(float(detail['lat']), float(detail['long']), 'cornflowerblue', title=detail['tweet'].encode()) # Draw te map that we will use if cordinates are actually present gmap.draw("views/my_map.html")
def mapfuntion(request): l1 = [] l2 = [] data = Location.objects.all() data1 = data.values() for x in data1: for y, z in x.items(): if y == 'latitude': l1.append(float(z)) elif y == 'longitude': l2.append(float(z)) gmap = gmplot.GoogleMapPlotter(30.3164945, 78.03219179999999, 2) gmap.heatmap(l1, l2) gmap.draw("templates/one.html") return render(request, "one.html")
def plot(self): gmap = gmplot.GoogleMapPlotter(self.x, self.y, 18) gmap.plot(self.items_track_x, self.items_track_y, 'cornflowerblue', edge_width=5) # gmap.s12catter(self.items_markers_x, self.items_markers_y, '#3B0B39', size=5, marker=False) gmap.scatter(self.free_places_x, self.free_places_y, 'k', marker=True) gmap.heatmap(self.items_markers_x, self.items_markers_y) gmap.draw(self.path) self.driver.refresh() #print(self.items_track_x) if not self.done: threading.Timer(1, self.plot).start() else: pass
def plotMap(lst, test_index, train_index=None): langt = [x[0] for x in lst] longt = [x[1] for x in lst] if train_index is None: filename = "a1_test" + str(test_index + 1) + ".html" else: filename = "a1_test" + str(test_index + 1) + "_n" + str(train_index) + ".html" medianSpot = ( # the 'center' of the route min(langt) + (max(langt) - min(langt)) / 2, min(longt) + (max(longt) - min(longt)) / 2) gmap = gmplot.GoogleMapPlotter(medianSpot[0], medianSpot[1], 12) gmap.plot(langt, longt, 'blue', edge_width=5) gmap.draw(filename)
def MidPoint(n, addr): geolocator = Nominatim(user_agent="MeetInTheMid") google_places = GooglePlaces('AIzaSyCd3yT-00TDYD1gYM6WWWKTO6kxOVr-ho8') lat = [] longy = [] temp = [] print("This is",addr) for x in addr: print(x) location = geolocator.geocode(x) lat.append(location.latitude) longy.append(location.longitude) temp.append((location.latitude, location.longitude)) lat_mid = sum(lat)/n longy_mid = sum(longy)/n print(temp) gmap = gmplot.GoogleMapPlotter(lat_mid,longy_mid,12) lat, longy = zip(*temp) #lat, longy = zip(*[(19.0549792, 72.8402203), (19.0549792, 72.8402203)]) lat_mid = round(lat_mid, 4) longy_mid = round(longy_mid, 4) print(lat_mid, longy_mid) print(type(lat_mid)) rest_near_me = google_places.nearby_search( lat_lng={'lat': lat_mid, 'lng': longy_mid}, radius=20, types=[types.TYPE_CAFE]) print("Rest mea",rest_near_me) for place in rest_near_me.places: print("this si:",place.geo_location['lat'], place.geo_location['lng']) gmap.marker(place.geo_location['lat'], place.geo_location['lng'], 'green') gmap.scatter(lat, longy, 'FA0000', size = 50, marker=False) for i in range(len(addr)): gmap.marker(lat[i], longy[i], 'red') gmap.marker(lat_mid, longy_mid, 'cornflowerblue' ) for x in range(len(addr)): gmap.plot([lat_mid, lat[x]], [longy_mid, longy[x]],'blue', edge_width=5) mid_addr = geolocator.reverse(lat_mid, longy_mid) #gmap.plot(lat_mid, longy_mid) gmap.apikey = "AIzaSyCd3yT-00TDYD1gYM6WWWKTO6kxOVr-ho8" #print(gmaps.directions(addr[0], mid_addr)) gmap.draw(r"D:\ritu-middle\ritu-middle\Main\templates\temp.html") #to save the image return lat_mid, longy_mid, temp
def plot_coordinates_on_map(): apikey = '' try: response = requests.get("") response.raise_for_status() print(response) response_json = response.json() feeds = response_json['feeds'] lat_list = [] lon_list = [] for feed in feeds: lat = float(feed['field2']) lon = float(feed['field1']) lat_list.append(lat) lon_list.append(lon) curr_lat = lat_list[-1] curr_lon = lon_list[-1] origin_lat = lat_list[0] origin_lon = lon_list[0] zoom_lvl = 16 gmap = gmplot.GoogleMapPlotter(origin_lat, origin_lon, zoom_lvl, apikey=apikey) for i in range(100): curr_lat += (random.rand() - 0.5) / 10000.0 lat_list.append(curr_lat) curr_lon += (random.rand() - 0.5) / 10000.0 lon_list.append(curr_lon) gmap.plot(lat_list, lon_list, edge_width=7, color='blue') print(lat_list[0:5]) print(lon_list[0:5]) gmap.draw('map.html') os.system('map.html') except RequestException: print('Request not satisfied!')
def plotGMapCsv(): """ loads location data from csv and plots it to a html file @param dbname - name of database @param dbuser - corresponding user for database @param node - name of node to grab information from @param franchise - badger franchise of node """ data = loader() gmap = gmplot.GoogleMapPlotter(data['Lat'][0], data['Long'][0], 16) tracker = set() counter = {} step = 0.00009 for i in range(len(data['Latitude'])): lat = float(data['Latitude'][i]) lon = float(data['Longitude'][i]) element = (lat, lon) # # if element in tracker and counter[element] > 4: # gmap.marker(lat, lon, color = 'b') #else: # gmap.marker(lat, lon, color = "#7FFF00") #gmap.marker(lat, lon, color = "#7FFF00") tracker.add(element) try: counter[element] += 1 except (KeyError): counter[element] = 0 counter[element] += 1 for count in counter: if counter[count] >= 10: gmap.marker(count[0], count[1], color='b') print count print counter[count] for i in range(len(data['Latitude'])): lat = float(data['Latitude'][i]) lon = float(data['Longitude'][i]) element = (lat, lon) if counter[element] < 10: gmap.marker(lat, lon, color="#7FFF00") gmap.draw('location.html')