@@ -8,16 +8,36 @@ Feature(x; kwargs...) = Feature(x, values(kwargs))
8
8
Base. getproperty (f:: Feature , s:: Symbol ) = s == :data ? getfield (f, 1 ) : s == :rest ? getfield (f, 2 ) : getproperty (getfield (f, 2 ), s)
9
9
Base. propertynames (f:: Feature ) = (:data , propertynames (f. rest)... )
10
10
11
- getnamestypes (:: Type{Feature{T, Names, Types}} ) where {T, Names, Types} = (T, Names, Types)
12
-
13
- function StructArrays. staticschema (:: Type{f} ) where {f<: Feature }
14
- T, names, types = getnamestypes (f)
15
- NamedTuple{(:data , names... ), Base. tuple_type_cons (T, types)}
11
+ # todo better function names
12
+ """
13
+ Put a collection(Array) of Features in a StructArray
14
+ """
15
+ function s_coll (iter:: Array )
16
+ unnested_iter = Base. Generator (iter) do geom_meta
17
+ geom = getfield (geom_meta, :data ) # well, the public accessor for this
18
+ metadata = getfield (geom_meta, :rest )
19
+ (; geometry= geom, metadata... ) # I think the GeometryBasics name for this field is `:position`
20
+ end
21
+ soa = fieldarrays (StructArray (unnested_iter))
22
+ return Feature (soa. geometry; Base. tail (soa)... )
16
23
end
17
24
18
- function StructArrays. createinstance (:: Type{f} , x, args... ) where {f<: Feature }
19
- T, names, types = getnamestypes (f)
20
- Feature (x, NamedTuple {names, types} (args))
25
+ function GeometryBasics. Feature (elements:: AbstractVector{XX} ; rest... ) where {XX}
26
+ isempty (rest) && return elements # no meta to add!
27
+ n = length (elements)
28
+ for (k, v) in rest
29
+ if v isa AbstractVector
30
+ mn = length (v)
31
+ mn != n && error (" Metadata array needs to have same length as data.
32
+ Found $(n) data items, and $mn metadata items" )
33
+ else
34
+ error (" Metadata needs to be an array with the same length as data items. Found: $(typeof (v)) " )
35
+ end
36
+ end
37
+ nt = values (rest)
38
+ # get the first element to get the per element named tuple type
39
+ ElementNT = typeof (map (first, nt))
40
+ return StructArray ((geometry = elements, nt... ))
21
41
end
22
42
23
43
#= ---------------------------------------------------------------------------------------------
@@ -216,9 +236,4 @@ Base.size(x::MultiPolygonMeta) = size(metafree(x))
216
236
217
237
@meta_type (Mesh, mesh, AbstractMesh, Element <: Polytope )
218
238
Base. getindex (x:: MeshMeta , idx:: Int ) = getindex (metafree (x), idx)
219
- Base. size (x:: MeshMeta ) = size (metafree (x))
220
-
221
-
222
- # function Base.getproperty(b::F, s::Symbol)
223
- # s == :data ? getfield(b, 1) : getproperty(getfield(b, 2), s)
224
- # end
239
+ Base. size (x:: MeshMeta ) = size (metafree (x))
0 commit comments