|
6 | 6 | Feature(x; kwargs...) = Feature(x, values(kwargs))
|
7 | 7 |
|
8 | 8 | #can change names?
|
| 9 | +""" |
| 10 | +Frees the Feature out of metadata |
| 11 | +i.e. returns and array of geometries |
| 12 | +""" |
9 | 13 | function metafree(F::Feature)
|
10 | 14 | getproperty(F, :data)
|
11 | 15 | end
|
12 | 16 | metafree(x::AbstractVector{<: Feature}) = [getproperty(i, :data) for i in x]
|
13 | 17 |
|
| 18 | +""" |
| 19 | +Returns the metadata of a Feature |
| 20 | +""" |
14 | 21 | function meta(x::Feature)
|
15 | 22 | getfield(x, :rest)
|
16 | 23 | end
|
17 | 24 | meta(x::AbstractVector{<: Feature}) = [getproperty(i, :rest) for i in x]
|
18 | 25 |
|
| 26 | +# helper methods |
19 | 27 | Base.getproperty(f::Feature, s::Symbol) = s == :data ? getfield(f, 1) : s == :rest ? getfield(f, 2) : getproperty(getfield(f, 2), s)
|
20 | 28 | Base.propertynames(f::Feature) = (:data, propertynames(f.rest)...)
|
21 |
| - |
22 | 29 | getnamestypes(::Type{Feature{T, Names, Types}}) where {T, Names, Types} = (T, Names, Types)
|
23 | 30 |
|
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} |
25 | 33 | T, names, types = getnamestypes(F)
|
26 | 34 | NamedTuple{(:data, names...), Base.tuple_type_cons(T, types)}
|
27 | 35 | end
|
28 | 36 |
|
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} |
30 | 39 | T , names, types = getnamestypes(F)
|
31 | 40 | Feature(x, NamedTuple{names, types}(args))
|
32 | 41 | end
|
33 | 42 |
|
| 43 | +""" |
| 44 | +Accepts an Array/iterator of Features and put it into a StructArray |
| 45 | +""" |
34 | 46 | function structarray(iter)
|
35 | 47 | cols = Tables.columntable(iter)
|
36 | 48 | structarray(first(cols), Base.tail(cols))
|
|
0 commit comments