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 __init__(self, fen1,Timer): super(Affichage_GPS, self).__init__() self.fenetre_graph = fen1 self.Timer = Timer tilemapbase.init(create=True) self.affichage_carte = False self.Latitude = [] self.Longitude = [] self.Altitude = [] self.Position = [] self.graph = mw.MatplotlibWidget() self.plot = self.graph.getFigure() #self.plot2 = self.plot.subplots(figsize=(8, 8), dpi=100) self.graph.resize(400,400) self.axe = self.plot.add_subplot(111) self.axe.axis("off") #self.axe.resize(800,800) #self.graph.set self.layout = QVBoxLayout() self.layout.addWidget(self.graph) self.setLayout(self.layout) #self.Timer.timeout.connect(self.gps_update) self.Timer.timeout.connect(self.variable_update) #self.Timer.timeout.connect(self.gps_carte_fond) self.Timer.timeout.connect(self.gps_waypoints)
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 __init__(self, name, parentwidget): """ """ # Initialize parent. Should be called after other # initialization since the base class calls _create_content(). super().__init__(name, parentwidget) # # Where is the tool allowed to dock in the main window. self.setAllowedAreas(QtCore.Qt.RightDockWidgetArea | QtCore.Qt.BottomDockWidgetArea) self.setBaseSize(600, 600) # Default position. Hide as default. self._parent.addDockWidget(QtCore.Qt.RightDockWidgetArea, self) self.hide() # Plot map queue. Used to separate threads. self.plot_map_queue = queue.Queue(maxsize=2) # Note: Small buffer. self.plot_map_thread = None # self.plot_map_active = False self.plot_map_active = True self.last_used_latitude = 0.0 self.last_used_longitude = 0.0 self.last_used_degree_range = 0.0 # Use sync object for workspaces and surveys. app_core.DesktopAppSync().item_id_changed_signal.connect(self.plot_map) # Also when visible. self.visibilityChanged.connect(self.visibility_changed) # Map init. tilemapbase.init(create=True) ### self.osm_tiles = tilemapbase.tiles.OSM self.osm_tiles = tilemapbase.tiles.build_OSM()
def plot_path_to_png(timezone='2017-03-28 15:22:00.000000', shapefile='./shapefiles/speedy_Como_dataset.shp', image_save_path='./images/'): # verifico che il path non sia già stato generato file_timezone = timezone.replace('.', '').replace(' ', '__').replace(':', '_') image_path = ospath.join(image_save_path, file_timezone) + '.png' if ospath.isfile(image_path): # in tal caso lo ritorno print('Image already existing at: ' + image_path) return image_path[1:] tmp.init(create=True) t = tmp.tiles.build_OSM() initiated = True tmp.start_logging() print("Opening shapefile...") with fiona.open(shapefile) as np: meta = np.meta paths = [] for feature in np: if feature['properties']['time_zone'] == timezone: paths.append(feature) print("Done.") tzgdf = gpd.GeoDataFrame.from_features(paths) extent = extent_from_frame(tzgdf) extent = extent.to_aspect(1.0) extent = extent.with_scaling(0.8) print("Plotting path...") fig, ax = plt.subplots(figsize=(8, 8), dpi=300) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) plotter = tmp.Plotter(extent, t, width=600) points = points_from_frame(tzgdf) plotter.plot(ax, t) plt.plot(*points) ts = time.time() print("Done, saving image...") plt.savefig(image_path, dpi=300, bbox_inches='tight') print("Done. Image saved as: " + image_path) return image_path[1:]
def __init__(self, new_run): tilemapbase.start_logging() tilemapbase.init(create=True) self.tiles = tilemapbase.tiles.build_OSM() self.run = new_run self.lat, self.lon = list(), list() self.extent = tilemapbase.Extent self.set_lat_and_lon(self.run.coordinates) self.set_extent(self.lat, self.lon)
def __init__(self, fen1, Timer): super(Affichage_GPS, self).__init__() self.fenetre_graph = fen1 tilemapbase.init(create=True) #self.affichage_carte = False self.Latitude = [] self.Longitude = [] self.Altitude = [] self.Position = [] self.graph = mw.MatplotlibWidget(size=(2, 2), dpi=300) self.plot = self.graph.getFigure() #self.plot2 = self.plot.subplots(figsize=(8, 8), dpi=300) self.graph.resize(800, 800) self.axe = self.plot.add_subplot(111) self.axe.axis("off") #self.axe.resize(800,800) #self.graph.set self.position_antenne = None """ self.layout = QVBoxLayout() self.layout.addWidget(self.graph) self.setLayout(self.layout) """ self.thread_gps = gps_thread(self.Latitude, self.Longitude, self.Altitude, self.Position, self.axe, self.fenetre_graph, self.graph) self.thread_gps.setTerminationEnabled(True) self.thread_gps.start() #self.Timer.timeout.connect(self.gps_update) #self.Timer.timeout.connect(self.thread_gps.variable_update()) #self.Timer.timeout.connect(self.gps_carte_fond) self.fenetre_graph.Timer.timeout.connect(self.gps_update) self.graph_altitude = pg.PlotWidget() self.Legend_Altitude = self.graph_altitude.addLegend() self.taille_altitude = 100 self.hbox = QHBoxLayout() self.hbox.addWidget(self.graph) self.hbox.addWidget(self.graph_altitude) self.hbox.addStretch(1) self.vbox = QVBoxLayout() self.vbox.addLayout(self.hbox) self.setLayout(self.vbox) self.update_altitude = thread_altitude(self.graph_altitude, self.taille_altitude, self.thread_gps) self.update_altitude.start()
def get_base_map(edges, zoom=12, dpi=600, t=None): tilemapbase.start_logging() tilemapbase.init(create=True) if not t: t = tilemapbase.tiles.Carto_Light_No_Labels extent = tilemapbase.Extent.from_lonlat(edges["west"], edges["east"], edges["south"], edges["north"]) fig, ax = plt.subplots(dpi=dpi) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) plotter = tilemapbase.Plotter(extent, t, zoom=zoom) plotter.plot(ax, t) return ax, extent
def test_train(): os.environ["NEPTUNE_API_TOKEN"] = "not_a_token" # for Github actions need to create this tilemapbase.init(create=True) initialize(config_path="../configs", job_name="test_app") config = compose( config_name="config", overrides=[ "logger=csv", "experiment=example_simple", "datamodule.fake_data=true", "datamodule.data_path=tests/configs/dataset", "trainer.fast_dev_run=true", ], ) train(config=config)
def __init__(self,fen1,fen_traj): super().__init__() #recupération des autres fenetre nécessaire self.fenetre_graph = fen1 self.fen_traj = fen_traj #position de l'antenne utilisé comme centre du repère self.position_antenne = None #position en x,y,z dans le repère mathématiques self.X_traj = None self.Y_traj = None self.Z_traj = None #position en Latitude,Longitude,Altitude self.Latitude = None self.Longitude = None self.Altitude = None #creation de la base de données pour la carte tilemapbase.init(create=True) #creation de l'objet carte (lib MatplotlibWidget) self.graph = mw.MatplotlibWidget(size=(2,2),dpi=300) self.plot = self.graph.getFigure() self.graph.resize(800,800) self.axe = self.plot.add_subplot(111) self.axe.axis("off") #init et lancement du thread de mise a jour de la position_antenne self.thread_centre = thread_position_antenne(self.fenetre_graph) self.thread_centre.start() #init et lancement du thread de tracé gps self.thread_gps = thread_trace_gps(self.axe,self.graph) self.thread_gps.start() self.fen_traj.boutton_tracer.clicked.connect(self.tracer) self.fenetre_graph.Timer.timeout.connect(self.position_antenne_update) self.Vbox = QVBoxLayout() self.Vbox.addWidget(self.graph) self.setLayout(self.Vbox)
""" Created on Fri Jul 19 11:28:32 2019 @author: john """ import json import matplotlib.pyplot as plt import itertools import operator import time import matplotlib.pyplot as plt import tilemapbase import math ###first plot a basemap#### tilemapbase.init(create=True) longscale = 0.6184 #cos(52) gives relative size of a degree of longitude to latitude where we are mylat = 51.854 mylong = -2.042 gb3vhflat = 51.313 gb3vhflong = 0.375 gb3ngilat = 55.063 gb3ngilong = -6.208 #select the right beacon middle_lat = (mylat + gb3ngilat) / 2 middle_long = (mylong + gb3ngilong) / 2 print("middle latitude " + str(middle_lat)) print("middle longitude " + str(middle_long)) #select the right beacon vrange = 69 * math.cos(middle_long) * (mylong - gb3ngilong)
import tilemapbase as tmb import matplotlib.pyplot as plt import matplotlib.lines as lines import folium from .maputil import copyright_osm import numpy as np import re tmb.init(create=True) def _extend(m, M, p): w = M - m return m - p * w, M + p * w def _expand(ex, p): xmin, xmax = _extend(ex.xmin, ex.xmax, p) ymin, ymax = _extend(ex.ymin, ex.ymax, p) return tmb.Extent(xmin, xmax, ymin, ymax) def _widen(ex, p): return tmb.Extent(*_extend(ex.xmin, ex.xmax, p), ex.ymin, ex.ymax) def _heighten(ex, p): return tmb.Extent(ex.xmin, ex.xmax, *_extend(ex.ymin, ex.ymax, p)) def _adjust(ex, w, h):
def init(): tmp.start_logging() tmp.init(create=True) t = tmp.tiles.build_OSM() initiated = True
import logging import numpy as np from django.db import models # from django.contrib.gis.db import models from model_utils import Choices from django.contrib.gis.gdal import SpatialReference, CoordTransform from datasets.models._plottable import PlottableCached from django.core.validators import MaxValueValidator, MinValueValidator from datasets.utils import plottable from .layer import Layer import tilemapbase import inspect log = logging.getLogger(__name__) tilemapbase.init(create=True) # TODO: Just once def get_tiles(): ret = {} for name, obj in inspect.getmembers(tilemapbase.tiles): if isinstance(obj, tilemapbase.tiles.Tiles): ret[obj.name] = obj return ret tiles = get_tiles() class Map(PlottableCached): name = models.CharField(max_length=64)