Skip to content

Commit 7505047

Browse files
committed
convert to module types
1 parent 40af14b commit 7505047

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/fallbacks.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ coordinates(t::AbstractFeatureCollectionTrait, fc) = [coordinates(f) for f in ge
111111

112112
Base.convert(T::Type, ::AbstractGeometryTrait, geom) = error("Conversion is enabled for type $T, but not implemented. Please report this issue to the package maintainer.")
113113

114+
# Package level `GeoInterface.convert` method
115+
# We convert Module to `Val{nameof(module)}` so that packages can use dispatch.
116+
# This is a slight hack: there can theoretically be multiple
117+
# packages with the same name and different UUIDs. We just ignore this possibility.
118+
# Whichever package has the name first in the main julia registry is canonical.
119+
convert(package::Module, geom) = convert(Val{nameof(package)}(), geom)
120+
function convert(package::Val, geom)
121+
t = trait(geom)
122+
convert(traittype(package, t), t, geom)
123+
end
124+
125+
126+
127+
"""
128+
traittype(package::Module, trait::AbstractTrait)
129+
traittype(package::Val{:PackageName}, trait::AbstractTrait)
130+
131+
Return the object type for a trait and a package.
132+
"""
133+
function traittype end
134+
traittype(mod::Module, trait::AbstractTrait) =
135+
traitype(Val{nameof(mod)}(), trait)
136+
114137
# Subtraits
115138

116139
"""

0 commit comments

Comments
 (0)