Exemplo n.º 1
0
 def __make_overview_tiles(self, mbtiles, zoom, start_coords, end_coords):
 #========================================================================
     if zoom > self.__min_zoom:
         zoom -= 1
         log('Tiling zoom level {} for {}'.format(zoom, self.__id))
         HALF_SIZE = (TILE_SIZE[0]//2, TILE_SIZE[1]//2)
         half_start = (start_coords[0]//2, start_coords[1]//2)
         half_end = (end_coords[0]//2, end_coords[1]//2)
         progress_bar = ProgressBar(total=(half_end[0]-half_start[0]+1)
                                  *(half_end[1]-half_start[1]+1),
             unit='tiles', ncols=40,
             bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt}')
         for x in range(half_start[0], half_end[0] + 1):
             for y in range(half_start[1], half_end[1] + 1):
                 overview_tile = blank_image(TILE_SIZE)
                 for i in range(2):
                     for j in range(2):
                         try:
                             tile = mbtiles.get_tile(zoom+1, 2*x+i, 2*y+j)
                             half_tile = cv2.resize(tile, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
                             paste_image(overview_tile, half_tile, (i*HALF_SIZE[0], j*HALF_SIZE[1]))
                         except ExtractionError:
                             pass
                 if not_empty(overview_tile):
                     mbtiles.save_tile_as_png(zoom, x, y, overview_tile)
                 progress_bar.update(1)
         progress_bar.close()
         self.__make_overview_tiles(mbtiles, zoom, half_start, half_end)
Exemplo n.º 2
0
 def extract_tile_as_image(self, image_tile_rect):
 #================================================
     X0 = max(0, round(image_tile_rect.x0))
     X1 = min(round(image_tile_rect.x1), self.__source_image.shape[1])
     Y0 = max(0, round(image_tile_rect.y0))
     Y1 = min(round(image_tile_rect.y1), self.__source_image.shape[0])
     if X0 >= X1 or Y0 >= Y1:
         return blank_image(self.tile_size)
     scaling = self.get_scaling(image_tile_rect)
     width = (self.tile_size[0] if image_tile_rect.x0 >= 0 and image_tile_rect.x1 < self.__source_image.shape[1]
         else round(scaling[0]*(X1 - X0)))
     height = (self.tile_size[1] if image_tile_rect.y0 >= 0 and image_tile_rect.y1 < self.__source_image.shape[0]
         else round(scaling[1]*(Y1 - Y0)))
     return cv2.resize(self.__source_image[Y0:Y1, X0:X1], (width, height), interpolation=cv2.INTER_CUBIC)
Exemplo n.º 3
0
 def get_tile(self, tile):
 #========================
     tile_pixel_rect = Rect(self.__tile_coords_to_pixels.transform_point((tile.x, tile.y)),
                            *self.__tile_size)
     image_tile_rect = self.__tile_pixels_to_image.transform_rect(tile_pixel_rect)
     tile_image = self.extract_tile_as_image(image_tile_rect)
     size = image_size(tile_image)
     if size == tuple(self.__tile_size):
         return tile_image
     else:
         padded = blank_image(self.__tile_size)
         scaling = self.get_scaling(image_tile_rect)
         offset = tuple(image_offset(size[i], self.__tile_size[i],
                                (image_tile_rect[i], image_tile_rect[i+2]),
                                (0, self.__image_rect[i+2]),
                                scaling[i])
                     for i in range(0, 2))
         return paste_image(padded, tile_image, offset)
Exemplo n.º 4
0
 def extract_tile_as_image(self, image_tile_rect):
 #================================================
     # Overridden by subclass
     return blank_image()