def set_markers(self, staticmap, zoom_level,random_city): marker=CircleMarker((float(random_city['lng']), float(random_city['lat'])), 'black', 10) marker2=CircleMarker((float(random_city['lng'])+zoom_level, float(random_city['lat'])+zoom_level), 'black', 0) marker3=CircleMarker((float(random_city['lng'])-zoom_level, float(random_city['lat'])-zoom_level), 'black', 0) staticmap.add_marker(marker) staticmap.add_marker(marker2) staticmap.add_marker(marker3)
def generate(self, filename): file = open('zipcodes.dat', 'r') long = 0 lat = 0 for line in file: line = line.split(';') if (line[0] == self.center): long = float(line[3]) lat = float(line[4]) break cir = CircleMarker((lat, long), 'black', 20) self.map.add_marker(cir) for x in self.entries: if (float(x[0]) < 50): color = "red" elif (float(x[0]) > 50 and float(x[0]) < 100): color = "orange" elif (float(x[0]) > 100 and float(x[0]) < 150): color = "yellow" elif (float(x[0]) > 150 and float(x[0]) < 200): color = "green" elif (float(x[0]) > 200 and float(x[0]) < 250): color = "blue" elif (float(x[0]) > 250 and float(x[0]) < 300): color = "purple" else: color = "white" cir = CircleMarker((float(x[1]), float(x[2])), color, 10) self.map.add_marker(cir) image = self.map.render() image.save(filename)
def route(G, name_file, addresses): coords = addressesTOcoordinates(addresses) coord_origin, coord_destination = coords G_coord = create_G_Coord(G, coord_origin, coord_destination) #Application of djijstra algorithm with the graph correctly weighted. fastest_path = nx.dijkstra_path(G_coord, coord_origin, coord_destination) #Creation of the map associated to the route. map = StaticMap(750, 750) for i in range(len(fastest_path) - 1): coord1, coord2 = fastest_path[i], fastest_path[i + 1] line = Line([[coord1[1], coord1[0]], [coord2[1], coord2[0]]], '#0000FFBB', 4) map.add_line(line) marker = CircleMarker([coord1[1], coord1[0]], 'red', 6) marker_outline = CircleMarker([coord1[1], coord1[0]], 'black', 8) map.add_marker(marker_outline) map.add_marker(marker) #Intentar coger el icono de internet y no tenerlo guardado como imagen local. dest_marker = IconMarker( [coord2[1], coord2[0]], '/home/victor/Documentos/AP2/Exercicis/Bicing/Icons/2344292-24.png', 24, 24) map.add_marker(dest_marker) image = map.render() image.save(name_file)
def draw_map(): m = StaticMap(4000, 4000) for key, access_point in access_point_data.items(): if not ('lat' in access_point and 'lng' in access_point): continue coords = (access_point['lat'], access_point['lng']) if access_point['lng'] - -34.611944444444 > 0.1: continue if access_point['lat'] - -58.364722222222 > 0.1: continue colors = { 'open': 'red', 'wep': 'red', 'wpa': 'yellow', 'wpa2': 'green' } marker_outline = CircleMarker(coords, colors[access_point['encryption']], 18) marker = CircleMarker(coords, colors[access_point['encryption']], 12) m.add_marker(marker_outline) m.add_marker(marker) image = m.render(zoom=15) temp_file = NamedTemporaryFile(suffix='.png') image.save(temp_file.name) image.save('/home/lcubo/test1.png') return temp_file
def dijkstra_route(G, position): m = StaticMap(400, 500) last = int(-1) time = int(0) path = nx.dijkstra_path(G, -1, 0) # We go through each node in the minimum path between the start and end. for i in path: if (i != -1): coord1 = swap(position[last]) coord2 = swap(position[i]) e = (last, i) time += G.get_edge_data(*e)['weight'] if i == path[1] or i == 0: # Walking -> green edge (first or last edge). m.add_line(Line((coord1, coord2), 'green', 2)) else: # Riding a Bicycle -> blue edge. m.add_line(Line((coord1, coord2), 'blue', 2)) # Origin and destination points are purple and bigger. if (i > 0): m.add_marker(CircleMarker(swap(position[i]), 'red', 2)) else: m.add_marker(CircleMarker(swap(position[i]), 'purple', 4)) last = i return m, int(time)
def add_markers(chosen_map, zoom_level): marker=CircleMarker((float(random_city['lng']), float(random_city['lat'])), 'black', 5) marker2=CircleMarker((float(random_city['lng'])+zoom_level, float(random_city['lat'])+zoom_level), 'black', 0) marker3=CircleMarker((float(random_city['lng'])-zoom_level, float(random_city['lat'])-zoom_level), 'black', 0) chosen_map.add_marker(marker) chosen_map.add_marker(marker2) chosen_map.add_marker(marker3)
def plot_mar_prediction(edge_index_to_tuples, node_locations, marginals, correct_next, used_edges, src_node, dst_node, map_name): m = StaticMap(2000, 1500, url_template="http://a.tile.osm.org/{z}/{x}/{y}.png") for key in marginals: if key in edge_index_to_tuples: cur_marginal = marginals[key] edge_tuple = edge_index_to_tuples[key] density = math.exp(cur_marginal[1]) src_gps = node_locations[edge_tuple[0]] dst_gps = node_locations[edge_tuple[1]] m.add_line( Line(((src_gps[1], src_gps[0]), (dst_gps[1], dst_gps[0])), get_color(density), 5)) for used_edge in used_edges: src_gps = node_locations[edge_index_to_tuples[used_edge][0]] dst_gps = node_locations[edge_index_to_tuples[used_edge][1]] m.add_line( Line(((src_gps[1], src_gps[0]), (dst_gps[1], dst_gps[0])), "black", 5)) src_gps = node_locations[src_node] dst_gps = node_locations[dst_node] m.add_marker(CircleMarker((src_gps[1], src_gps[0]), "blue", 3)) m.add_marker(CircleMarker((dst_gps[1], dst_gps[0]), "blue", 3)) src_gps = node_locations[edge_index_to_tuples[correct_next][0]] dst_gps = node_locations[edge_index_to_tuples[correct_next][1]] m.add_line( Line(((src_gps[1], src_gps[0]), (dst_gps[1], dst_gps[0])), "green", 2)) image = m.render() image.save(map_name)
def find_drone_path(self): # desired path of drone m = StaticMap(1200, 950) marker_outline = CircleMarker(self.start, 'white', 18) marker = CircleMarker(self.start, '#0036FF', 12) m.add_marker(marker_outline) m.add_marker(marker) for t in self.targets: target_marker_outline = CircleMarker(t, 'white', 18) target_marker = CircleMarker(t, 'red', 12) m.add_marker(target_marker_outline) m.add_marker(target_marker) path = [] path.append(self.start) for t in self.targets: path.append(t) m.add_line(Line(path, 'blue', 3)) image = m.render(zoom=self.zoom) image.save(r'GMap\drone_path.png')
def plot_mpe_prediction(edge_index_to_tuples, node_locations, mpe_result, used_edges, total_route, src_node, dst_node, map_name): m = StaticMap(2000, 1500, url_template="http://a.tile.osm.org/{z}/{x}/{y}.png") for used_edge in used_edges: src_gps = node_locations[edge_index_to_tuples[used_edge][0]] dst_gps = node_locations[edge_index_to_tuples[used_edge][1]] m.add_line( Line(((src_gps[1], src_gps[0]), (dst_gps[1], dst_gps[0])), "black", 5)) src_gps = node_locations[src_node] dst_gps = node_locations[dst_node] m.add_marker(CircleMarker((src_gps[1], src_gps[0]), "blue", 8)) m.add_marker(CircleMarker((dst_gps[1], dst_gps[0]), "blue", 8)) for used_edge in total_route: if used_edge not in used_edges: src_gps = node_locations[edge_index_to_tuples[used_edge][0]] dst_gps = node_locations[edge_index_to_tuples[used_edge][1]] m.add_line( Line(((src_gps[1], src_gps[0]), (dst_gps[1], dst_gps[0])), "green", 10)) for active_variable_index in mpe_result: if active_variable_index in edge_index_to_tuples and active_variable_index not in used_edges: edge_tuple = edge_index_to_tuples[active_variable_index] src_gps = node_locations[edge_tuple[0]] dst_gps = node_locations[edge_tuple[1]] m.add_line( Line(((src_gps[1], src_gps[0]), (dst_gps[1], dst_gps[0])), "red", 5)) image = m.render() image.save(map_name)
def draw_map(point1, point2): url_template = "https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png" #url_template = "http://a.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png" # alternatiba_1 #url_template = "http://tile.memomaps.de/tilegen/{z}/{x}/{y}.png" # alternatiba_2 map_width = 600 map_height = 400 z = 8 fName = str(uuid.uuid4().hex) m = StaticMap(map_width, map_height, url_template=url_template) coords1 = point_to_coordinates(point1) coords2 = point_to_coordinates(point2) marker_outline1 = CircleMarker(coords1, 'white', 18) marker1 = CircleMarker(coords1, '#0036FF', 12) m.add_marker(marker_outline1) m.add_marker(marker1) marker_outline2 = CircleMarker(coords2, 'white', 18) marker2 = CircleMarker(coords2, '#0036FF', 12) m.add_marker(marker_outline2) m.add_marker(marker2) image = m.render(zoom=z) image.save("./maps/" + fName + ".png") return fName+".png"
def createMap(reviews=[], recs=[], zoom=None): global m global m_helper marker = CircleMarker((-88.2234, 40.1064), '#0036FF', 0) m.add_marker(marker) for i in reviews: marker = CircleMarker(i, '#0036FF', 8) m.add_marker(marker) m_helper.add_marker(marker) for i in recs: marker = CircleMarker(i, '#FA2020', 8) m.add_marker(marker) i = 5 while i > 0: try: if zoom is not None: image = m.render(zoom) else: image = m.render() break except RuntimeError: i -= 1 time.sleep(2) if i == 0: messagebox.showerror("Warning: Couldn't download maps", "Please check internet connection.") image = ImageTk.PhotoImage(image) displaymap_image.configure(image=image) displaymap_image.image = image
def display_start_map(self): # Not Using m = StaticMap(1200, 950) marker_outline = CircleMarker(self.start, 'white', 18) marker = CircleMarker(self.start, '#0036FF', 12) m.add_marker(marker_outline) m.add_marker(marker) image = m.render(zoom=self.zoom) image.save(r'GMap\start_map.png')
def paintNodes(g, mapa, custom_size): for n in list(g.nodes): latitude_node = float(g.nodes[n]['latitude']) longitude_node = float(g.nodes[n]['longitude']) population_node = float(g.nodes[n]['population']) if g.nodes[n]['visible']: if custom_size: mapa.add_marker(CircleMarker((longitude_node, latitude_node), 'red', population_node/(2*100000))) else: mapa.add_marker(CircleMarker((longitude_node, latitude_node), 'red', 2)) return mapa
def getmap(latitude, longitude, largeur, hauteur, zoom): m = StaticMap(largeur,hauteur, url_template='http://a.tile.osm.org/{z}/{x}/{y}.png') marker_outline = CircleMarker((longitude,latitude), 'white', 18) marker = CircleMarker((longitude,latitude), '#0036FF', 12) m.add_marker(marker_outline) m.add_marker(marker) image = m.render(zoom) image.save('marker.png')
def render_map(): m = StaticMap(400, 400, url_template='http://a.tile.osm.org/{z}/{x}/{y}.png') marker_outline = CircleMarker((42.883333, -9.883333), 'white', 18) marker = CircleMarker((42.883333, -9.883333), '#0036FF', 12) m.add_marker(marker_outline) m.add_marker(marker) image = m.render() image.save('map.png')
def location(bot, update): # Colors: Red, Blue, Purple, Green, Yellow, Brown, Orange, Grey listOfColor = ['#8B0000', '#0000FF', '#8A2BE2', '#228B22', '#FFD700', '#8B4513', '#D2691E', '#808080' user = User.objects.get(chat_id=update.message.chat_id) point = Point(user.lon, user.lat) # Distance in KM to search the parkings close by radius = 0.5 radius = radius / 40000 * 360 circle = point.buffer(radius) shape = multiPolygonHandler.getMultiPolygonByPoint(point) m = StaticMap(600, 800, 12, 12, tile_size=256) marker_outline = CircleMarker((user.lon, user.lat), 'white', 22) marker = CircleMarker((user.lon, user.lat), 'Red', 18) m.add_marker(marker_outline) m.add_marker(marker) circleLine = Line(circle[0], color='red', width=3) geoCircle = GEOPolygon(circle[0]) # Draw the circle for compare it with closest parkings m.add_line(circleLine) listPolygon, listOfColor2, listOfMultiPolygon = getAllPolygonsInCircleArea(geoCircle) i = 0 if len(listPolygon) is not 0: for p in listPolygon: polygonLine = Line(p[0], color=listOfColor[i], width=3) m.add_line(polygonLine) i = i + 1 image = m.render(zoom=14) fileName = 'ParkingStreet' + str(update.message.chat_id) + '.png' image.save(fileName) baseDir = settings.BASE_DIR picture = open(baseDir + '/' + fileName, 'rb') text = buildParkingZoneMessage(listOfMultiPolygon) btn_keyboard1 = KeyboardButton(text="Find another parking") btn_keyboard2 = KeyboardButton(text="Find closest electric charge point") btn_keyboard3 = KeyboardButton(text="Show my profile") btn_keyboard4 = KeyboardButton(text="That's all, thanks") custom_keyboard = [[btn_keyboard1], [btn_keyboard2], [btn_keyboard3], [btn_keyboard4]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard, resize_keyboard=True, one_time_keyboard=True) bot.sendPhoto(chat_id=update.message.chat_id, photo=picture) bot.sendMessage(chat_id=update.message.chat_id, text=text, parse_mode='HTML') bot.sendMessage(chat_id=update.message.chat_id, text='What do you want to do now?', reply_markup=reply_markup) userHandler.setUserBotActived(update.message.chat_id, True) else: btn_keyboard1 = KeyboardButton(text="Find another parking") btn_keyboard2 = KeyboardButton(text="Find closest electric charge point") btn_keyboard3 = KeyboardButton(text="Show my profile") btn_keyboard4 = KeyboardButton(text="That's all, thanks") custom_keyboard = [[btn_keyboard1], [btn_keyboard2], [btn_keyboard3], [btn_keyboard4]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard, resize_keyboard=True, one_time_keyboard=True) bot.sendMessage(chat_id=update.message.chat_id, text='There is no parking info close to your position.') bot.sendMessage(chat_id=update.message.chat_id, text='What do you want to do now?', reply_markup=reply_markup) userHandler.setUserBotActived(update.message.chat_id, True)
def print_path(path, G, file): m = StaticMap(800, 800) # go through the path and print every node for i in range(len(path) - 1): marker = CircleMarker(path[i], 'red', 6) m.add_marker(marker) coordinates = [path[i], path[i + 1]] line = Line(coordinates, 'blue', 1) m.add_line(line) marker = CircleMarker(path[len(path) - 1], 'red', 6) m.add_marker(marker) image = m.render() image.save(file)
def draw_map_route(graph, src, dst): fitxer = "%d.png" % random.randint(1000000, 9999999) route_node_list = graphs.get_graph_route(graph, src, dst) mapa = StaticMap(500, 500) mapa.add_marker(CircleMarker(route_node_list[0].lon_lat(), 'blue', 5)) for i in range(len(route_node_list) - 1): mapa.add_marker( CircleMarker(route_node_list[i + 1].lon_lat(), 'blue', 5)) mapa.add_line( Line((route_node_list[i].lon_lat(), route_node_list[i + 1].lon_lat()), 'blue', 1)) imatge = mapa.render() imatge.save(fitxer) return fitxer
def FindBusLocation(busName, routeCode): #routeCode = "2006" response = requests.post( "http://telematics.oasa.gr/api/?act=getBusLocation&p1={}".format( routeCode)) json_response = response.json() #busCoordinateList = [] stopCoordinateList = [] #zoomValue = 14 m = StaticMap(1200, 1200) if json_response: for resp in json_response: CS_LNG = float(resp["CS_LNG"]) CS_LAT = float(resp["CS_LAT"]) marker = IconMarker([CS_LNG, CS_LAT], "BusMarker.png", 17, 62) m.add_marker(marker) #busCoordinateList.append([CS_LNG,CS_LAT]) #for coordinate in busCoordinateList: #marker = CircleMarker(coordinate, '#4286f4', 12) #zoomValue -= 1 response = requests.post( "http://telematics.oasa.gr/api/?act=webGetStops&p1={}".format( routeCode)) json_response = response.json() for resp in json_response: StopLng = float(resp["StopLng"]) StopLat = float(resp["StopLat"]) stopCoordinateList.append([StopLng, StopLat]) #for coordinate in stopCoordinateList: # marker = CircleMarker(coordinate, '#4286f4', 12) # m.add_marker(marker) firstStop = CircleMarker(stopCoordinateList[0], '#37fc4b', 12) #first stop lastStop = CircleMarker(stopCoordinateList[-1], '#f45c42', 12) #last stop m.add_marker(firstStop) m.add_marker(lastStop) line = Line( stopCoordinateList, '#4286f4', 4) #draw a line through all stops, which is basically the route itself m.add_line(line) mapImg = m.render() mapImg.save("BusLocation.png") return mapImg
def plotgraph(G, name_file): map = StaticMap(750, 750) for station in G.edges: coord1, coord2 = station[0], station[1] line = Line([[coord1.lon, coord1.lat], [coord2.lon, coord2.lat]], '#0000FFBB', 2) map.add_line(line) for station in G.nodes: marker = CircleMarker([station.lon, station.lat], 'red', 4) marker_outline = CircleMarker([station.lon, station.lat], 'black', 8) map.add_marker(marker_outline) map.add_marker(marker) image = map.render() image.save(name_file)
def plotRoute(self, src, dst): isSRC = False isDST = False fctSRC = 0 fctDST = 0 for zona in self.MAPA: for ciutat in zona: stringCiutat = str(ciutat.nom) + ", " + str(ciutat.country) factor = fuzz.partial_ratio(stringCiutat, src.lower()) if factor > fctSRC: ciutatSRC = ciutat isSRC = True fctSRC = factor factor = fuzz.partial_ratio(stringCiutat, dst.lower()) if factor >= fctDST: ciutatDST = ciutat isDST = True fctDST = factor if (not isSRC) | (not isDST): print("NO") else: distancia = haversine((ciutatSRC.latitude, ciutatSRC.longitude), (ciutatDST.latitude, ciutatDST.longitude)) cami = nx.dijkstra_path(self.G, ciutatSRC, ciutatDST) mapa = StaticMap(600, 600) i = 0 if len(cami) == 1: mapa.add_marker( CircleMarker((cami[i].longitude, cami[i].latitude), 'red', 3)) else: while i < (len(cami) - 1): ciutatO = cami[i] ciutatD = cami[i + 1] mapa.add_marker( CircleMarker((ciutatO.longitude, ciutatO.latitude), 'red', 3)) mapa.add_marker( CircleMarker((ciutatD.longitude, ciutatD.latitude), 'red', 3)) mapa.add_line( Line(((ciutatO.longitude, ciutatO.latitude), (ciutatD.longitude, ciutatD.latitude)), 'blue', 2)) i += 1 image = mapa.render() image.save('route.png')
def route(self, src, dst): ''' Returns the plot of the shortest route between src and dst ''' real_src = self.get_most_similar(src) real_dst = self.get_most_similar(dst) if real_src and real_dst: try: path = nx.algorithms.shortest_paths.generic.shortest_path( self.G, source=real_src, target=real_dst, weight='weight') except Exception as e: return c.PATH_FAIL mapa = StaticMap(400, 400) for cities in zip([''] + path, path): rev_coords_1 = tuple(reversed(self.coordinates[cities[1]])) circle = CircleMarker(rev_coords_1, 'red', 4) mapa.add_marker(circle) if '' in cities: continue rev_coords_0 = tuple(reversed(self.coordinates[cities[0]])) mapa.add_line(Line((rev_coords_0, rev_coords_1), 'blue', 3)) image = mapa.render() bio = BytesIO() bio.name = 'map.png' image.save(bio) bio.seek(0) return bio if not real_src: return c.SOURCE_FAIL return c.DEST_FAIL
def plotpop(self, lat, lon, dist): ''' Returns the plot of the graph of the cities that have distance lower than dist from (lat, lon) ''' mapa = StaticMap(400, 400) some = False max_pop = 0 for node in self.G.nodes: if self.is_plottable((node, node), (lat, lon), dist): some = True if max_pop < self.populations[node]: max_pop = self.populations[node] if not some: return for node in self.G.nodes: if self.is_plottable((node, node), (lat, lon), dist): rev_coords = tuple(reversed(self.coordinates[node])) circle = CircleMarker( rev_coords, 'red', self.populations[node] * c.CIRCLE_SCALE / max_pop) mapa.add_marker(circle) image = mapa.render() bio = BytesIO() bio.name = 'map.png' image.save(bio) bio.seek(0) return bio
def set_moving_obstacles(self, moving_obstacles): self.moving_obstacles = [] for obstacle in moving_obstacles: print("here i am") self.moving_obstacles.append(CircleMarker((obstacle), 'green', 12)) self.refresh_map() self.master.update()
def drawRoute(G, path): m = StaticMap(400, 400) m.add_marker( CircleMarker( (G.nodes[path[0]]['longitude'], G.nodes[path[0]]['latitude']), 'red', 3)) for i in range(len(path) - 1): m.add_marker( CircleMarker((G.nodes[path[i + 1]]['longitude'], G.nodes[path[i + 1]]['latitude']), 'red', 3)) m.add_line( Line( ((G.nodes[path[i]]['longitude'], G.nodes[path[i]]['latitude']), (G.nodes[path[i + 1]]['longitude'], G.nodes[path[i + 1]]['latitude'])), 'blue', 1)) image = m.render() image.save('plotroute.png')
def paintMapPop(self): m = StaticMap(2000,1500,20) for n in self.subgraph.nodes: point = (float(self.lista[int(n)][6]),float(self.lista[int(n)][5])) pob = float(self.lista[int(n)][4]) tam = int(pob/100000)+1 m.add_marker(CircleMarker(point,'red',tam)) image = m.render() image.save("pop.png")
def draw_map_plotpop(graph, dist, lat, lon): fitxer = "%d.png" % random.randint(1000000, 9999999) reduced_graph = graphs.get_graph_dist_lat_lon(graph, dist, lat, lon) mapa = StaticMap(500, 500) for node in reduced_graph: mapa.add_marker( CircleMarker(node.lon_lat(), 'blue', node.population / 1000000)) imatge = mapa.render() imatge.save(fitxer) return fitxer
def plot_route(path, filename): ''' Creates a file with the map of Barcelona showing the route indicated in path.''' mapa = StaticMap(800, 800) last = path[0] for node in path: if node.coords() != last.coords(): mapa.add_marker(CircleMarker(last.coords(), 'blue', 6)) coord = [list(node.coords()), list(last.coords())] if (node == path[1] or node == path[-1]): line = Line(coord, 'red', 3) else: line = Line(coord, 'blue', 3) mapa.add_line(line) last = node mapa.add_marker(CircleMarker(path[0].coords(), 'red', 8)) mapa.add_marker(CircleMarker(path[-1].coords(), 'red', 8)) imatge = mapa.render() imatge.save(filename)
def paintMapGraph(self): m = StaticMap(2000,1500,20) for (n, nbrs) in self.subgraph.edges: origen = (float(self.lista[int(n)][6]),float(self.lista[int(n)][5])) desti = (float(self.lista[int(nbrs)][6]),float(self.lista[int(nbrs)][5])) m.add_line(Line([origen,desti],'blue',2)) for n in self.subgraph.nodes: point = (float(self.lista[int(n)][6]),float(self.lista[int(n)][5])) m.add_marker(CircleMarker(point,'red',7)) image = m.render() image.save('graph.png')
def draw_map_plotgraph(graph, dist, lat, lon): fitxer = "%d.png" % random.randint(1000000, 9999999) reduced_graph = graphs.get_graph_dist_lat_lon(graph, dist, lat, lon) mapa = StaticMap(500, 500) for node in reduced_graph: mapa.add_marker(CircleMarker(node.lon_lat(), 'blue', 5)) for (u, v) in reduced_graph.edges(): mapa.add_line(Line((u.lon_lat(), v.lon_lat()), 'blue', 1)) imatge = mapa.render() imatge.save(fitxer) return fitxer