diff --git a/src/grids.jl b/src/grids.jl index 65bea90..d93afc5 100644 --- a/src/grids.jl +++ b/src/grids.jl @@ -19,18 +19,22 @@ Interpolated value in the grid that convert `Datumₛ` to `Datumₜ` of the coordinate with latitude `lat` and longitude `lon`. """ function interpolatelatlon(Datumₛ, Datumₜ, lat, lon) - lat′ = ustrip(lat) - lon′ = ustrip(lon) interps = interpolators(Datumₛ, Datumₜ) - for interp in interps + _interpolatelatlon(interps, ustrip(lat), ustrip(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′) + if lonmin < lon < lonmax && latmin < lat < latmax + return interp(lon, lat) end end throw(ArgumentError("coordinates outside of the transform domain")) end +_interpolatelatlon(interp, lat, lon) = interp(lon, lat) + """ interpolators(Datumₛ, Datumₜ) @@ -50,7 +54,7 @@ function interpolators(Datumₛ, Datumₜ) interps = if geotiff isa GeoTIFF.GeoTIFFImageIterator map(interpolator, geotiff) else - [interpolator(geotiff)] + interpolator(geotiff) end # store interpolators in cache diff --git a/test/converions.jl b/test/converions.jl index 9274391..fe779e4 100644 --- a/test/converions.jl +++ b/test/converions.jl @@ -264,6 +264,6 @@ @test allapprox(c3, c1) # error: coordinates outside of the transform domain - c1 = LatLon{SAD96}(T(10), T(-10)) - @test_throws ArgumentError convert(LatLon{SIRGAS2000}, c1) + c1 = LatLon{RD83}(T(65), T(25)) + @test_throws ArgumentError convert(LatLon{ETRFLatest}, c1) end