Skip to content

Commit 4076f51

Browse files
committed
Some Cleanup
1 parent d0ea0a0 commit 4076f51

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/metadata.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,43 @@ end
66
Feature(x; kwargs...) = Feature(x, values(kwargs))
77

88
#can change names?
9+
"""
10+
Frees the Feature out of metadata
11+
i.e. returns and array of geometries
12+
"""
913
function metafree(F::Feature)
1014
getproperty(F, :data)
1115
end
1216
metafree(x::AbstractVector{<: Feature}) = [getproperty(i, :data) for i in x]
1317

18+
"""
19+
Returns the metadata of a Feature
20+
"""
1421
function meta(x::Feature)
1522
getfield(x, :rest)
1623
end
1724
meta(x::AbstractVector{<: Feature}) = [getproperty(i, :rest) for i in x]
1825

26+
# helper methods
1927
Base.getproperty(f::Feature, s::Symbol) = s == :data ? getfield(f, 1) : s == :rest ? getfield(f, 2) : getproperty(getfield(f, 2), s)
2028
Base.propertynames(f::Feature) = (:data, propertynames(f.rest)...)
21-
2229
getnamestypes(::Type{Feature{T, Names, Types}}) where {T, Names, Types} = (T, Names, Types)
2330

24-
function StructArrays.staticschema(::Type{F}) where {F<:Feature} #explicitly give the "schema" of the object to StructArrays
31+
# explicitly give the "schema" of the object to StructArrays
32+
function StructArrays.staticschema(::Type{F}) where {F<:Feature}
2533
T, names, types = getnamestypes(F)
2634
NamedTuple{(:data, names...), Base.tuple_type_cons(T, types)}
2735
end
2836

29-
function StructArrays.createinstance(::Type{F}, x, args...) where {F<:Feature} #generate an instance of Feature type
37+
# generate an instance of Feature type
38+
function StructArrays.createinstance(::Type{F}, x, args...) where {F<:Feature}
3039
T , names, types = getnamestypes(F)
3140
Feature(x, NamedTuple{names, types}(args))
3241
end
3342

43+
"""
44+
Accepts an Array/iterator of Features and put it into a StructArray
45+
"""
3446
function structarray(iter)
3547
cols = Tables.columntable(iter)
3648
structarray(first(cols), Base.tail(cols))

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ using GeometryBasics: attributes
207207
@test GeometryBasics.metafree(poly) == polys[1]
208208
@test GeometryBasics.metafree(multipoly) == multipol
209209
@test GeometryBasics.meta(meta_p) == (boundingbox = GeometryBasics.HyperRectangle{2,Int64}([0, 0], [2, 2]),)
210-
@test GeometryBasics.meta(poly) == (name = "cMlR", value = 0.0, category = true)
210+
@test GeometryBasics.meta(poly) == (name = pnames[1], value = 0.0, category = bin[1])
211211
@test GeometryBasics.meta(multipoly) == (name = pnames, value = numbers, category = bin)
212212
end
213213

0 commit comments

Comments
 (0)