@@ -56,38 +56,31 @@ using GeometryBasics: attributes
5656 end
5757
5858 end
59+
5960 @testset " polygon with metadata" begin
6061 polys = [Polygon (rand (Point{2 , Float32}, 20 )) for i in 1 : 10 ]
6162 pnames = [randstring (4 ) for i in 1 : 10 ]
6263 numbers = LinRange (0.0 , 1.0 , 10 )
6364 bin = rand (Bool, 10 )
64- # create just an array
65- plain = meta (polys, name = pnames, value = numbers, category = bin)
65+ # create a polygon
66+ poly = PolygonMeta (polys[ 1 ] , name = pnames[ 1 ] , value = numbers[ 1 ] , category = bin[ 1 ] )
6667 # create a MultiPolygon with the right type & meta information!
67- multipoly = MultiPolygon (polys; name = pnames, value = numbers, category = bin)
68- for x in (plain, multipoly)
69- for (mp, p, n, num, b) in zip (x, polys, pnames, numbers, bin)
70- @test mp. polygon == p
71- @test mp. name == n
72- @test mp. value == num
73- @test mp. category == b
74- end
75-
76- filtered = filter (i -> i. value < 0.7 , x)
77- @test length (filtered) == 7
78- end
79- @test GeometryBasics. getcolumn (plain, :name ) == pnames
80- @test GeometryBasics. MetaType (Polygon) == PolygonMeta
81- @test_throws ErrorException GeometryBasics. meta (plain)
68+ multipoly = MultiPolygonMeta (polys, name = pnames, value = numbers, category = bin)
69+ @test multipoly isa AbstractVector
70+ @test poly isa GeometryBasics. AbstractPolygon
71+
72+ @test GeometryBasics. getcolumn (poly, :name ) == pnames[1 ]
8273 @test GeometryBasics. MetaFree (PolygonMeta) == Polygon
8374
75+ @test GeometryBasics. getcolumn (multipoly, :name ) == pnames
76+ @test GeometryBasics. MetaFree (MultiPolygonMeta) == MultiPolygon
77+
8478 meta_p = meta (polys[1 ], boundingbox= Rect (0 , 0 , 2 , 2 ))
8579 @test meta_p. boundingbox === Rect (0 , 0 , 2 , 2 )
8680 @test metafree (meta_p) === polys[1 ]
8781 attributes (meta_p) == Dict {Symbol, Any} (:boundingbox => meta_p. boundingbox,
8882 :polygon => polys[1 ])
8983 end
90-
9184 @testset " point with metadata" begin
9285 p = Point (1.1 , 2.2 )
9386 @test p isa AbstractVector{Float64}
@@ -99,8 +92,26 @@ using GeometryBasics: attributes
9992 @test metafree (pm) === p
10093 @test propertynames (pm) == (:position , :a , :b )
10194 end
95+
96+ @testset " MultiPoint with metadata" begin
97+ p = collect (Point {2, Float64} (x, x+ 1 ) for x in 1 : 5 )
98+ @test p isa AbstractVector
99+ mpm = MultiPointMeta (p, a= 1 , b= 2 )
100+ @test coordinates (mpm) == mpm
101+ @test meta (mpm) === (a= 1 , b= 2 )
102+ @test metafree (mpm) == p
103+ @test propertynames (mpm) == (:points , :a , :b )
104+ end
105+
106+ @testset " LineString with metadata" begin
107+ linestring = LineStringMeta (Point{2 , Int}[(10 , 10 ), (20 , 20 ), (10 , 40 )], a = 1 , b = 2 )
108+ @test linestring isa AbstractVector
109+ @test meta (linestring) === (a = 1 , b = 2 )
110+ @test metafree (linestring) == linestring
111+ @test propertynames (linestring) == (:lines , :a , :b )
112+ end
102113
103- @testset " MultiLineString with metadata" begin
114+ @testset " MultiLineString with metadata" begin
104115 linestring1 = LineString (Point{2 , Int}[(10 , 10 ), (20 , 20 ), (10 , 40 )])
105116 linestring2 = LineString (Point{2 , Int}[(40 , 40 ), (30 , 30 ), (40 , 20 ), (30 , 10 )])
106117 multilinestring = MultiLineString ([linestring1, linestring2])
0 commit comments