Exemple #1
0
def test_web_tiles():
    extent = [-15, 0.1, 50, 60]
    target_domain = sgeom.Polygon([[extent[0], extent[1]],
                                   [extent[2], extent[1]],
                                   [extent[2], extent[3]],
                                   [extent[0], extent[3]],
                                   [extent[0], extent[1]]])
    map_prj = cimgt.GoogleTiles().crs

    ax = plt.subplot(3, 2, 1, projection=map_prj)
    gt = cimgt.GoogleTiles()
    gt._image_url = types.MethodType(ctest_tiles.GOOGLE_IMAGE_URL_REPLACEMENT,
                                     gt)
    img, extent, origin = gt.image_for_domain(target_domain, 1)
    ax.imshow(np.array(img),
              extent=extent,
              transform=gt.crs,
              interpolation='bilinear',
              origin=origin)
    ax.coastlines(color='white')

    ax = plt.subplot(3, 2, 2, projection=map_prj)
    qt = cimgt.QuadtreeTiles()
    img, extent, origin = qt.image_for_domain(target_domain, 1)
    ax.imshow(np.array(img),
              extent=extent,
              transform=qt.crs,
              interpolation='bilinear',
              origin=origin)
    ax.coastlines(color='white')

    ax = plt.subplot(3, 2, 3, projection=map_prj)
    mq_osm = cimgt.MapQuestOSM()
    img, extent, origin = mq_osm.image_for_domain(target_domain, 1)
    ax.imshow(np.array(img),
              extent=extent,
              transform=mq_osm.crs,
              interpolation='bilinear',
              origin=origin)
    ax.coastlines()

    ax = plt.subplot(3, 2, 4, projection=map_prj)
    mq_oa = cimgt.MapQuestOpenAerial()
    img, extent, origin = mq_oa.image_for_domain(target_domain, 1)
    ax.imshow(np.array(img),
              extent=extent,
              transform=mq_oa.crs,
              interpolation='bilinear',
              origin=origin)
    ax.coastlines()

    ax = plt.subplot(3, 2, 5, projection=map_prj)
    osm = cimgt.OSM()
    img, extent, origin = osm.image_for_domain(target_domain, 1)
    ax.imshow(np.array(img),
              extent=extent,
              transform=osm.crs,
              interpolation='bilinear',
              origin=origin)
    ax.coastlines()
Exemple #2
0
def test_web_tiles():
    extent = [-15, 0.1, 50, 60]
    target_domain = shapely.geometry.Polygon([[extent[0], extent[1]],
                                              [extent[2], extent[1]],
                                              [extent[2], extent[3]],
                                              [extent[0], extent[3]],
                                              [extent[0], extent[1]]])

    ax = plt.subplot(3, 2, 1, projection=ccrs.Mercator())
    gt = cimgt.GoogleTiles()
    img, extent, origin = gt.image_for_domain(target_domain, 1)
    ax.imshow(np.array(img),
              extent=extent,
              transform=ccrs.Mercator(),
              interpolation='bilinear',
              origin=origin)
    ax.coastlines(color='white')

    ax = plt.subplot(3, 2, 2, projection=ccrs.Mercator())
    qt = cimgt.QuadtreeTiles()
    img, extent, origin = qt.image_for_domain(target_domain, 1)
    ax.imshow(np.array(img),
              extent=extent,
              transform=ccrs.Mercator(),
              interpolation='bilinear',
              origin=origin)
    ax.coastlines(color='white')

    ax = plt.subplot(3, 2, 3, projection=ccrs.Mercator())
    mq_osm = cimgt.MapQuestOSM()
    img, extent, origin = mq_osm.image_for_domain(target_domain, 1)
    ax.imshow(np.array(img),
              extent=extent,
              transform=ccrs.Mercator(),
              interpolation='bilinear',
              origin=origin)
    ax.coastlines()

    ax = plt.subplot(3, 2, 4, projection=ccrs.Mercator())
    mq_oa = cimgt.MapQuestOpenAerial()
    img, extent, origin = mq_oa.image_for_domain(target_domain, 1)
    ax.imshow(np.array(img),
              extent=extent,
              transform=ccrs.Mercator(),
              interpolation='bilinear',
              origin=origin)
    ax.coastlines()

    ax = plt.subplot(3, 2, 5, projection=ccrs.Mercator())
    osm = cimgt.OSM()
    img, extent, origin = osm.image_for_domain(target_domain, 1)
    ax.imshow(np.array(img),
              extent=extent,
              transform=ccrs.Mercator(),
              interpolation='bilinear',
              origin=origin)
    ax.coastlines()
