<s> import fiona <EOL> import rasterio <EOL> from rasterio . tools . mask import mask <EOL> with fiona . open ( "<STR_LIT>" , "<STR_LIT:r>" ) as shapefile : <EOL> geoms = [ feature [ "<STR_LIT>" ] for feature in shapefile ] <EOL> with rasterio . open ( "<STR_LIT>" ) as src : <EOL> out_image , out_transform = mask ( src , geoms , crop = True ) <EOL> out_meta = src . meta . copy ( ) <EOL> out_meta . update ( { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : out_image . shape [ <NUM_LIT:1> ] , <EOL> "<STR_LIT:width>" : out_image . shape [ <NUM_LIT:2> ] , <EOL> "<STR_LIT>" : out_transform } ) <EOL> with rasterio . open ( "<STR_LIT>" , "<STR_LIT:w>" , ** out_meta ) as dest : <EOL> dest . write ( out_image ) </s>
