Skip to content

Commit a26c3d2

Browse files
committed
Resolve conflict
2 parents a75a775 + 31afffa commit a26c3d2

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ stdout*
1414
/integration*
1515
.idea/
1616
docs/_build/
17+
18+
.tox

label_maker/utils.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
from urllib.parse import urlparse, parse_qs
55

66
from mercantile import bounds
7-
from pyproj import Transformer
87
from PIL import Image
98
import numpy as np
109
import requests
1110
import rasterio
11+
from rasterio.crs import CRS
12+
from rasterio.warp import transform, transform_bounds
13+
14+
WGS84_CRS = CRS.from_epsg(4326)
1215

1316
def url(tile, imagery):
1417
"""Return a tile url provided an imagery template and a tile"""
@@ -49,9 +52,6 @@ def get_tile_tif(tile, imagery, folder, kwargs):
4952
imagery_offset = kwargs.get('imagery_offset') or [0, 0]
5053
with rasterio.open(imagery) as src:
5154
x_res, y_res = src.transform[0], src.transform[4]
52-
p1 = 'epsg:4326'
53-
p2 = str(src.crs)
54-
transformer = Transformer.from_crs(p1, p2)
5555

5656
# offset our imagery in the "destination pixel" space
5757
offset_bound = dict()
@@ -64,8 +64,12 @@ def get_tile_tif(tile, imagery, folder, kwargs):
6464
offset_bound['south'] = bound.south + imagery_offset[1] * deg_per_pix_y
6565

6666
# project tile boundaries from lat/lng to source CRS
67-
tile_ul_proj = transformer.transform(offset_bound['west'], offset_bound['north'])
68-
tile_lr_proj = transformer.transform(offset_bound['east'], offset_bound['south'])
67+
x, y = transform(WGS84_CRS, src.crs, [offset_bound['west']], [offset_bound['north']])
68+
tile_ul_proj = x[0], y[0]
69+
70+
x, y = transform(WGS84_CRS, src.crs, [offset_bound['east']], [offset_bound['south']])
71+
tile_lr_proj = x[0], y[0]
72+
6973
# get origin point from the TIF
7074
tif_ul_proj = (src.bounds.left, src.bounds.top)
7175

@@ -107,17 +111,12 @@ def get_tile_wms(tile, imagery, folder, kwargs):
107111

108112
# find our tile bounding box
109113
bound = bounds(*[int(t) for t in tile.split('-')])
110-
p1 = 'epsg:4326'
111-
p2 = wms_srs
112-
transformer = Transformer.from_crs(p1, p2)
114+
xmin, ymin, xmax, ymax = transform_bounds(WGS84_CRS, CRS.from_string(wms_srs), *bound, densify_pts=21)
113115

114116
# project the tile bounding box from lat/lng to WMS SRS
115-
tile_ll_proj = transformer.transform(bound.west, bound.south)
116-
tile_ur_proj = transformer.transform(bound.east, bound.north)
117-
if wms_version == '1.3.0':
118-
bbox = tile_ll_proj[::-1] + tile_ur_proj[::-1]
119-
else:
120-
bbox = tile_ll_proj + tile_ur_proj
117+
bbox = (
118+
[ymin, xmin, ymax, xmax] if wms_version == "1.3.0" else [xmin, ymin, xmax, ymax]
119+
)
121120

122121
# request the image with the transformed bounding box and save
123122
wms_url = imagery.replace('{bbox}', ','.join([str(b) for b in bbox]))

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mapbox-vector-tile==1.2.0
55
mercantile>=1.0.3
66
numpy>=1.18.4
77
Pillow==7.1.2
8-
pyproj>=2.6.1
98
rasterio[s3]>=1.1
109
requests>=2.20.0
1110
Shapely>=1.6.3

0 commit comments

Comments
 (0)