<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import division <EOL> from math import ceil <EOL> import warnings <EOL> from affine import Affine <EOL> import numpy as np <EOL> from rasterio . _base import _transform <EOL> from rasterio . _warp import ( <EOL> _transform_geom , _reproject , _calculate_default_transform ) <EOL> from rasterio . enums import Resampling <EOL> import rasterio . env <EOL> from rasterio . transform import guard_transform <EOL> RESAMPLING = Resampling <EOL> warnings . warn ( <EOL> "<STR_LIT>" , DeprecationWarning ) <EOL> def transform ( src_crs , dst_crs , xs , ys , zs = None ) : <EOL> """<STR_LIT>""" <EOL> rasterio . env . setenv ( ) <EOL> return _transform ( src_crs , dst_crs , xs , ys , zs ) <EOL> def transform_geom ( <EOL> src_crs , <EOL> dst_crs , <EOL> geom , <EOL> antimeridian_cutting = False , <EOL> antimeridian_offset = <NUM_LIT> , <EOL> precision = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> rasterio . env . setenv ( ) <EOL> return _transform_geom ( <EOL> src_crs , <EOL> dst_crs , <EOL> geom , <EOL> antimeridian_cutting , <EOL> antimeridian_offset , <EOL> precision ) <EOL> def transform_bounds ( <EOL> src_crs , <EOL> dst_crs , <EOL> left , <EOL> bottom , <EOL> right , <EOL> top , <EOL> densify_pts = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> if densify_pts < <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> in_xs = [ ] <EOL> in_ys = [ ] <EOL> if densify_pts > <NUM_LIT:0> : <EOL> densify_factor = <NUM_LIT:1.0> / float ( densify_pts + <NUM_LIT:1> ) <EOL> for x in ( left , right ) : <EOL> in_xs . extend ( [ x ] * ( densify_pts + <NUM_LIT:2> ) ) <EOL> in_ys . extend ( <EOL> bottom + np . arange ( <NUM_LIT:0> , densify_pts + <NUM_LIT:2> , dtype = np . float32 ) * <EOL> ( ( top - bottom ) * densify_factor ) <EOL> ) <EOL> for y in ( bottom , top ) : <EOL> in_xs . extend ( <EOL> left + np . arange ( <NUM_LIT:1> , densify_pts + <NUM_LIT:1> , dtype = np . float32 ) * <EOL> ( ( right - left ) * densify_factor ) <EOL> ) <EOL> in_ys . extend ( [ y ] * densify_pts ) <EOL> else : <EOL> in_xs = [ left , left , right , right ] <EOL> in_ys = [ bottom , top , bottom , top ] <EOL> xs , ys = transform ( src_crs , dst_crs , in_xs , in_ys ) <EOL> return ( min ( xs ) , min ( ys ) , max ( xs ) , max ( ys ) ) <EOL> def reproject ( <EOL> source , <EOL> destination , <EOL> src_transform = None , <EOL> src_crs = None , <EOL> src_nodata = None , <EOL> dst_transform = None , <EOL> dst_crs = None , <EOL> dst_nodata = None , <EOL> resampling = Resampling . nearest , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> Resampling ( resampling ) <EOL> if resampling == <NUM_LIT:7> : <EOL> raise ValueError <EOL> except ValueError : <EOL> raise ValueError ( <EOL> "<STR_LIT>" . format ( "<STR_LIT:U+002CU+0020>" . join ( <EOL> [ '<STR_LIT>' . format ( k ) for k in <EOL> Resampling . __members__ . keys ( ) if k != '<STR_LIT>' ] ) ) ) <EOL> if src_transform : <EOL> src_transform = guard_transform ( src_transform ) . to_gdal ( ) <EOL> if dst_transform : <EOL> dst_transform = guard_transform ( dst_transform ) . to_gdal ( ) <EOL> rasterio . env . setenv ( ) <EOL> _reproject ( <EOL> source , <EOL> destination , <EOL> src_transform , <EOL> src_crs , <EOL> src_nodata , <EOL> dst_transform , <EOL> dst_crs , <EOL> dst_nodata , <EOL> resampling , <EOL> ** kwargs ) <EOL> def calculate_default_transform ( <EOL> src_crs , <EOL> dst_crs , <EOL> width , <EOL> height , <EOL> left , <EOL> bottom , <EOL> right , <EOL> top , <EOL> resolution = None ) : <EOL> """<STR_LIT>""" <EOL> rasterio . env . setenv ( ) <EOL> dst_affine , dst_width , dst_height = _calculate_default_transform ( <EOL> src_crs , dst_crs , <EOL> width , height , <EOL> left , bottom , right , top ) <EOL> if resolution : <EOL> try : <EOL> res = ( float ( resolution ) , float ( resolution ) ) <EOL> except TypeError : <EOL> res = ( resolution [ <NUM_LIT:0> ] , resolution [ <NUM_LIT:0> ] ) if len ( resolution ) == <NUM_LIT:1> else resolution [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> xres = res [ <NUM_LIT:0> ] <EOL> yres = - res [ <NUM_LIT:1> ] <EOL> xratio = dst_affine . a / xres <EOL> yratio = dst_affine . e / yres <EOL> dst_affine = Affine ( xres , dst_affine . b , dst_affine . c , <EOL> dst_affine . d , yres , dst_affine . f ) <EOL> dst_width = ceil ( dst_width * xratio ) <EOL> dst_height = ceil ( dst_height * yratio ) <EOL> return dst_affine , dst_width , dst_height </s>
