Return the tile image for this location

        :param gid: GID of image
        :rtype: surface if found, otherwise ValueError
976171
def get_tile_image_by_gid(self, gid):
        
        try:
            assert (int(gid) >= 0)
            return self.images[gid]
        except TypeError:
            msg = "GIDs must be expressed as a number.  Got: {0}"
            logger.debug(msg.format(gid))
            raise TypeError
        except (AssertionError, IndexError):
            msg = "Coords: ({0},{1}) in layer {2} has invalid GID: {3}"
            logger.debug(msg.format(gid))
            raise ValueError
947620
def surface2image(surface):
    
    # TODO(Jflesch): Python 3 problem
    # cairo.ImageSurface.get_data() raises NotImplementedYet ...

    # import PIL.ImageDraw
    #
    # if surface is None:
    #     return None
    # dimension = (surface.get_width(), surface.get_height())
    # img = PIL.Image.frombuffer("RGBA", dimension,
    #                            surface.get_data(), "raw", "BGRA", 0, 1)
    #
    # background = PIL.Image.new("RGB", img.size, (255, 255, 255))
    # background.paste(img, mask=img.split()[3])  # 3 is the alpha channel
    # return background

    global g_lock
    with g_lock:
        img_io = io.BytesIO()
        surface.write_to_png(img_io)
        img_io.seek(0)
        img = PIL.Image.open(img_io)
        img.load()

        if "A" not in img.getbands():
            return img

        img_no_alpha = PIL.Image.new("RGB", img.size, (255, 255, 255))
        img_no_alpha.paste(img, mask=img.split()[3])  # 3 is the alpha channel
        return img_no_alpha
215454
def show(self, fmt=None):
        
        # force any delayed redraws
        # TODO: this really needs to be addressed in get_rgb_image_as_bytes()
        # of the various superclasses, as it affects other backends as well
        self.redraw_now()

        from IPython.display import Image

        if fmt is None:
            # what format are we using for the Jupyter image--use that
            fmt = self.jp_img.format

        return Image(data=bytes(self.get_rgb_image_as_bytes(format=fmt)),
                     format=fmt, embed=True)
650617
def edges_touching_tile(tile_id):
    
    coord = tile_id_to_coord(tile_id)
    edges = []
    for offset in _tile_edge_offsets.keys():
        edges.append(coord + offset)
    # logging.debug('tile_id={}, edges touching={}'.format(tile_id, edges))
    return edges
883966
def createTileUrl(self, x, y, z):
        '''
        
        '''
        return self.tileTemplate.replace('{{x}}', str(x)).replace('{{y}}', str(
            y)).replace('{{z}}', str(z))
1218421
def get_tile_images_by_rect(self, rect):
        

        def rev(seq, start, stop):
            if start < 0:
                start = 0
            return enumerate(seq[start:stop + 1], start)

        x1, y1, x2, y2 = rect_to_bb(rect)
        images = self.tmx.images
        layers = self.tmx.layers
        at = self._animated_tile
        tracked_gids = self._tracked_gids
        anim_map = self._animation_map
        track = bool(self._animation_queue)

        for l in self.tmx.visible_tile_layers:
            for y, row in rev(layers[l].data, y1, y2):
                for x, gid in [i for i in rev(row, x1, x2) if i[1]]:
                    # since the tile has been queried, assume it wants to be checked
                    # for animations sometime in the future
                    if track and gid in tracked_gids:
                        anim_map[gid].positions.add((x, y, l))

                    try:
                        # animated, so return the correct frame
                        yield x, y, l, at[(x, y, l)]

                    except KeyError:

                        # not animated, so return surface from data, if any
                        yield x, y, l, images[gid]
242252
def tile_to_path(self, tile):
		''''''
		return os.path.join(self.cache_path, self.service, tile.path())
476942
def get_tile_location(self, x, y):
        """"""
        x1, y1 = self.origin
        x1 += self.BORDER + (self.BORDER + self.cell_width) * x
        y1 += self.BORDER + (self.BORDER + self.cell_height) * y
        return x1, y1
1024839
def tiles(ctx, bounds, zoom):
    """"""
    tiles = TilePyramid(
        ctx.obj['grid'],
        tile_size=ctx.obj['tile_size'],
        metatiling=ctx.obj['metatiling']
    ).tiles_from_bounds(bounds, zoom=zoom)
    if ctx.obj['output_format'] == 'Tile':
        for tile in tiles:
            click.echo('%s %s %s' % tile.id)
    elif ctx.obj['output_format'] == 'WKT':
        for tile in tiles:
            click.echo(tile.bbox(pixelbuffer=ctx.obj['pixelbuffer']))
    elif ctx.obj['output_format'] == 'GeoJSON':
        click.echo(
            '{\n'
            '  "type": "FeatureCollection",\n'
            '  "features": ['
        )
        # print tiles as they come and only add comma if there is a next tile
        try:
            tile = next(tiles)
            while True:
                gj = '    %s' % geojson.Feature(
                    geometry=tile.bbox(pixelbuffer=ctx.obj['pixelbuffer']),
                    properties=dict(
                        zoom=tile.zoom,
                        row=tile.row,
                        col=tile.col
                    )
                )
                try:
                    tile = next(tiles)
                    click.echo(gj + ',')
                except StopIteration:
                    click.echo(gj)
                    raise
        except StopIteration:
            pass
        click.echo(
            '  ]\n'
            '}'
        )
