def plotLocation(df, df2=None): # Sensor locations latSensor = [50.12565556, 50.10290556, 50.12691389] lonSensor = [8.69305556, 8.54222222, 8.74861111] # Create a basic map using OpenStreetMap centerPoint = (8.69305556, 50.12565556) degree_range = 0.1 extent = tilemapbase.Extent.from_lonlat( centerPoint[0] - 1.6 * degree_range, centerPoint[0] + degree_range, centerPoint[1] - degree_range, centerPoint[1] + degree_range) extent = extent.to_aspect(1.0) plotter = tilemapbase.Plotter(extent, t, width=600) fig, ax = plt.subplots(figsize=(8, 8), dpi=100) plotter.plot(ax, t) plotxSensor = [] plotySensor = [] for i in range(len(latSensor)): setTEMP = (lonSensor[i], latSensor[i]) x, y = tilemapbase.project(*setTEMP) plotxSensor.append(x) plotySensor.append(y) lonTEMP = df["Lon"] latTEMP = df["Lat"] plotx = [] ploty = [] for i in range(len(lonTEMP)): setTEMP = (lonTEMP.iloc[i], latTEMP.iloc[i]) x, y = tilemapbase.project(*setTEMP) plotx.append(x) ploty.append(y) ax.scatter(plotx, ploty, label="Loops") ax.scatter(plotxSensor, plotySensor, label="Sensor") plotx_add = [] ploty_add = [] if df2 is not None: colList = [ df2.columns[i] for i in range( 1, df2.columns.get_loc("Stickstoffmonoxid (NO)[µg/m³]")) ] for column in colList: location = df[df["ElemUID"] == int(column)] setTEMP = (location["Lon"].values[0], location["Lat"].values[0]) x, y = tilemapbase.project(*setTEMP) plotx_add.append(x) ploty_add.append(y) ax.scatter(plotx_add, ploty_add, c="green", label="Reduced Loops") plt.legend() plt.show()
def drawp(df, poly_col, val_col, extent, color_selector, figsize=(8, 8), dpi=100, width=600, alpha=0.8): fig, ax = plt.subplots(figsize=figsize, dpi=dpi) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) t = tmb.tiles.build_OSM() plotter = tmb.Plotter(extent, t, width=width) plotter.plot(ax, t) n = len(df) for i in range(n): val = df[val_col].iloc[i] color = color_selector(val) vts = df[poly_col].iloc[i]["coordinates"][0] xys = [tmb.project(*x) for x in vts] poly = plt.Polygon(xys, fc=color, alpha=alpha) ax.add_patch(poly) fig.text(0.86, 0.125, '© DATAWISE', va='bottom', ha='right') return fig, ax
def draw(df, id_col, val_col, extent, color_selector, figsize=(8, 8), dpi=100, width=600, alpha=0.8, axis_visible=False, **kwargs): fig, ax = plt.subplots(figsize=figsize, dpi=dpi) ax.xaxis.set_visible(axis_visible) ax.yaxis.set_visible(axis_visible) t = tmb.tiles.build_OSM() plotter = tmb.Plotter(extent, t, width=width) plotter.plot(ax, t) add_color_bar(df, val_col, fig, color_selector, **kwargs) n = len(df) for i in range(n): id = df[id_col].iloc[i] val = df[val_col].iloc[i] color = color_selector(val) vts = _swap(h3.h3_to_geo_boundary(id)) xys = [tmb.project(*x) for x in vts] poly = plt.Polygon(xys, fc=color, alpha=alpha) ax.add_patch(poly) fig.text(0.86, 0.125, '© DATAWISE', va='bottom', ha='right') return fig, ax
def plot_coords(ground_truth, coords, degree_range=0.0001): tilemapbase.start_logging() tilemapbase.init(create=True) t = tilemapbase.tiles.build_OSM() degree_range = degree_range center_lat = np.mean(np.array([coord[0] for coord in ground_truth])) center_lon = np.mean(np.array([coord[1] for coord in ground_truth])) extent = tilemapbase.Extent.from_lonlat(center_lon - degree_range, center_lon + degree_range, center_lat - degree_range, center_lat + degree_range) extent = extent.to_aspect(1.0) fig, ax = plt.subplots(figsize=(8, 8), dpi=100) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) plotter = tilemapbase.Plotter(extent, t, width=600) plotter.plot(ax, t) # for coord in ground_truth: # x, y = tilemapbase.project(coord[1], coord[0]) # ax.scatter(x,y, marker="*", color="red", linewidth=5) for idx, coord in enumerate(coords): x, y = tilemapbase.project(coord[2], coord[1]) ax.scatter(x, y, marker=".", c=(0, 1 - (1 / len(coords)) * idx, (1 / len(coords)) * idx), linewidth=1) plt.show()
def printRoute(self, dpi, width): tilemapbase.start_logging() tilemapbase.init(create=True) t = tilemapbase.tiles.build_OSM() if self.s[0] < self.e[0]: south = self.s[0] north = self.e[0] else: south = self.e[0] north = self.s[0] if self.s[1] < self.e[1]: east = self.s[1] west = self.e[1] else: east = self.e[1] west = self.s[1] degree_range = 0.1 extent = tilemapbase.Extent.from_lonlat(east - degree_range, west + degree_range, south - degree_range, north + degree_range) fig, ax = plt.subplots(figsize=(8, 8), dpi=dpi) plotter = tilemapbase.Plotter(extent, t, width=width) plotter.plot(ax, t) for i in self.routeLatLons: x, y = tilemapbase.project(i[1], i[0]) ax.scatter(x, y, marker=".", color="black", linewidth=2) plt.show()
def trace_trajectoire(self,Latitude,Longitude,centre): print("trace") #self.centre_mean = (np.mean(Longitude),np.mean(Latitude)) #print(self.centre_mean) self.centre = centre print("Longitude: ",Longitude) print("Lat : ",Latitude) self.i = self.gps_carte_fond(centre,self.i) if Latitude is not None : path = [tilemapbase.project(x,y) for x,y in zip(Longitude,Latitude)] x,y = zip(*path) #print(x) x0,y0 = tilemapbase.project(*self.centre) self.axe.plot(x,y,'ro-') self.axe.plot(x0,y0,'b>') self.axe.axis("off") self.graph.draw()
def get_xy(data, spe=''): list_x = [] list_y = [] for index in data.index: x, y = tilemapbase.project(data.lon[index], data.lat[index]) list_x.append(x) list_y.append(y) c = data[spe] return (list_x, list_y, c)
def gps_waypoints(self): if self.fenetre_graph.update_graph.Matrice is not None : self.axe.clear() #self.affichage_carte = False self.gps_carte_fond() #print("nouveau point") path = [tilemapbase.project(x,y) for x,y in zip(self.Longitude,self.Latitude)] x, y = zip(*path) self.axe.plot(x,y,'ro-') self.axe.axis("off") self.graph.draw()
def _draw_png(df, lats, lngs, p_size, p_color, l_size, l_color, figsize=(8, 8), dpi=100, axis_visible=False, padding=0.03, adjust=True): ex1 = tmb.Extent.from_lonlat(min(lngs), max(lngs), min(lats), max(lats)) ex2 = _expand(ex1, padding) extent = ex2.to_aspect(figsize[0] / figsize[1], shrink=False) if adjust else ex2 fig, ax = plt.subplots(figsize=figsize, dpi=dpi) ax.xaxis.set_visible(axis_visible) ax.yaxis.set_visible(axis_visible) t = tmb.tiles.build_OSM() plotter = tmb.Plotter(extent, t, width=figsize[0] * 100, height=figsize[1] * 100) plotter.plot(ax, t) ps = [tmb.project(x, y) for x, y in zip(lngs, lats)] xs = [p[0] for p in ps] ys = [p[1] for p in ps] n = len(df) for i in range(n - 1): l2 = lines.Line2D(xs[i:(i + 2)], ys[i:(i + 2)], linewidth=l_size[i], color=l_color[i]) ax.add_line(l2) for i in range(n): x, y = ps[i] ax.plot(x, y, marker=".", markersize=p_size[i], color=p_color[i]) fig.text(0.8875, 0.125, '© DATAWISE', va='bottom', ha='right') return fig, ax
def osm_plot(path): path = np.array(path) path = path[:, 0:2] margins = [38.1598, 38.163, -122.457, -122.451] # lats, lons degree_range = 0.0015 extent = tilemapbase.Extent.from_lonlat( latitude_min=margins[0] - degree_range, latitude_max=margins[1] + degree_range, longitude_min=margins[2] - degree_range, longitude_max=margins[3] + degree_range) extent = extent.to_aspect(1.0) points = np.array( [tilemapbase.project(*waypoint[::-1]) for waypoint in path]) x, y = points[:, 0], points[:, 1] # x, y = tilemapbase.project(*goal_loc[::-1]) fig, ax = plt.subplots(figsize=(6, 6)) plotter = tilemapbase.Plotter(extent, tile_provider=tilemapbase.tiles.build_OSM(), width=600) plotter.plot(ax) ax.scatter(x[0], y[0], marker=".", color="black", linewidth=10) ax.scatter(x[-1], y[-1], marker="x", color="red", linewidth=2) ax.plot(x, y, linewidth=2) ax.scatter(x, y, marker=".", color="green", linewidth=1) plt.xlabel('Longitude') plt.ylabel('Latitude') plt.xticks([]), plt.yticks([]) plt.tight_layout() ax.grid(b=True, which='major', color='#666666', linestyle='-') ax.minorticks_on() ax.grid(b=True, which='minor', color='#999999', linestyle='-', alpha=0.2) plt.show()
if lat is not None and lon is not None: pos_lats.append(lat) pos_longs.append(lon) color_vals.append(v if v is not None else 0.0) min_color_val = min(color_vals) max_color_val = max(color_vals) # add a bit to the max value max_color_val += (max_color_val - min_color_val) * 0.01 color_intervals = np.linspace(min_color_val, max_color_val, colors + 1) if background: try: path = [tilemapbase.project(x, y) for x, y in zip(pos_longs, pos_lats)] except ValueError: print("something is wrong with the coordinates.") sys.exit(1) path_x, path_y = zip(*path) else: path_x, path_y = pos_longs, pos_lats mid_x = (min(path_x) + max(path_x)) / 2. mid_y = (min(path_y) + max(path_y)) / 2. size_x = (max(path_x) - min(path_x)) * 1.618033988749894 size_y = (max(path_y) - min(path_y)) * 1.618033988749894 size = max(size_x, size_y) min_x = mid_x - size / 2. max_x = mid_x + size / 2. min_y = mid_y - size / 2.
def lon_lat_to_tile_space(self, lon, lat): """Convert to actual tile coordinates.""" scale = 2**self._zoom * self.tile_size x, y = tilemapbase.project(lon, lat) return x * scale, y * scale
def update_map(self): """ """ if not self.isVisible(): self.last_used_latitude = 0.0 self.last_used_longitude = 0.0 self.last_used_degree_range = 0.0 return try: survey = app_core.DesktopAppSync().get_selected_survey() item_id = app_core.DesktopAppSync().get_selected_item_id() item_metadata = app_core.DesktopAppSync().get_metadata_dict() item_title = item_metadata.get('item_title', '') latitude_dd = item_metadata.get('rec_latitude_dd', '') if not latitude_dd: latitude_dd = item_metadata.get('latitude_dd', '') longitude_dd = item_metadata.get('rec_longitude_dd', '') if not longitude_dd: longitude_dd = item_metadata.get('longitude_dd', '') # self.survey_edit.setText(survey) self.itemid_edit.setText(item_id) self.title_edit.setText(item_title) # if not item_id: self.last_used_latitude = 0.0 self.last_used_longitude = 0.0 self.last_used_degree_range = 0.0 self.axes.cla() self._canvas.draw() return # lat_dd = 0.0 long_dd = 0.0 try: lat_dd = float(latitude_dd) long_dd = float(longitude_dd) except: self.last_used_latitude = 0.0 self.last_used_longitude = 0.0 self.last_used_degree_range = 0.0 self.axes.cla() self._canvas.draw() return # if (lat_dd == 0.0) or (long_dd == 0): # Clear. self.last_used_latitude = 0.0 self.last_used_longitude = 0.0 self.last_used_degree_range = 0.0 self.axes.cla() self._canvas.draw() return current_position = (long_dd, lat_dd) degree_range = 0.05 zoom_range = self.zoom_combo.currentText() try: degree_range = float(zoom_range) except: pass # Don't redraw the same map. if (self.last_used_latitude == lat_dd) and \ (self.last_used_longitude == long_dd) and \ (self.last_used_degree_range == degree_range): return # self.last_used_latitude = lat_dd self.last_used_longitude = long_dd self.last_used_degree_range = degree_range # extent = tilemapbase.Extent.from_lonlat( current_position[0] - degree_range, current_position[0] + degree_range, current_position[1] - degree_range, current_position[1] + degree_range) extent = extent.to_aspect(1.0) self.axes.cla() self.axes.xaxis.set_visible(False) self.axes.yaxis.set_visible(False) plotter = tilemapbase.Plotter(extent, self.osm_tiles, width=600) plotter.plot(self.axes, self.osm_tiles) x, y = tilemapbase.project(*current_position) self.axes.scatter(x, y, marker=".", color="black", linewidth=20) # self._canvas.draw() except Exception as e: debug_info = self.__class__.__name__ + ', row ' + str( sys._getframe().f_lineno) app_utils.Logging().error('Exception: (' + debug_info + '): ' + str(e))
def from_lonlat(longitude_min, longitude_max, latitude_min, latitude_max): """Construct a new instance from longitude/latitude space.""" xmin, ymin = tilemapbase.project(longitude_min, latitude_max) xmax, ymax = tilemapbase.project(longitude_max, latitude_min) return CustomExtent(xmin, xmax, ymin, ymax)
if EXTENT: extent = EXTENT else: extent = list(np.percentile(df.coordinates_lon, (EXCLUDE_DATA_THRESHOLD, 100 - EXCLUDE_DATA_THRESHOLD))) + \ list(np.percentile(df.coordinates_lat, (EXCLUDE_DATA_THRESHOLD, 100 - EXCLUDE_DATA_THRESHOLD))) map_extent = CustomExtent.from_lonlat(*extent) map_extent = map_extent.to_aspect(ASPECT_RATIO) # Reprojecting extant extent = [map_extent.xmin, map_extent.xmax, map_extent.ymin, map_extent.ymax] # Reprojecting coordinates df.coordinates_lon = df.coordinates_lon.apply( lambda x: tilemapbase.project(x, 0)[0]) df.coordinates_lat = df.coordinates_lat.apply( lambda x: tilemapbase.project(0, x)[1]) # Editing colormap ref_cm = plt.get_cmap(COLORMAP) if REVERSE_COLORMAP: ref_cm = ref_cm.reversed() # Giving colormap a gradual alpha color_list = ref_cm(np.arange(ref_cm.N)) color_list = color_list[math.floor(len(color_list) * COLORMAP_CUT):, ] color_list[:, -1] = [ MAX_ALPHA * (MIN_ALPHA + (math.log(1 + x, len(color_list)) * (1 - MIN_ALPHA))) for x in range(0, len(color_list)) ] # Log distribution of alpha
my_office = (-1.554934, 53.804198) degree_range = 0.003 extent = tilemapbase.Extent.from_lonlat(my_office[0] - degree_range, my_office[0] + degree_range, my_office[1] - degree_range, my_office[1] + degree_range) extent = extent.to_aspect(1.0) #The path to plot longs = [-1.554934, -1.555, -1.5552, -1.554] lats = [53.804198, 53.80416, 53.8041, 53.8042] # Convert to web mercator path = [tilemapbase.project(x, y) for x, y in zip(longs, lats)] for x, y in zip(longs, lats): print(x, y) x, y = zip(*path) fig, ax = plt.subplots(figsize=(10, 10)) plotter = tilemapbase.Plotter(extent, tilemapbase.tiles.build_OSM(), width=600) plotter.plot(ax) ax.plot(x, y, "ro-") fig.show() input() plotter.plot(plt.axes()) plt.plot(x, y, "ro-")
# extent = extent.to_aspect(1.0) fig, ax = plt.subplots(figsize=figure_size) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) plotter = tilemapbase.Plotter(extent, tiles, width=600) plotter.plot(ax, tiles) # Convert GPS coordinates to "Web Mercator" projection, normalised between 0 # and 1. x_coordinates = [] y_coordinates = [] for x, y in zip(df["longitude"].to_list(), df["latitude"].to_list()): x_norm, y_norm = tilemapbase.project(x, y) x_coordinates.append(x_norm) y_coordinates.append(y_norm) colour_map = sns.color_palette("plasma_r", as_cmap=True) # plasma_r YlOrRd # Minimum and maximum of colour map. vmin = 0.0 vmax = np.ceil(df[pollutant].max()) # Plot air pollution on map. scatter = ax.scatter( x_coordinates, y_coordinates, s=150.0, c=df[pollutant].to_list(),
try: if (sighting['snr'] > 20.0) and (float( sighting['plane.geo_altitude']) > midrange_vis_height): obsdict = { 'icao24': sighting['icao24'], 'latitude': sighting['latitude'], 'longitude': sighting['longitude'], 'last_contact': sighting['last_contact'] } newlist.append(obsdict) except TypeError: print('record type issue') #print(newlist) ## print(' from ' + time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(tamydalist[0]['last_contact'])),end = '') # print(' to ' + time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(mydatalist[-1]['last_contact']))) # Define the `extent` of basemap extent = tilemapbase.Extent.from_lonlat(minlong, maxlong, minlat, maxlat) extent = extent.to_aspect(1.0) fig, ax = plt.subplots(figsize=(10, 10)) plotter = tilemapbase.Plotter(extent, tilemapbase.tiles.build_OSM(), width=600) plotter.plot(ax) plotter.plot(plt.axes()) for planeobservation in newlist: x, y = tilemapbase.project(planeobservation['longitude'], planeobservation['latitude']) print('x ' + str(x) + ' y ' + str(y)) plt.plot(x, y, "ro-") plt.show
print("") Longitude = [] Latitude = [] print(len(X)) for i in range(len(X)): rho = np.sqrt((X[i]**2) + (Y[i]**2) + (Z[i]**2)) Longitude_temp = np.arcsin(Z[i] / rho) * 180 / np.pi if Longitude_temp > 90: Longitude_temp = 90 - Longitude_temp Longitude.append(Longitude_temp) Latitude.append(np.arctan(Y[i] / X[i]) * 180 / np.pi) #return Longitude,Latitude print("COUCOU", Latitude, Longitude) path = [tilemapbase.project(x, y) for x, y in zip(Longitude, Latitude)] x, y = zip(*path) #print(np.mean(x)) centre = (centre0[0], centre0[1]) extent = tilemapbase.Extent.from_lonlat(centre[0] - marge, centre[0] + marge, centre[1] - marge, centre[1] + marge) extent = extent.to_aspect(1.0) fig, ax = plt.subplots(figsize=(10, 10), dpi=100) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) plotter = tilemapbase.Plotter(extent, tilemapbase.tiles.build_OSM(), width=600) plotter.plot(ax, tilemapbase.tiles.build_OSM()) x0, y0 = tilemapbase.project(*centre0)