Skip to content

Commit

Permalink
add PointOutsideBounds error (#237)
Browse files Browse the repository at this point in the history
* add PointOutsideBounds error

* update from master

* version bump
  • Loading branch information
vincentsarago authored Aug 24, 2020
1 parent 37d6afa commit 588e512
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.0b8 (2020-08-24)
------------------
- raise specific `PointOutsideBounds` in rio_tiler.reader.point (#236)

2.0b7 (2020-08-21)
------------------
- allow setting default kwargs in COGReader __init__ (#227)
Expand Down
4 changes: 4 additions & 0 deletions rio_tiler/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class TileOutsideBounds(RioTilerError):
"""Z-X-Y Tile is outside image bounds."""


class PointOutsideBounds(RioTilerError):
"""Point is outside image bounds."""


class InvalidBandName(RioTilerError):
"""Invalid band name."""

Expand Down
9 changes: 7 additions & 2 deletions rio_tiler/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
from rasterio.warp import transform_bounds

from . import constants
from .errors import AlphaBandWarning, DeprecationWarning, TileOutsideBounds
from .errors import (
AlphaBandWarning,
DeprecationWarning,
PointOutsideBounds,
TileOutsideBounds,
)
from .utils import _requested_tile_aligned_with_internal_tile as is_aligned
from .utils import _stats as raster_stats
from .utils import (
Expand Down Expand Up @@ -364,7 +369,7 @@ def point(
(src_dst.bounds[0] < lon[0] < src_dst.bounds[2])
and (src_dst.bounds[1] < lat[0] < src_dst.bounds[3])
):
raise Exception("Point is outside dataset bounds")
raise PointOutsideBounds("Point is outside dataset bounds")

indexes = indexes if indexes is not None else src_dst.indexes

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

setup(
name="rio-tiler",
version="2.0b7",
version="2.0b8",
python_requires=">=3.5",
description="Rasterio plugin to read mercator tiles from Cloud Optimized GeoTIFF.",
long_description=readme,
Expand Down
9 changes: 7 additions & 2 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import rasterio

from rio_tiler import constants, reader
from rio_tiler.errors import AlphaBandWarning, DeprecationWarning, TileOutsideBounds
from rio_tiler.errors import (
AlphaBandWarning,
DeprecationWarning,
PointOutsideBounds,
TileOutsideBounds,
)

S3_KEY = "hro_sources/colorado/201404_13SED190110_201404_0x1500m_CL_1.tif"
S3_KEY_ALPHA = "hro_sources/colorado/201404_13SED190110_201404_0x1500m_CL_1_alpha.tif"
Expand Down Expand Up @@ -522,7 +527,7 @@ def test_point():
p = reader.point(src_dst, [310000, 4100000], coord_crs=src_dst.crs)
assert p == [8917]

with pytest.raises(Exception):
with pytest.raises(PointOutsideBounds):
reader.point(src_dst, [810000, 4100000], coord_crs=src_dst.crs)

with rasterio.open(COG_CMAP) as src_dst:
Expand Down

0 comments on commit 588e512

Please sign in to comment.