Skip to content

Commit f92fe69

Browse files
committed
Make Field names consistent with existing meta
1 parent 007471a commit f92fe69

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/metadata.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ eg: A Point MetaGeometry is a `PointMeta`
201201
But a feature is represented as `Feature{Point}`
202202
"""
203203
struct Feature{T, Names, Types}
204-
data::T
205-
rest::NamedTuple{Names, Types}
204+
main::T
205+
meta::NamedTuple{Names, Types}
206206
end
207207

208208
Feature(x; kwargs...) = Feature(x, values(kwargs))
@@ -212,27 +212,27 @@ Frees the Feature out of metadata
212212
i.e. returns and array of geometries
213213
"""
214214
function metafree(F::Feature)
215-
getproperty(F, :data)
215+
getproperty(F, :main)
216216
end
217-
metafree(x::AbstractVector{<: Feature}) = [getproperty(i, :data) for i in x]
217+
metafree(x::AbstractVector{<: Feature}) = [getproperty(i, :main) for i in x]
218218

219219
"""
220220
Returns the metadata of a Feature
221221
"""
222222
function meta(x::Feature)
223-
getfield(x, :rest)
223+
getfield(x, :meta)
224224
end
225-
meta(x::AbstractVector{<: Feature}) = [getproperty(i, :rest) for i in x]
225+
meta(x::AbstractVector{<: Feature}) = [getproperty(i, :meta) for i in x]
226226

227227
# helper methods
228-
Base.getproperty(f::Feature, s::Symbol) = s == :data ? getfield(f, 1) : s == :rest ? getfield(f, 2) : getproperty(getfield(f, 2), s)
229-
Base.propertynames(f::Feature) = (:data, propertynames(f.rest)...)
228+
Base.getproperty(f::Feature, s::Symbol) = s == :main ? getfield(f, 1) : s == :meta ? getfield(f, 2) : getproperty(getfield(f, 2), s)
229+
Base.propertynames(f::Feature) = (:main, propertynames(f.meta)...)
230230
getnamestypes(::Type{Feature{T, Names, Types}}) where {T, Names, Types} = (T, Names, Types)
231231

232232
# explicitly give the "schema" of the object to StructArrays
233233
function StructArrays.staticschema(::Type{F}) where {F<:Feature}
234234
T, names, types = getnamestypes(F)
235-
NamedTuple{(:data, names...), Base.tuple_type_cons(T, types)}
235+
NamedTuple{(:main, names...), Base.tuple_type_cons(T, types)}
236236
end
237237

238238
# generate an instance of Feature type
@@ -249,9 +249,9 @@ function collect_feature(iter)
249249
collect_feature(first(cols), Base.tail(cols))
250250
end
251251

252-
function collect_feature(data, rest::NamedTuple{names, types}) where {names, types}
253-
F = Feature{eltype(data), names, StructArrays.eltypes(types)}
254-
return StructArray{F}(; data=data, rest...)
252+
function collect_feature(main, meta::NamedTuple{names, types}) where {names, types}
253+
F = Feature{eltype(main), names, StructArrays.eltypes(types)}
254+
return StructArray{F}(; main=main, meta...)
255255
end
256256

257257
Base.getindex(f::Feature, idx::Int) = getindex(metafree(f), idx)

