Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv committed Dec 12, 2024
1 parent 54fa0f1 commit 7d746f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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ₜ)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/converions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7d746f8

Please sign in to comment.