<s> import logging <EOL> import os <EOL> import click <EOL> from cligj import ( <EOL> precision_opt , indent_opt , compact_opt , projection_geographic_opt , <EOL> projection_mercator_opt , projection_projected_opt , sequence_opt , <EOL> use_rs_opt , geojson_type_feature_opt , geojson_type_bbox_opt , <EOL> geojson_type_collection_opt ) <EOL> from . helpers import write_features , to_lower <EOL> import rasterio <EOL> from rasterio . env import Env <EOL> from rasterio . warp import transform_bounds <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> @ click . command ( short_help = "<STR_LIT>" ) <EOL> @ click . argument ( '<STR_LIT>' , nargs = - <NUM_LIT:1> , type = click . Path ( ) , required = True ) <EOL> @ precision_opt <EOL> @ indent_opt <EOL> @ compact_opt <EOL> @ projection_geographic_opt <EOL> @ projection_projected_opt <EOL> @ projection_mercator_opt <EOL> @ click . option ( <EOL> '<STR_LIT>' , default = '<STR_LIT>' , metavar = "<STR_LIT>" , callback = to_lower , <EOL> help = "<STR_LIT>" ) <EOL> @ sequence_opt <EOL> @ use_rs_opt <EOL> @ geojson_type_collection_opt ( True ) <EOL> @ geojson_type_feature_opt ( False ) <EOL> @ geojson_type_bbox_opt ( False ) <EOL> @ click . pass_context <EOL> def bounds ( ctx , input , precision , indent , compact , projection , dst_crs , <EOL> sequence , use_rs , geojson_type ) : <EOL> """<STR_LIT>""" <EOL> import rasterio . warp <EOL> verbosity = ( ctx . obj and ctx . obj . get ( '<STR_LIT>' ) ) or <NUM_LIT:1> <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> dump_kwds = { '<STR_LIT>' : True } <EOL> if indent : <EOL> dump_kwds [ '<STR_LIT>' ] = indent <EOL> if compact : <EOL> dump_kwds [ '<STR_LIT>' ] = ( '<STR_LIT:U+002C>' , '<STR_LIT::>' ) <EOL> stdout = click . get_text_stream ( '<STR_LIT>' ) <EOL> class Collection ( object ) : <EOL> def __init__ ( self , env ) : <EOL> self . _xs = [ ] <EOL> self . _ys = [ ] <EOL> self . env = env <EOL> @ property <EOL> def bbox ( self ) : <EOL> return min ( self . _xs ) , min ( self . _ys ) , max ( self . _xs ) , max ( self . _ys ) <EOL> def __call__ ( self ) : <EOL> for i , path in enumerate ( input ) : <EOL> with rasterio . open ( path ) as src : <EOL> bounds = src . bounds <EOL> if dst_crs : <EOL> bbox = transform_bounds ( src . crs , <EOL> dst_crs , * bounds ) <EOL> elif projection == '<STR_LIT>' : <EOL> bbox = transform_bounds ( src . crs , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , * bounds ) <EOL> elif projection == '<STR_LIT>' : <EOL> bbox = transform_bounds ( src . crs , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , * bounds ) <EOL> else : <EOL> bbox = bounds <EOL> if precision >= <NUM_LIT:0> : <EOL> bbox = [ round ( b , precision ) for b in bbox ] <EOL> yield { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : bbox , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ [ <EOL> [ bbox [ <NUM_LIT:0> ] , bbox [ <NUM_LIT:1> ] ] , <EOL> [ bbox [ <NUM_LIT:2> ] , bbox [ <NUM_LIT:1> ] ] , <EOL> [ bbox [ <NUM_LIT:2> ] , bbox [ <NUM_LIT:3> ] ] , <EOL> [ bbox [ <NUM_LIT:0> ] , bbox [ <NUM_LIT:3> ] ] , <EOL> [ bbox [ <NUM_LIT:0> ] , bbox [ <NUM_LIT:1> ] ] ] ] } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : str ( i ) , <EOL> '<STR_LIT:title>' : path , <EOL> '<STR_LIT:filename>' : os . path . basename ( path ) } } <EOL> self . _xs . extend ( bbox [ : : <NUM_LIT:2> ] ) <EOL> self . _ys . extend ( bbox [ <NUM_LIT:1> : : <NUM_LIT:2> ] ) <EOL> try : <EOL> with Env ( CPL_DEBUG = verbosity > <NUM_LIT:2> ) as env : <EOL> write_features ( <EOL> stdout , Collection ( env ) , sequence = sequence , <EOL> geojson_type = geojson_type , use_rs = use_rs , <EOL> ** dump_kwds ) <EOL> except Exception : <EOL> logger . exception ( "<STR_LIT>" ) <EOL> raise click . Abort ( ) </s>
