Skip to content

Commit

Permalink
Merge remote-tracking branch 'asinghvi17/as/geometryops_core' into as…
Browse files Browse the repository at this point in the history
…/dd_and_cellsize
  • Loading branch information
asinghvi17 committed Oct 6, 2024
2 parents 87b5d4c + 90dfa27 commit 7baf9b2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Flatten = "0.4"
GRIBDatasets = "0.2, 0.3"
GeoFormatTypes = "0.4"
GeoInterface = "1"
GeometryOpsCore = "0.1"
GeometryOpsCore = "0.1.1"
Makie = "0.19, 0.20, 0.21"
Missings = "0.4, 1"
NCDatasets = "0.13, 0.14"
Expand Down
4 changes: 2 additions & 2 deletions src/Rasters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ using CommonDataModel: AbstractDataset, AbstractVariable

using DiskArrays: @implement_diskarray

using GeometryOpsCore: Linear, Spherical
export Linear, Spherical
using GeometryOpsCore: Planar, Spherical
export Planar, Spherical

export AbstractRaster, Raster
export AbstractRasterStack, RasterStack
Expand Down
6 changes: 3 additions & 3 deletions src/extensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ By assuming the earth is a sphere, it approximates the true size to about 0.1%,
Run `using ArchGDAL` to make this method fully available.
`method` can be `Spherical(; radius)` (the default) or `Linear()`.
`method` can be `Spherical(; radius)` (the default) or `Planar()`.
- `Spherical` will compute cell area on the sphere, by transforming all points back to long-lat. You can specify the radius by the `radius` keyword argument here. By default, this is `6371008.8`, the mean radius of the Earth.
- `Linear` will compute cell area in the plane of the CRS you have chosen. Be warned that this will likely be incorrect for non-equal-area projections.
- `Planar` will compute cell area in the plane of the CRS you have chosen. Be warned that this will likely be incorrect for non-equal-area projections.
## Example
Expand Down Expand Up @@ -199,7 +199,7 @@ $EXPERIMENTAL
cellarea(x; kw...) = cellarea(Spherical(), x; kw...)
cellarea(method::GeometryOpsCore.Manifold, x; kw...) = cellarea(method, dims(x, (XDim, YDim)); kw...)

function cellarea(method::GeometryOpsCore.Linear, dims::Tuple{<:XDim, <:YDim}; kw...)
function cellarea(method::GeometryOpsCore.Planar, dims::Tuple{<:XDim, <:YDim}; kw...)
isintervals(dims) || throw(ArgumentError("Cannot calculate cell size for a `Raster` with `Points` sampling."))
areas = _planar_cellarea(dims; kw...)
return Raster(areas; dims)
Expand Down
8 changes: 4 additions & 4 deletions test/cellarea.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl"))
@test cs == cs_ras

## test with area_in_crs true
cs_planar = cellarea(dimz; area_in_crs = true)
cs_planar2 = cellarea(dimz_25832; area_in_crs = true)
cs_planar3 = cellarea((x, y_rev); area_in_crs = true)
cs_planar = cellarea(Planar(), dimz)
cs_planar2 = cellarea(Planar(), dimz_25832)
cs_planar3 = cellarea(Planar(), (x, y_rev))
@test all((0.01), cs_planar)
@test all((10_000), cs_planar2)
@test all((0.01), cs_planar3)
Expand All @@ -70,4 +70,4 @@ include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl"))
# test missing crs throws an error
nocrsdimz = setcrs(dimz, nothing)
@test_throws ArgumentError cellarea(nocrsdimz)
end
end

0 comments on commit 7baf9b2

Please sign in to comment.