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 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 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 get_border(self): vs = self.get_vertices() vs = [[x[1], x[0]] for x in vs] l1 = Line([vs[0], vs[1]], 'darkgray', 1) l2 = Line([vs[1], vs[2]], 'darkgray', 1) l3 = Line([vs[2], vs[3]], 'darkgray', 1) l4 = Line([vs[3], vs[0]], 'darkgray', 1) return [l1, l2, l3, l4]
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 draw_map(location_entry): m = StaticMap(400, 400, 80) locations = location_entry["locations"] coordinates = transform(locations) line_outline = Line(coordinates, 'white', 4) line = Line(coordinates, '#D2322D', 3) m.add_line(line_outline) m.add_line(line) image = m.render() byte_io = BytesIO() image.save(byte_io, 'PNG') return byte_io.getvalue()
def img_fire(user_coordinates_lat, user_coordinates_lon): m = StaticMap(800, 800, 80) coordinates = [[ min_distance(user_coordinates_lat, user_coordinates_lon)[1][0], min_distance(user_coordinates_lat, user_coordinates_lon)[1][1] ]] line_outline = Line(coordinates, 'white', 6) line = Line(coordinates, '#D2322D', 10) m.add_line(line_outline) m.add_line(line) image = m.render() image.save(IMAGE_FILE)
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 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 plotgraph(self, lat, lon, dist): ''' Returns the plot of the graph of the edges between cities that have distance than dist from (lat, lon) ''' mapa = StaticMap(400, 400) some = False for edge in self.G.edges: if self.is_plottable(edge, (lat, lon), dist): some = True # Staticmap needs coordinates in order (Longitude, Latitude) rev_coords_0 = tuple(reversed(self.coordinates[edge[0]])) rev_coords_1 = tuple(reversed(self.coordinates[edge[1]])) mapa.add_line(Line((rev_coords_0, rev_coords_1), 'blue', 3)) if not some: return image = mapa.render() bio = BytesIO() bio.name = 'map.png' image.save(bio) bio.seek(0) return bio
def getRSSIMax(): """ fonction who search in the DB the best signal reception and despaly it in the map""" m = StaticMap(largeur, hauteur, url_template='http://a.tile.osm.org/{z}/{x}/{y}.png') cursor.execute("""SELECT max(RSSI) FROM coord """) rssi = cursor.fetchone() print rssi cursor.execute( """SELECT e_lat, e_long, s_lat, s_long, distance, SNR FROM coord WHERE RSSI=?""", rssi) coord = cursor.fetchone() #getGPS() print coord lat_E, long_E, lat_S, long_S = coord[0], coord[1], coord[2], coord[3] m.add_line(Line(((long_S, lat_S), (long_E, lat_E)), 'blue', 3)) icon_flag_1 = IconMarker((long_E, lat_E), 'icon/icon-flag.png', 12, 32) m.add_marker(icon_flag_1) icon_flag_2 = IconMarker((long_S, lat_S), 'icon/icon-flag.png', 12, 32) m.add_marker(icon_flag_2) global image image = m.render() image.save('map/RSSIMaxMap.png') image = PhotoImage(file='map/RSSIMaxMap.png') canvas.create_image(0, 0, image=image, anchor=NW) latLabel.configure(text=coord[0]) longLabel.configure(text=coord[1]) distenceLabel.configure(text=coord[4]) rssiLabel.configure(text=coord[4]) snrLabel.configure(text=coord[5])
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 paintEdges(g, mapa): for m in list(g.edges): first_node = m[0] second_node = m[1] if g.nodes[first_node]['visible'] and g.nodes[second_node]['visible']: mapa.add_line(Line(((g.nodes[first_node]['longitude'], g.nodes[first_node]['latitude']), (g.nodes[second_node]['longitude'], g.nodes[second_node]['latitude'])), 'blue', 1)) return mapa
def main( conn: connection, journey_id: int, last_location: t.Optional[dict], current_lat: float, current_lon: float, current_distance: float, steps_data: list[dict], gargling_info: dict[int, dict], ) -> t.Optional[bytes]: old_coords, locations, overview_coords, detailed_coords = traversal_data( conn, journey_id, last_location, current_lat, current_lon, current_distance, steps_data, ) template = "https://a.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png" height = 600 width = 1000 overview_map = StaticMap(width=width, height=height, url_template=template) if old_coords: overview_map.add_line(Line(old_coords, "grey", 2)) for lon, lat in locations: overview_map.add_marker(CircleMarker((lon, lat), "blue", 6)) overview_map.add_line(Line(overview_coords, "red", 2)) overview_map.add_marker(CircleMarker((current_lon, current_lat), "red", 6)) detailed_map = StaticMap(width=width, height=height, url_template=template) start = detailed_coords[0]["coords"][0] detailed_map.add_marker(CircleMarker(start, "black", 6)) detailed_map.add_marker(CircleMarker(start, "grey", 4)) for gargling in detailed_coords: color = gargling_info[gargling["gargling_id"]]["color_hex"] detailed_map.add_line(Line(gargling["coords"], "grey", 4)) detailed_map.add_line(Line(gargling["coords"], color, 2)) detailed_map.add_marker( CircleMarker(gargling["coords"][-1], "black", 6)) detailed_map.add_marker(CircleMarker(gargling["coords"][-1], color, 4)) legend = map_legend(detailed_coords, gargling_info) overview_img = render_map(overview_map) detailed_img = render_map(detailed_map) img = merge_maps(overview_img, detailed_img, legend) return img
def create_staticmaps(trail_id, base_uri): from .models import Trail current_trail = Trail.objects.get(pk=trail_id) try: static_thumbnail = StaticMap(425, 225, 10, 10, base_uri + '/trail/api/tile/{z}/{x}/{y}.png', tile_request_timeout=180) static_hero = StaticMap(1280, 480, 10, 10, base_uri + '/trail/api/tile/{z}/{x}/{y}.png', tile_request_timeout=180) for track in current_trail.tracks: coordinates = get_coordinates(track['points']) static_thumbnail.add_line(Line(coordinates, 'white', 11)) static_hero.add_line(Line(coordinates, 'white', 11)) for track in current_trail.tracks: coordinates = get_coordinates(track['points']) static_thumbnail.add_line(Line(coordinates, '#2E73B8', 5)) static_hero.add_line(Line(coordinates, '#2E73B8', 5)) image_thumbnail = static_thumbnail.render() image_hero = static_hero.render() file_thumbnail = io.BytesIO(b'') file_hero = io.BytesIO(b'') image_thumbnail.save(file_thumbnail, format='JPEG', optimize=True, progressive=True) image_hero.save(file_hero, format='JPEG', optimize=True, progressive=True) current_trail.thumbnail.delete(save=False) current_trail.thumbnail.save('thumbnail.jpg', file_thumbnail) current_trail.hero.delete(save=False) current_trail.hero.save('hero.jpg', file_hero) except: # TODO pass current_trail.is_draft = False current_trail.save() # TODO Translate to = mail( current_trail.name, 'Your trail is ready.\n\n' + 'https://mountainbikers.club' + reverse('trail__main', args=[current_trail.id]) ) to([current_trail.author.email])
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 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
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 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 print_map(G, filename): m = StaticMap(800, 800) # print nodes on the map for n in G.nodes(): marker = CircleMarker(n, 'red', 6) m.add_marker(marker) # print edges on the map for n2 in G.edges(data=True): coordinates = [n2[0], n2[1]] line = Line(coordinates, 'blue', 1) m.add_line(line) image = m.render() image.save(filename)
def ploting(G, position): m = StaticMap(400, 500) for j in G.edges(): coord1 = swap(position[j[0]]) coord2 = swap(position[j[1]]) m.add_line(Line((coord1, coord2), 'blue', 1)) for i in G.nodes(): m.add_marker(CircleMarker(swap(position[i]), 'red', 2)) return m
def plot_graph(G, filename): ''' Creates a file (filename) with the map of Barcelona showing all Bicing stations and the edges of the graph that connect them. ''' mapa = StaticMap(800, 800) for node in list(G.nodes): mapa.add_marker(CircleMarker(node.coords(), 'red', 5)) for node1, node2 in list(G.edges): coord = [list(node1.coords()), list(node2.coords())] line = Line(coord, 'blue', 1) mapa.add_line(line) imatge = mapa.render() imatge.save(filename)
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 drawGraph(dist, lat, lon, graph): m = StaticMap(400, 400) returned = nodesAtDistFrom(dist, lat, lon, graph) G = returned[0] for node in list(G.nodes): m.add_marker( CircleMarker( (G.nodes[node]['longitude'], G.nodes[node]['latitude']), 'red', 3)) for connection in list(G.adj[node]): m.add_line( Line(((G.nodes[node]['longitude'], G.nodes[node]['latitude']), (G.nodes[connection]['longitude'], G.nodes[connection]['latitude'])), 'blue', 0)) image = m.render() image.save('plotgraph.png')
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 getmap(lat_server, lon_server, lat_client, lon_client, largeur, hauteur, zoom): m = StaticMap(largeur, hauteur, url_template='http://b.tile.osm.org/{z}/{x}/{y}.png') m.add_line( Line(((lon_server, lat_server), (lon_client, lat_client)), 'blue', 3)) icon_flag_1 = IconMarker((lon_client, lat_client), 'icon/icon-flag.png', 12, 32) m.add_marker(icon_flag_1) icon_flag_2 = IconMarker((lon_server, lat_server), 'icon/icon-flag.png', 12, 32) m.add_marker(icon_flag_2) image = m.render() image.save('map/map.png')
def process_line(l, pnv): """Creates a list of Line objects with the properties from the request""" l_properties = dict(item.split(':') for item in l.split('|')) l_coords = l_properties['coords'].split(';') assert len(l_coords) > 1 l_color = l_properties['color'] check_hex_code(l_color) l_width = int(l_properties['width']) l_segments = [] s_coordinates = [] i = 0 for coord in l_coords: pnv = pnv_counter(pnv) s_coordinate = [] s_coordinate.append(float(coord.split(',')[1])) s_coordinate.append(float(coord.split(',')[0])) # Polyline handling if i == 0: s_coordinates.append(s_coordinate) elif i == 1: s_coordinates.append(s_coordinate) coord_for_next_loop = s_coordinate else: s_coordinates.append(coord_for_next_loop) s_coordinates.append(s_coordinate) coord_for_next_loop = s_coordinate if len(s_coordinates) % 2 == 0: l_segment = Line(s_coordinates, l_color, l_width) l_segments.append(l_segment) s_coordinates = [] i += 1 return l_segments, pnv