Skip to content

Commit

Permalink
Merge pull request #154 from ljstrnadiii/handle_utm_west_east_antimer…
Browse files Browse the repository at this point in the history
…idian

fix: handle utm west and east antimeridian
  • Loading branch information
vincentsarago authored Aug 29, 2024
2 parents 4fba810 + a0b5e55 commit 2e83dde
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
3 changes: 1 addition & 2 deletions morecantile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,9 +1250,8 @@ def tiles( # noqa: C901

for w, s, e, n in bboxes:
# Clamp bounding values.
ws_contain_180th = lons_contain_antimeridian(w, self.bbox.left)
es_contain_180th = lons_contain_antimeridian(e, self.bbox.right)
w = min(self.bbox.left, w) if ws_contain_180th else max(self.bbox.left, w)
w = max(self.bbox.left, w)
s = max(self.bbox.bottom, s)
e = max(self.bbox.right, e) if es_contain_180th else min(self.bbox.right, e)
n = min(self.bbox.top, n)
Expand Down
30 changes: 25 additions & 5 deletions tests/test_morecantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,29 @@ def test_tiles():
assert len(list(tms.tiles(*bounds, zooms=[2]))) == 2


def test_tiles_when_tms_bounds_and_provided_bounds_cross_antimeridian():
bounds = (119.1, -32.86, 119.2, -32.82)
utm = CRS.from_epsg(32750)
@pytest.mark.parametrize(
("bounds", "expected", "crs", "tms_bbox"),
[
# case where east tms bbox crosses antimeridian
(
(119.1, -32.86, 119.2, -32.82),
6,
32750,
(100.23646734667152, -79.99407435445299, -158.6052850376368, 0.0),
),
# case where west tms bbox crosses antimeridian
(
(11.700978, 52.056474, 11.711114, 52.062706),
4,
32632,
(-17.582877658817317, 0.0, 95.87417095917766, 83.95429547980198),
),
],
)
def test_tiles_when_tms_bounds_and_provided_bounds_cross_antimeridian(
bounds: tuple, expected: int, crs: int, tms_bbox: tuple
):
utm = CRS.from_epsg(crs)
rs_extent = utm.area_of_use.bounds
tms = morecantile.TileMatrixSet.custom(
crs=utm, extent_crs=CRS.from_epsg(4326), extent=list(rs_extent)
Expand All @@ -407,8 +427,8 @@ def test_tiles_when_tms_bounds_and_provided_bounds_cross_antimeridian():
# antimeridian e.g. min(119.2, -158.605) clamps to much larger area. Now
# that we check to see if lons contain antimeridian, we build tiles that
# actually overlap the provided bounds to tiles.
assert tms.bbox == (100.23646734667152, -79.99407435445299, -158.6052850376368, 0.0)
assert len(list(tms.tiles(*bounds, zooms=4))) == 1
assert tms.bbox == tms_bbox
assert len(list(tms.tiles(*bounds, zooms=11))) == expected


def test_tiles_for_tms_with_non_standard_row_col_order():
Expand Down

0 comments on commit 2e83dde

Please sign in to comment.