diff --git a/src/grids.jl b/src/grids.jl index d93afc5..aa15330 100644 --- a/src/grids.jl +++ b/src/grids.jl @@ -24,16 +24,28 @@ function interpolatelatlon(Datumₛ, Datumₜ, lat, lon) end function _interpolatelatlon(interps::AbstractVector, lat, lon) - @inbounds for interp in interps - (lonmin, lonmax), (latmin, latmax) = bounds(interp) - if lonmin < lon < lonmax && latmin < lat < latmax - return interp(lon, lat) + itp = zero(eltype(first(interps))) + for interp in interps + if _inbounds(interp, lat, lon) + itp = @inbounds interp(lon, lat) + break end end - throw(ArgumentError("coordinates outside of the transform domain")) + itp end -_interpolatelatlon(interp, lat, lon) = interp(lon, lat) +function _interpolatelatlon(interp, lat, lon) + if _inbounds(interp, lat, lon) + @inbounds interp(lon, lat) + else + zero(eltype(interp)) + end +end + +function _inbounds(interp, lat, lon) + (lonmin, lonmax), (latmin, latmax) = bounds(interp) + lonmin < lon < lonmax && latmin < lat < latmax +end """ interpolators(Datumₛ, Datumₜ) diff --git a/test/converions.jl b/test/converions.jl index c9a1bf1..d428044 100644 --- a/test/converions.jl +++ b/test/converions.jl @@ -263,7 +263,29 @@ c3 = convert(LatLon{NTF}, c2) @test allapprox(c3, c1) - # error: coordinates outside of the transform domain + # coordinates outside the grid bounds + # hgridshift + c1 = LatLon{SAD96}(T(10), T(-10)) + c2 = convert(LatLon{SIRGAS2000}, c1) + @test c2.lat ≈ c1.lat + @test c2.lon ≈ c1.lon + c1 = LatLon{RD83}(T(65), T(25)) - @test_throws ArgumentError convert(LatLon{ETRFLatest}, c1) + c2 = convert(LatLon{ETRFLatest}, c1) + @test c2.lat ≈ c1.lat + @test c2.lon ≈ c1.lon + + # pointmotion + c1 = LatLonAlt{NAD83CSRS{3}}(T(90), T(10), T(1)) + c2 = convert(LatLonAlt{NAD83CSRS{4}}, c1) + @test c2.lat ≈ c1.lat + @test c2.lon ≈ c1.lon + @test c2.alt ≈ c1.alt + + # geocgridtranslation + c1 = convert(Cartesian, LatLon{NTF}(T(65), T(25))) + c2 = convert(Cartesian{RGF93v1}, c1) + @test c2.x ≈ c1.x + @test c2.y ≈ c1.y + @test c2.z ≈ c1.z end