Exemple #3
0
def main():
    # Create a MapQuest open aerial instance.
    map_quest_aerial = cimgt.MapQuestOpenAerial()

    # Create a GeoAxes in the tile's projection.
    ax = plt.axes(projection=map_quest_aerial.crs)

    # Limit the extent of the map to a small longitude/latitude range.
    ax.set_extent([-22, -15, 63, 65])

    # Add the MapQuest data at zoom level 8.
    ax.add_image(map_quest_aerial, 8)

    # Add a marker for the Eyjafjallajökull volcano.
    plt.plot(-19.613333,
             63.62,
             marker='o',
             color='yellow',
             markersize=12,
             alpha=0.7,
             transform=ccrs.Geodetic())

    # Use the cartopy interface to create a matplotlib transform object
    # for the Geodetic coordinate system. We will use this along with
    # matplotlib's offset_copy function to define a coordinate system which
    # translates the text by 25 pixels to the left.
    geodetic_transform = ccrs.Geodetic()._as_mpl_transform(ax)
    text_transform = offset_copy(geodetic_transform, units='dots', x=-25)

    # Add text 25 pixels to the left of the volcano.
    plt.text(-19.613333,
             63.62,
             u'Eyjafjallajökull',
             verticalalignment='center',
             horizontalalignment='right',
             transform=text_transform,
             bbox=dict(facecolor='wheat', alpha=0.5, boxstyle='round'))
    plt.show()
Exemple #4
0
def wmts_data():
    """
    A fixture which ensures that the WMTS data is available for use in testing.
    """
    aerial = cimgt.MapQuestOpenAerial()

    # get web tiles up to 3 zoom levels deep
    tiles = [(0, 0, 0)]
    for tile in aerial.subtiles((0, 0, 0)):
        tiles.append(tile)
    for tile in tiles[1:]:
        for sub_tile in aerial.subtiles(tile):
            tiles.append(sub_tile)

    fname_template = os.path.join(_TEST_DATA_DIR, 'z_{}', 'x_{}_y_{}.png')

    if not os.path.isdir(_TEST_DATA_DIR):
        os.makedirs(_TEST_DATA_DIR)

    data_version_fname = os.path.join(_TEST_DATA_DIR, 'version.txt')

    test_data_version = None
    try:
        with open(data_version_fname) as fh:
            test_data_version = int(fh.read().strip())
    except OSError:
        pass
    finally:
        if test_data_version != _TEST_DATA_VERSION:
            warnings.warn('WMTS test data is out of date, regenerating at '
                          f'{_TEST_DATA_DIR}.')
            shutil.rmtree(_TEST_DATA_DIR)
            os.makedirs(_TEST_DATA_DIR)
            with open(data_version_fname, 'w') as fh:
                fh.write(str(_TEST_DATA_VERSION))

    # Download the tiles.
    for tile in tiles:
        x, y, z = tile
        fname = fname_template.format(z, x, y)
        if not os.path.exists(fname):
            if not os.path.isdir(os.path.dirname(fname)):
                os.makedirs(os.path.dirname(fname))

            img, extent, _ = aerial.get_image(tile)
            nx, ny = 256, 256
            x_rng = extent[1] - extent[0]
            y_rng = extent[3] - extent[2]

            pix_size_x = x_rng / nx
            pix_size_y = y_rng / ny

            upper_left_center = (extent[0] + pix_size_x / 2,
                                 extent[2] + pix_size_y / 2)

            pgw_fname = fname[:-4] + '.pgw'
            pgw_keys = {
                'x_pix_size': np.float64(pix_size_x),
                'y_rotation': 0,
                'x_rotation': 0,
                'y_pix_size': np.float64(pix_size_y),
                'x_center': np.float64(upper_left_center[0]),
                'y_center': np.float64(upper_left_center[1]),
            }
            _save_world(pgw_fname, pgw_keys)
            img.save(fname)
