def tiles(ctx, bounds, zoom):
    """Print Tiles from bounds."""
    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'
            '}'
        )
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": [' ) 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' '}' )
Print Tiles from bounds.