test/runtests.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ end
165165
p1 = Point(2.2, 3.6)
166166
p2 = [p, p1]
167167
@test coordinates(p2) == p2
168-
@test pm.rest === (a=1, b=2)
169-
@test pm.data === p
170-
@test propertynames(pm) == (:data, :a, :b)
168+
@test pm.meta === (a=1, b=2)
169+
@test pm.main === p
170+
@test propertynames(pm) == (:main, :a, :b)
171171
@test GeometryBasics.metafree(pm) == p
172172
@test GeometryBasics.meta(pm) == (a = 1, b = 2)
173173
end
@@ -176,19 +176,19 @@ end
176176
p = collect(Point{2, Float64}(x, x+1) for x in 1:5)
177177
@test p isa AbstractVector
178178
mpm = Feature(MultiPoint(p); a=1, b=2)
179-
@test coordinates(mpm.data) == Point{2, Float64}[(x, x+1) for x in 1:5]
180-
@test mpm.rest === (a=1, b=2)
181-
@test mpm.data == p
182-
@test propertynames(mpm) == (:data, :a, :b)
179+
@test coordinates(mpm.main) == Point{2, Float64}[(x, x+1) for x in 1:5]
180+
@test mpm.meta === (a=1, b=2)
181+
@test mpm.main == p
182+
@test propertynames(mpm) == (:main, :a, :b)
183183
@test GeometryBasics.metafree(mpm) == p
184184
@test GeometryBasics.meta(mpm) == (a = 1, b = 2)
185185
end
186186

187187
@testset "Feature{LineString}" begin
188188
linestring = Feature(LineString(Point{2, Int}[(10, 10), (20, 20), (10, 40)]), a = 1, b = 2)
189189
@test linestring isa Feature
190-
@test linestring.rest === (a = 1, b = 2)
191-
@test propertynames(linestring) == (:data, :a, :b)
190+
@test linestring.meta === (a = 1, b = 2)
191+
@test propertynames(linestring) == (:main, :a, :b)
192192
@test GeometryBasics.metafree(linestring) == LineString(Point{2, Int}[(10, 10), (20, 20), (10, 40)])
193193
@test GeometryBasics.meta(linestring) == (a = 1, b = 2)
194194
end
@@ -199,9 +199,9 @@ end
199199
multilinestring = MultiLineString([linestring1, linestring2])
200200
multilinestringmeta = Feature(MultiLineString([linestring1, linestring2]); boundingbox = Rect(1.0, 1.0, 2.0, 2.0))
201201
@test multilinestringmeta isa Feature
202-
@test multilinestringmeta.rest === (boundingbox = Rect(1.0, 1.0, 2.0, 2.0),)
203-
@test multilinestringmeta.data == multilinestring
204-
@test propertynames(multilinestringmeta) == (:data, :boundingbox)
202+
@test multilinestringmeta.meta === (boundingbox = Rect(1.0, 1.0, 2.0, 2.0),)
203+
@test multilinestringmeta.main == multilinestring
204+
@test propertynames(multilinestringmeta) == (:main, :boundingbox)
205205
@test GeometryBasics.metafree(multilinestringmeta) == multilinestring
206206
@test GeometryBasics.meta(multilinestringmeta) == (boundingbox = GeometryBasics.HyperRectangle{2,Float64}([1.0, 1.0], [2.0, 2.0]),)
207207
end
@@ -224,8 +224,8 @@ end
224224
@test hasproperty(mesh, :normals)
225225
@test mesh.stress == stress
226226
@test mesh.normals == normals
227-
@test GeometryBasics.faces(mesh.data) == tfaces
228-
@test propertynames(mesh) == (:data, :normals, :stress)
227+
@test GeometryBasics.faces(mesh.main) == tfaces
228+
@test propertynames(mesh) == (:main, :normals, :stress)
229229
end
230230
end
231231
end
@@ -617,9 +617,9 @@ end
617617

618618
@test nameof(eltype(feat)) == :Feature
619619
@test eltype(sa) === Feature{Any,(:country_states, :rainfall),Tuple{Any,Float64}}
620-
@test propertynames(sa) === (:data, :country_states, :rainfall)
620+
@test propertynames(sa) === (:main, :country_states, :rainfall)
621621
@test getproperty(sa, :country_states) isa Array{Any}
622-
@test getproperty(sa, :data) == geom
622+
@test getproperty(sa, :main) == geom
623623
end
624624

625625
@testset "Tests from GeometryTypes" begin

0 commit comments

Comments
 (0)