Exemple #5
0
def main():

    # This is just useful for formatting returned dict
    # pp = pprint.PrettyPrinter(indent=2)

    # Create instance of Meso object, pass in YOUR token
    m = Meso(token='YOUR TOKEN')

    # Use to lookup stations, could specify counties or whatever here
    # findstationids = m.station_list(state='CO')
    # print(findstationids)

    # Grab most recent temp (F) ob in last 90 min at each of the below stations
    stations = [
        'kgxy, kccu, kcos, kden, kgjt, kbdu, kpub, klhx, kspd, kdro, ksbs, keeo, kguc, klic, '
        'kstk, kals, ktad'
    ]
    latest = m.latest(stid=stations,
                      within='90',
                      vars='air_temp',
                      units='temp|F')

    # create a list to store everything, iterate over the number of objs returned in latest and append
    # lat, long, temp, and stid for use later
    data = []
    [
        data.append((float(ob['LATITUDE']), float(ob['LONGITUDE']),
                     float(ob['OBSERVATIONS']['air_temp_value_1']['value']),
                     ob['STID'])) for ob in latest['STATION']
    ]
    print(data)

    # Create a MapQuest open aerial instance.
    map_quest_aerial = cimgt.MapQuestOpenAerial()
    # Create a GeoAxes in the tile's projection.
    ax = plt.axes(projection=map_quest_aerial.crs)
    # Limit the extent of the map to Colorado's borders
    ax.set_extent([-102.03, -109.03, 37, 41])
    # Add the MapQuest data at zoom level 8.
    ax.add_image(map_quest_aerial, 8)

    # Plot lat/long pts with below params
    for lat, lon, temp, stid in data:
        plt.plot(lon,
                 lat,
                 marker='o',
                 color='y',
                 markersize=1,
                 alpha=0.7,
                 transform=ccrs.Geodetic())

    # Transforms for the text func we're about to call
    geodetic_transform = ccrs.Geodetic()._as_mpl_transform(ax)
    text_transform = offset_copy(geodetic_transform, units='dots', x=0, y=0)

    # Plot temp and station id for each of the markers
    for lat, lon, temp, stid in data:
        plt.text(lon,
                 lat,
                 stid + '\n' + str(round(temp, 1)) + u' \N{DEGREE SIGN}' + 'F',
                 verticalalignment='center',
                 horizontalalignment='center',
                 transform=text_transform,
                 fontsize=9,
                 bbox=dict(facecolor='wheat', alpha=0.5, boxstyle='round'))
    plt.title('Current Weather Around Colorado')
    plt.show()
Exemple #6
0
def test_tile_bbox_y0_at_south_pole():
    tms = cimgt.MapQuestOpenAerial()

    # Check the y0_at_north_pole keywords returns the appropriate bounds.
    assert_arr_almost(tms.tile_bbox(8, 6, 4, y0_at_north_pole=False),
                      np.array(KNOWN_EXTENTS[(8, 9, 4)]).reshape([2, 2]))
    plt.show()
    if title:
        plt.savefig(title + '.png')


for provider in [
    {
        'tiler': cimgt.OSM(),
        'title': 'OSM'
    },
    {
        'tiler': cimgt.GoogleTiles(),
        'title': 'GoogleTiles'
    },
    {
        'tiler': cimgt.MapQuestOpenAerial(),
        'title': 'MapQuestOpenAerial'
    },
        #this last one raises an errot which is managed
    {
        'tiler': cimgt.Stamen(),
        'title': 'Stamen'
    },
    {
        'tiler': cimgt.QuadtreeTiles(),
        'title': 'QuadtreeTiles'
    },
]:
    print(provider['title'])
    plot_track_with_tiles(provider['tiler'], title=provider['title'], lw=3)
Exemple #8
0
Demonstrates cartopy's ability to draw map tiles which are downloaded on
demand from the MapQuest tile server. Internally these tiles are then combined
into a single image and displayed in the cartopy GeoAxes.


mapquest.com right-click mouse for coordinates
"""
import matplotlib.pyplot as plt
from matplotlib.transforms import offset_copy

import cartopy.crs as ccrs
import cartopy.io.img_tiles as cimgt

# Create a MapQuest open aerial instance.
map_quest_aerial = cimgt.MapQuestOpenAerial()

plt.figure()
# Create a GeoAxes in the tile's projection.
ax = plt.axes(projection=map_quest_aerial.crs)

# Limit the extent of the map to a small longitude/latitude range.
ax.set_extent([-70.56, -70.49, 41.54, 41.59])

# Add the MapQuest data at zoom level 8.
ax.add_image(map_quest_aerial, 16)

SeapitRSDock = {'lat': 41.569653, 'lon': -70.532917}
D = SeapitRSDock

# Add a marker for SeapitRSDock