44from urllib .parse import urlparse , parse_qs
55
66from mercantile import bounds
7- from pyproj import Proj , transform
7+ from pyproj import Proj , Transformer
88from PIL import Image
99import numpy as np
1010import requests
@@ -51,6 +51,7 @@ def get_tile_tif(tile, imagery, folder, kwargs):
5151 x_res , y_res = src .transform [0 ], src .transform [4 ]
5252 p1 = Proj ('epsg:4326' )
5353 p2 = Proj (str (src .crs ))
54+ transformer = Transformer .from_crs (p1 , p2 )
5455
5556 # offset our imagery in the "destination pixel" space
5657 offset_bound = dict ()
@@ -63,8 +64,8 @@ def get_tile_tif(tile, imagery, folder, kwargs):
6364 offset_bound ['south' ] = bound .south + imagery_offset [1 ] * deg_per_pix_y
6465
6566 # project tile boundaries from lat/lng to source CRS
66- tile_ul_proj = transform (p1 , p2 , offset_bound ['west' ], offset_bound ['north' ])
67- tile_lr_proj = transform (p1 , p2 , offset_bound ['east' ], offset_bound ['south' ])
67+ tile_ul_proj = transformer . transform (offset_bound ['west' ], offset_bound ['north' ])
68+ tile_lr_proj = transformer . transform (offset_bound ['east' ], offset_bound ['south' ])
6869 # get origin point from the TIF
6970 tif_ul_proj = (src .bounds .left , src .bounds .top )
7071
@@ -108,10 +109,11 @@ def get_tile_wms(tile, imagery, folder, kwargs):
108109 bound = bounds (* [int (t ) for t in tile .split ('-' )])
109110 p1 = Proj ('epsg:4326' )
110111 p2 = Proj (wms_srs )
112+ transformer = Transformer .from_crs (p1 , p2 )
111113
112114 # project the tile bounding box from lat/lng to WMS SRS
113- tile_ll_proj = transform (p1 , p2 , bound .west , bound .south )
114- tile_ur_proj = transform (p1 , p2 , bound .east , bound .north )
115+ tile_ll_proj = transformer . transform (bound .west , bound .south )
116+ tile_ur_proj = transformer . transform (bound .east , bound .north )
115117 if wms_version == '1.3.0' :
116118 bbox = tile_ll_proj [::- 1 ] + tile_ur_proj [::- 1 ]
117119 else :
0 commit comments