Skip to content

Commit

Permalink
change TMS bbox calculation [port from 4.0]
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed May 15, 2023
1 parent d55618e commit f6689b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 40 deletions.
43 changes: 4 additions & 39 deletions morecantile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,46 +655,11 @@ def bounds(self, *tile: Tile) -> BoundingBox:
@property
def xy_bbox(self):
"""Return TMS bounding box in TileMatrixSet's CRS."""
if self.boundingBox:
left = (
self.boundingBox.lowerCorner[1]
if self._invert_axis
else self.boundingBox.lowerCorner[0]
)
bottom = (
self.boundingBox.lowerCorner[0]
if self._invert_axis
else self.boundingBox.lowerCorner[1]
)
right = (
self.boundingBox.upperCorner[1]
if self._invert_axis
else self.boundingBox.upperCorner[0]
)
top = (
self.boundingBox.upperCorner[0]
if self._invert_axis
else self.boundingBox.upperCorner[1]
)
if self.boundingBox.crs != self.crs:
transform = Transformer.from_crs(
self.boundingBox.crs, self.crs, always_xy=True
)
left, bottom, right, top = transform.transform_bounds(
left,
bottom,
right,
top,
densify_pts=21,
)
zoom = self.minzoom
matrix = self.matrix(zoom)

else:
zoom = self.minzoom
matrix = self.matrix(zoom)
left, top = self._ul(Tile(0, 0, zoom))
right, bottom = self._ul(
Tile(matrix.matrixWidth, matrix.matrixHeight, zoom)
)
left, top = self._ul(Tile(0, 0, zoom))
right, bottom = self._ul(Tile(matrix.matrixWidth, matrix.matrixHeight, zoom))

return BoundingBox(left, bottom, right, top)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_InvertedLatLonGrids():
tms = morecantile.tms.get("NZTM2000")
bound = tms.xy_bounds(morecantile.Tile(1, 2, 0))
assert bound == (1293760.0, 3118720.0, 3587520.0, 5412480.0)
assert tms.xy_bbox == (274000.0, 3087000.0, 3327000.0, 7173000.0)
assert tms.xy_bbox == (-1000000.0, 824960.0, 3587520.0, 10000000.0)

tms = morecantile.tms.get("LINZAntarticaMapTilegrid")
assert tms.xy_bbox == (
Expand Down

0 comments on commit f6689b3

Please sign in to comment.