Skip to content

Commit

Permalink
Allow reproject(obj, target_crs) as well (#856)
Browse files Browse the repository at this point in the history
* Allow `reproject(obj, target_crs)` as well

Just allows a different argument order so that Rasters and GO reproject definitions are compatible

* add test

* Error message on 2 GeoFormats

Co-authored-by: Felix Cremer <[email protected]>

* Update src/methods/reproject.jl

Co-authored-by: Felix Cremer <[email protected]>

---------

Co-authored-by: Felix Cremer <[email protected]>
  • Loading branch information
asinghvi17 and felixcremer authored Jan 12, 2025
1 parent 9a718eb commit 28a21cf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/methods/reproject.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ are silently returned without modification.
$CRS_KEYWORD
"""
reproject(x; crs::GeoFormat) = reproject(crs, x)
reproject(x, target::GeoFormat) = reproject(target, x)
reproject(::GeoFormat, ::GeoFormat) = throw(ArgumentError("You need to provide a raster object to reproject. Got two coordinate reference systems."))
reproject(target::GeoFormat, x) = rebuild(x; dims=reproject(target, dims(x)))
reproject(target::GeoFormat, dims::Tuple) = map(d -> reproject(target, d), dims)
reproject(target::GeoFormat, l::Lookup) = l
Expand Down
1 change: 1 addition & 0 deletions test/reproject.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using Rasters: reproject, convertlookup
y = Y(Projected(-80.0:1.0:80.0; crs=EPSG(4326), dim=Y(), order=ReverseOrdered(), span=Regular(1.0), sampling=Intervals(Start())))

x1, y1 = reproject((x, y); crs=projcea)
@test reproject((x, y), projcea) == reproject(projcea, (x, y))
@test span(x1) isa Irregular
@test span(y1) isa Irregular
x2, y2 = reproject((x, y); crs=EPSG(4326))
Expand Down

0 comments on commit 28a21cf

Please sign in to comment.