def image_for_domain(self, target_domain, target_z): # XXX Copied from cartopy.io.img_tiles if target_z not in self._collections_by_name: # TODO: Handle integer depths also? raise ValueError('%s is not one of the possible collections.' % target_z) tiles = [] for tile in self.find_images(target_domain, target_z): try: img, extent, origin = self.get_image(tile) except IOError: continue img = numpy.array(img) x = numpy.linspace(extent[0], extent[1], img.shape[1], endpoint=False) y = numpy.linspace(extent[2], extent[3], img.shape[0], endpoint=False) tiles.append([numpy.array(img), x, y, origin]) from cartopy.io.img_tiles import _merge_tiles img, extent, origin = _merge_tiles(tiles) return img, extent, origin
def image_for_domain(self, target_domain, target_z): # XXX Copied from cartopy.io.img_tiles if target_z not in self._collections_by_name: # TODO: Handle integer depths also? raise ValueError('%s is not one of the possible ' 'collections.' % target_z) tiles = [] for tile in self.find_images(target_domain, target_z): try: img, extent, origin = self.get_image(tile) except IOError: continue img = numpy.array(img) x = numpy.linspace(extent[0], extent[1], img.shape[1], endpoint=False) y = numpy.linspace(extent[2], extent[3], img.shape[0], endpoint=False) tiles.append([numpy.array(img), x, y, origin]) from cartopy.io.img_tiles import _merge_tiles img, extent, origin = _merge_tiles(tiles) return img, extent, origin
def test_image_merge(): # tests the basic image merging functionality tiles = [] for i in range(1, 4): for j in range(0, 3): tiles.append((i, j, 2)) gt = cimgt.GoogleTiles() gt._image_url = types.MethodType(ctest_tiles.GOOGLE_IMAGE_URL_REPLACEMENT, gt) images_to_merge = [] for tile in tiles: img, extent, origin = gt.get_image(tile) img = np.array(img) x = np.linspace(extent[0], extent[1], img.shape[1], endpoint=False) y = np.linspace(extent[2], extent[3], img.shape[0], endpoint=False) images_to_merge.append([img, x, y, origin]) img, extent, origin = cimgt._merge_tiles(images_to_merge) ax = plt.axes(projection=gt.crs) ax.set_global() ax.coastlines() ax.imshow(img, origin=origin, extent=extent, alpha=0.5) return ax.figure
def image_for_domain(self, target_domain, target_z): """ Determine the image that provides complete coverage of target location. The composed image is merged from one or more image tiles that overlay the target location and provide complete image coverage of the target location. Parameters ---------- target_domain A :class:`~shapely.geometry.linestring.LineString` instance that specifies the target location requiring image coverage. target_z The name of the target :class`~cartopy.io.img_nest.ImageCollection` which specifies the target zoom level (resolution) of the required images. Returns ------- img, extent, origin A tuple containing three items, consisting of the target location :class:`numpy.ndarray` image data, the (x-lower, x-upper, y-lower, y-upper) extent of the image, and the origin for the target location. """ # XXX Copied from cartopy.io.img_tiles if target_z not in self._collections_by_name: # TODO: Handle integer depths also? msg = '{!r} is not one of the possible collections.' raise ValueError(msg.format(target_z)) tiles = [] for tile in self.find_images(target_domain, target_z): try: img, extent, origin = self.get_image(tile) except IOError: continue img = np.array(img) x = np.linspace(extent[0], extent[1], img.shape[1], endpoint=False) y = np.linspace(extent[2], extent[3], img.shape[0], endpoint=False) tiles.append([np.array(img), x, y, origin]) from cartopy.io.img_tiles import _merge_tiles img, extent, origin = _merge_tiles(tiles) return img, extent, origin
def image_for_domain(self, target_domain, target_z): tiles = [] with futures.ThreadPoolExecutor(max_workers=20) as executor: todo = {} for tile in self.find_images(target_domain, target_z): future = executor.submit(self.one_image, tile) todo[future] = tile done_iter = futures.as_completed(todo) for future in done_iter: try: res = future.result() except IOError: continue tiles.append(res) img, extent, origin = _merge_tiles(tiles) return img, extent, origin
def test_image_merge(): # tests the basic image merging functionality tiles = [] for i in range(1, 4): for j in range(0, 3): tiles.append((i, j, 2)) tiler = cimgt.GoogleTiles() images_to_merge = [] for tile in tiles: img, extent, origin = tiler.get_image(tile) img = np.array(img) x = np.linspace(extent[0], extent[1], img.shape[1], endpoint=False) y = np.linspace(extent[2], extent[3], img.shape[0], endpoint=False) images_to_merge.append([img, x, y, origin]) img, extent, origin = cimgt._merge_tiles(images_to_merge) ax = plt.axes(projection=ccrs.Mercator()) ax.set_global() ax.coastlines() plt.imshow(img, origin=origin, extent=extent, alpha=0.5)
def test_image_merge(): # tests the basic image merging functionality tiles = [] for i in range(1, 4): for j in range(0, 3): tiles.append((i, j, 2)) gt = cimgt.GoogleTiles() gt._image_url = types.MethodType(ctest_tiles.GOOGLE_IMAGE_URL_REPLACEMENT, gt) images_to_merge = [] for tile in tiles: img, extent, origin = gt.get_image(tile) img = np.array(img) x = np.linspace(extent[0], extent[1], img.shape[1], endpoint=False) y = np.linspace(extent[2], extent[3], img.shape[0], endpoint=False) images_to_merge.append([img, x, y, origin]) img, extent, origin = cimgt._merge_tiles(images_to_merge) ax = plt.axes(projection=gt.crs) ax.set_global() ax.coastlines() plt.imshow(img, origin=origin, extent=extent, alpha=0.5)
def image_for_domain(self, target_domain, _): """ Implements method used by cartopy for drawing tile sets. The third argument *target_z* is ignored, because it's defined by the zoom level of the tileset. """ img, extent, origin = _merge_tiles(self.tiles) return img, extent, origin