1040662
def getTile(self, lat, lon):
        """"""
        global childFileListDownload
        if childFileListDownload is not None and childFileListDownload.is_alive():
            '''print "Getting file list"'''
            return 0
        elif not self.filelist:
            '''print "Filelist download complete, loading data"'''
            data = open(self.filelist_file, 'rb')
            self.filelist = pickle.load(data)
            data.close()

        try:
            continent, filename = self.filelist[(int(lat), int(lon))]
        except KeyError:
            '''print "here??"'''
            if len(self.filelist) > self.min_filelist_len:
                # we appear to have a full filelist - this must be ocean
                return SRTMOceanTile(int(lat), int(lon))
            return 0

        global childTileDownload
        if not os.path.exists(os.path.join(self.cachedir, filename)):
            if childTileDownload is None or not childTileDownload.is_alive():
                try:
                    childTileDownload = multiprocessing.Process(target=self.downloadTile, args=(str(continent), str(filename)))
                    childTileDownload.start()
                except Exception as ex:
                    childTileDownload = None
                    return 0
                '''print "Getting Tile"'''
            return 0
        elif childTileDownload is not None and childTileDownload.is_alive():
            '''print "Still Getting Tile"'''
            return 0
        # TODO: Currently we create a new tile object each time.
        # Caching is required for improved performance.
        try:
            return SRTMTile(os.path.join(self.cachedir, filename), int(lat), int(lon))
        except InvalidTileError:
            return 0
1164418
function (pos) {
        var layerSize = this.layerSize,
            tiles = this.tiles

        if (pos.x < 0 || pos.y < 0 || pos.x >= layerSize.width || pos.y >= layerSize.height) {
            throw "TMX Layer: Invalid position"
        }

        var tile,
            gid = this.tileGIDAt(pos)

        // if GID is 0 then no tile exists at that point
        if (gid) {
            var z = pos.x + pos.y * layerSize.width
            tile = this.getChild({tag: z})
        }

        return tile
    }
836767
def image(self):
        
        return self._uid.image.image if isinstance(self._uid, UserAttribute) else None
1290299
public static void tileImage (Graphics2D gfx, Mirage image, int x, int y, int width, int height)
    {
        int iwidth = image.getWidth(), iheight = image.getHeight();
        int xnum = width / iwidth, xplus = width % iwidth;
        int ynum = height / iheight, yplus = height % iheight;
        Shape oclip = gfx.getClip();

        for (int ii=0; ii < ynum; ii++) {
            // draw the full copies of the image across
            int xx = x;
            for (int jj=0; jj < xnum; jj++) {
                image.paint(gfx, xx, y);
                xx += iwidth;
            }

            if (xplus > 0) {
                gfx.clipRect(xx, y, xplus, iheight);
                image.paint(gfx, xx, y);
                gfx.setClip(oclip);
            }

            y += iheight;
        }

        if (yplus > 0) {
            int xx = x;
            for (int jj=0; jj < xnum; jj++) {
                gfx.clipRect(xx, y, iwidth, yplus);
                image.paint(gfx, xx, y);
                gfx.setClip(oclip);
                xx += iwidth;
            }

            if (xplus > 0) {
                gfx.clipRect(xx, y, xplus, yplus);
                image.paint(gfx, xx, y);
                gfx.setClip(oclip);
            }
        }
    }
1227093
private static Tile checkTile(MapTile map, ImageBuffer tileSprite, Integer sheet, int x, int y)
    {
        final int tw = map.getTileWidth();
        final int th = map.getTileHeight();
        final SpriteTiled tileSheet = map.getSheet(sheet);
        final ImageBuffer sheetImage = tileSheet.getSurface();
        final int tilesInX = tileSheet.getWidth() / tw;
        final int tilesInY = tileSheet.getHeight() / th;

        for (int surfaceCurrentTileY = 0; surfaceCurrentTileY < tilesInY; surfaceCurrentTileY++)
        {
            for (int surfaceCurrentTileX = 0; surfaceCurrentTileX < tilesInX; surfaceCurrentTileX++)
            {
                // Tile number on tile sheet
                final int number = surfaceCurrentTileX + surfaceCurrentTileY * tilesInX;

                // Compare tiles between sheet and image map
                final int xa = x * tw;
                final int ya = y * th;
                final int xb = surfaceCurrentTileX * tw;
                final int yb = surfaceCurrentTileY * th;

                if (TilesExtractor.compareTile(tw, th, tileSprite, xa, ya, sheetImage, xb, yb))
                {
                    return map.createTile(sheet, number, xa, (map.getInTileHeight() - 1.0 - y) * th);
                }
            }
        }
        return null;
    }
205060
def get_wcs(self, data_x, data_y):
        
        img = self.fitsimage.get_image()
        ra, dec = img.pixtoradec(data_x, data_y)
        return ra, dec
1305230
def get_imgid(self, img):
        
        imgid = img.filename()

        # More heuristics here...
        # get FILENAME keyword, CHECKSUM, for example...
        hdr = self.get_header(img)
        if 'checksum' in hdr:
            return hdr['checksum']

        if 'filename' in hdr:
            return hdr['filename']

        if not imgid:
            imgid = repr(img)

        return imgid
629818
def _queue_edge_tiles(self, dx, dy):
        
        v = self._tile_view
        tw, th = self.data.tile_size
        self._tile_queue = iter([])

        def append(rect):
            self._tile_queue = chain(self._tile_queue, self.data.get_tile_images_by_rect(rect))
            # TODO: optimize so fill is only used when map is smaller than buffer
            self._clear_surface(self._buffer, ((rect[0] - v.left) * tw, (rect[1] - v.top) * th,
                                               rect[2] * tw, rect[3] * th))

        if dx > 0:    # right side
            append((v.right - 1, v.top, dx, v.height))

        elif dx < 0:  # left side
            append((v.left, v.top, -dx, v.height))

        if dy > 0:    # bottom side
            append((v.left, v.bottom - 1, v.width, dy))

        elif dy < 0:  # top side
            append((v.left, v.top, v.width, -dy))