Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/RastersArchGDALExt/RastersArchGDALExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const DA = DiskArrays
const GI = GeoInterface
const LA = Lookups

Rasters.is_loaded(::Rasters.ArchGDALExt) = true

include("gdal_source.jl")
include("resample.jl")
include("warp.jl")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const RA = Rasters
const DD = DimensionalData
const LA = Lookups

Rasters.is_loaded(::Rasters.CoordinateTransformationsExt) = true

include("affineprojected.jl")

end # module
2 changes: 2 additions & 0 deletions ext/RastersGRIBDatasetsExt/RastersGRIBDatasetsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const RA = Rasters
const DA = DiskArrays
const GDS = GRIBDatasets

Rasters.is_loaded(::Rasters.GRIBDatasetsExt) = true

include("gribdatasets_source.jl")

end
2 changes: 2 additions & 0 deletions ext/RastersMakieExt/RastersMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ using Rasters
using Rasters.DimensionalData
using Rasters.Dimensions

Rasters.is_loaded(::Rasters.MakieExt) = true

include("plotrecipes.jl")

end
2 changes: 2 additions & 0 deletions ext/RastersNCDatasetsExt/RastersNCDatasetsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const RA = Rasters
const DD = DimensionalData
const LA = Lookups

Rasters.is_loaded(::Rasters.NCDatasetsExt) = true

include("ncdatasets_source.jl")

end
2 changes: 2 additions & 0 deletions ext/RastersProjExt/RastersProjExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const DA = DiskArrays
const GI = GeoInterface
const LA = Lookups

Rasters.is_loaded(::Rasters.ProjExt) = true

include("cellarea.jl")
include("reproject.jl")
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ using Rasters.Dimensions
const RA = Rasters
const RDS = RasterDataSources

Rasters.is_loaded(::Rasters.RasterDataSourcesExt) = true

include("constructors.jl")

end # Module
2 changes: 2 additions & 0 deletions ext/RastersStatsBaseExt/RastersStatsBaseExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const RA = Rasters
import Rasters: _True, _False, _booltype, istrue
import Rasters.DimensionalData as DD

Rasters.is_loaded(::Rasters.StatsBaseExt) = true

include("sample.jl")

end # Module
2 changes: 2 additions & 0 deletions ext/RastersZarrDatasetsExt/RastersZarrDatasetsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ using Rasters: Zarrsource

const RA = Rasters

Rasters.is_loaded(::Rasters.ZarrDatasetsExt) = true

include("zarrdatasets_source.jl")

end
35 changes: 27 additions & 8 deletions src/extensions.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
# extensions
function throw_extension_error(f::Function, package::String, extension::Symbol, args)
if isnothing(Base.get_extension(Rasters, extension))
throw(BackendException(package))
else
abstract type Extension end

# Concrete extension markers. These exist so callers can test availability
# with `is_loaded(::Type{...})` instead of scattered `Base.get_extension` calls.
struct ArchGDALExt <: Extension end
struct CoordinateTransformationsExt <: Extension end
struct GRIBDatasetsExt <: Extension end
struct MakieExt <: Extension end
struct NCDatasetsExt <: Extension end
struct ProjExt <: Extension end
struct RasterDataSourcesExt <: Extension end
struct StatsBaseExt <: Extension end
struct ZarrDatasetsExt <: Extension end

# defaults to false
is_loaded(::Extension) = false

function throw_extension_error(f::Function, extension::Extension, args)
if is_loaded(extension)
throw(MethodError(f, args))
else
throw(BackendException(extension))
end
end

BackendException(e::E) where E <: Extension =
BackendException(replace(string(nameof(E)), r"Ext$" => ""))

# stubs that need ArchGDAL

Expand Down Expand Up @@ -90,7 +109,7 @@ savefig(b, "build/resample_example_after.png"); nothing

$EXPERIMENTAL
"""
resample(args...; kw...) = throw_extension_error(resample, "ArchGDAL", :RastersArchGDALExt, args)
resample(args...; kw...) = throw_extension_error(resample, ArchGDALExt(), args)

"""
warp(A::AbstractRaster, flags::Dict; kw...)
Expand Down Expand Up @@ -154,7 +173,7 @@ In practise, prefer [`resample`](@ref) for this. But `warp` may be more flexible

$EXPERIMENTAL
"""
warp(args...; kw...) = throw_extension_error(warp, "ArchGDAL", :RastersArchGDALExt, args)
warp(args...; kw...) = throw_extension_error(warp, ArchGDALExt(), args)

# stubs that need Proj

Expand Down Expand Up @@ -218,7 +237,7 @@ function cellarea(method::GeometryOpsCore.Spherical, dims::Tuple{<:XDim, <:YDim}
return Raster(areas; dims)
end

_spherical_cellarea(args...; kw...) = throw_extension_error(_spherical_cellarea, "Proj", :RastersProjExt, args)
_spherical_cellarea(args...; kw...) = throw_extension_error(_spherical_cellarea, ProjExt(), args)

function _planar_cellarea(dims::Tuple{<:XDim, <:YDim})
xbnds, ybnds = DD.intervalbounds(dims)
Expand Down Expand Up @@ -273,7 +292,7 @@ Rasters.sample(myraster, 5; weights=cellarea(myraster))
@NamedTuple{geometry::Tuple{Float64, Float64}, ::Union{Missing, Float64}}(((110.0, 10.0), 0.5291143028176258))
```
"""
sample(args...; kw...) = throw_extension_error(sample, "StatsBase", :RastersStatsBaseExt, args)
sample(args...; kw...) = throw_extension_error(sample, StatsBaseExt, args)



Expand Down
2 changes: 1 addition & 1 deletion src/methods/reproject.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function _reproject(source::GeoFormat, target::GeoFormat, dim::Union{XDim,YDim},
reshape(_reproject(source, target, dim, vec(vals)), size(vals))
end
function _reproject(source::GeoFormat, target::GeoFormat, dim::Union{XDim,YDim}, vals::AbstractVector)
throw_extension_error(reproject, "Proj", :RastersProjExt, (source, target, dim, vals))
throw_extension_error(reproject, ProjExt(), (source, target, dim, vals))
end

# Guess the step for arrays
Expand Down
Loading