Beispiel #1
0
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()
Beispiel #2
0
    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()
Beispiel #3
0
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:]
Beispiel #4
0
    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)
Beispiel #5
0
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
Beispiel #6
0
#   the path to search on the command line.
# Can also be used with a few non-Open Data tiles from the UK Ordnance Survey.
#   Specify the paths to search as additional options, in the order
#   [25k Raster Tiles path] [1-to-1000 MasterMap Tiles path]

import sys

try:
    import tilemapbase
except:
    print(
        "Failed to import `tilemapbase`.  Please install from https://github.com/MatthewDaws/TileMapBase"
    )
    sys.exit(1)

tilemapbase.start_logging()

import os
sys.path.insert(0, os.path.abspath(".."))

import tilewindow
import tilewindow.tilemap as tilemap

if len(sys.argv) < 2:
    path = os.path.join("..", "..", "..", "Data", "OS_OpenMap")
    # TODO: Test with a dummy directory...
else:
    path = sys.argv[1]
print("Scanning path '{}' for Ordnance Survey tiles...".format(path))
try:
    tilemapbase.ordnancesurvey.init(path)
Beispiel #7
0
def init():
    tmp.start_logging()

    tmp.init(create=True)
    t = tmp.tiles.build_OSM()
    initiated = True