Skip to content

Commit f2575c0

Browse files
committed
use a module method for traittype
1 parent 7505047 commit f2575c0

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

src/fallbacks.jl

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,28 +112,15 @@ coordinates(t::AbstractFeatureCollectionTrait, fc) = [coordinates(f) for f in ge
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

114114
# 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.
115+
# Packages must implement their own `traittype` method
116+
# that accepts a GeoInterface.jl trait and returns the
117+
# corresponding geometry type
119118
convert(package::Module, geom) = convert(Val{nameof(package)}(), geom)
120119
function convert(package::Val, geom)
121120
t = trait(geom)
122-
convert(traittype(package, t), t, geom)
121+
convert(package.traittype(t), t, geom)
123122
end
124123

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-
137124
# Subtraits
138125

139126
"""

src/interface.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,13 @@ coordinates(obj) = coordinates(trait(obj), obj)
605605

606606
"""
607607
convert(type::CustomGeom, geom)
608+
convert(module::Module, geom)
608609
609610
Convert `geom` into the `CustomGeom` type if both geom as the CustomGeom package
610611
have implemented GeoInterface.
612+
613+
Can also convert to a `Module`, which finds the corresponding
614+
type for the trait using the modules `traittype` method.
611615
"""
612616
convert(T, geom) = convert(T, geomtrait(geom), geom)
613617

0 commit comments

Comments
 (0)