@@ -4,18 +4,26 @@ using Test
4
4
@testset " Developer" begin
5
5
# Implement interface
6
6
struct MyPoint end
7
+ struct MyEmptyPoint end
7
8
struct MyCurve end
8
9
struct MyPolygon end
10
+ struct MyTriangle end
9
11
struct MyMultiPoint end
10
12
struct MyMultiCurve end
11
13
struct MyMultiPolygon end
14
+ struct MyTIN end
12
15
struct MyCollection end
13
16
14
17
GeoInterface. isgeometry (:: MyPoint ) = true
15
18
GeoInterface. geomtype (:: MyPoint ) = PointTrait ()
16
19
GeoInterface. ncoord (:: PointTrait , geom:: MyPoint ) = 2
17
20
GeoInterface. getcoord (:: PointTrait , geom:: MyPoint , i) = [1 , 2 ][i]
18
21
22
+ GeoInterface. isgeometry (:: MyEmptyPoint ) = true
23
+ GeoInterface. geomtype (:: MyEmptyPoint ) = PointTrait ()
24
+ GeoInterface. ncoord (:: PointTrait , geom:: MyEmptyPoint ) = 0
25
+ GeoInterface. isempty (:: PointTrait , geom:: MyEmptyPoint ) = true
26
+
19
27
GeoInterface. isgeometry (:: MyCurve ) = true
20
28
GeoInterface. geomtype (:: MyCurve ) = LineStringTrait ()
21
29
GeoInterface. ngeom (:: LineStringTrait , geom:: MyCurve ) = 2
@@ -28,6 +36,11 @@ using Test
28
36
GeoInterface. ngeom (:: PolygonTrait , geom:: MyPolygon ) = 2
29
37
GeoInterface. getgeom (:: PolygonTrait , geom:: MyPolygon , i) = MyCurve ()
30
38
39
+ GeoInterface. isgeometry (:: MyTriangle ) = true
40
+ GeoInterface. geomtype (:: MyTriangle ) = TriangleTrait ()
41
+ GeoInterface. ngeom (:: TriangleTrait , geom:: MyTriangle ) = 3
42
+ GeoInterface. getgeom (:: TriangleTrait , geom:: MyTriangle , i) = MyCurve ()
43
+
31
44
GeoInterface. isgeometry (:: MyMultiPoint ) = true
32
45
GeoInterface. geomtype (:: MyMultiPoint ) = MultiPointTrait ()
33
46
GeoInterface. ngeom (:: MultiPointTrait , geom:: MyMultiPoint ) = 2
@@ -43,18 +56,38 @@ using Test
43
56
GeoInterface. ngeom (:: MultiPolygonTrait , geom:: MyMultiPolygon ) = 2
44
57
GeoInterface. getgeom (:: MultiPolygonTrait , geom:: MyMultiPolygon , i) = MyPolygon ()
45
58
59
+ GeoInterface. isgeometry (:: MyTIN ) = true
60
+ GeoInterface. geomtype (:: MyTIN ) = PolyhedralSurfaceTrait ()
61
+ GeoInterface. ngeom (:: PolyhedralSurfaceTrait , geom:: MyTIN ) = 2
62
+ GeoInterface. getgeom (:: PolyhedralSurfaceTrait , geom:: MyTIN , i) = MyTriangle ()
63
+
46
64
GeoInterface. isgeometry (:: MyCollection ) = true
47
65
GeoInterface. geomtype (:: MyCollection ) = GeometryCollectionTrait ()
48
66
GeoInterface. ngeom (:: GeometryCollectionTrait , geom:: MyCollection ) = 2
49
67
GeoInterface. getgeom (:: GeometryCollectionTrait , geom:: MyCollection , i) = MyCurve ()
50
68
51
-
52
69
@testset " Point" begin
53
70
geom = MyPoint ()
54
71
@test testgeometry (geom)
55
72
@test GeoInterface. x (geom) === 1
56
73
@test GeoInterface. y (geom) === 2
74
+ @test_throws ArgumentError GeoInterface. z (geom)
75
+ @test_throws ArgumentError GeoInterface. m (geom)
57
76
@test ncoord (geom) === 2
77
+ @test collect (getcoord (geom)) == [1 , 2 ]
78
+ @test getcoord (geom, 1 ) === 1
79
+ @test GeoInterface. coordnames (geom) == (:X , :Y )
80
+ @test ! GeoInterface. isempty (geom)
81
+ @test ! GeoInterface. is3d (geom)
82
+ @test ! GeoInterface. ismeasured (geom)
83
+
84
+ geom = MyEmptyPoint ()
85
+ @test GeoInterface. coordnames (geom) == ()
86
+ @test GeoInterface. isempty (geom)
87
+
88
+ @test isnothing (GeoInterface. crs (geom))
89
+ @test isnothing (GeoInterface. extent (geom))
90
+ @test isnothing (GeoInterface. bbox (geom))
58
91
end
59
92
60
93
@testset " LineString" begin
@@ -63,9 +96,18 @@ using Test
63
96
64
97
@test GeoInterface. npoint (geom) == 2 # defaults to ngeom
65
98
@test GeoInterface. coordinates (geom) == [[1 , 2 ], [1 , 2 ]]
66
- @test_throws MethodError GeoInterface. area (geom)
99
+ points = GeoInterface. getpoint (geom)
67
100
point = GeoInterface. getpoint (geom, 1 )
101
+ pointa = GeoInterface. startpoint (geom)
102
+ pointb = GeoInterface. endpoint (geom)
68
103
@test GeoInterface. y (point) == 2
104
+
105
+ @test_throws MethodError GeoInterface. length (geom)
106
+
107
+ @test GeoInterface. issimple (geom)
108
+ @test GeoInterface. isclosed (geom)
109
+ @test GeoInterface. isring (geom)
110
+
69
111
end
70
112
71
113
@testset " Polygon" begin
@@ -77,10 +119,20 @@ using Test
77
119
@test GeoInterface. nhole (geom) == 1
78
120
@test GeoInterface. coordinates (geom) == [[[1 , 2 ], [1 , 2 ]], [[1 , 2 ], [1 , 2 ]]]
79
121
lines = GeoInterface. getring (geom)
122
+ line = GeoInterface. getring (geom, 1 )
123
+ lines = GeoInterface. gethole (geom)
80
124
line = GeoInterface. gethole (geom, 1 )
81
125
line = GeoInterface. getexterior (geom)
82
126
@test GeoInterface. npoint (geom) == 4
83
127
@test collect (GeoInterface. getpoint (geom)) == [MyPoint (), MyPoint (), MyPoint (), MyPoint ()]
128
+
129
+ @test_throws MethodError GeoInterface. area (geom)
130
+
131
+ geom = MyTriangle ()
132
+ @test testgeometry (geom)
133
+ @test GeoInterface. nring (geom) == 1
134
+ @test GeoInterface. nhole (geom) == 0
135
+ @test GeoInterface. npoint (geom) == 3
84
136
end
85
137
86
138
@testset " MultiPoint" begin
@@ -92,6 +144,8 @@ using Test
92
144
point = GeoInterface. getpoint (geom, 1 )
93
145
@test GeoInterface. coordinates (geom) == [[1 , 2 ], [1 , 2 ]]
94
146
@test collect (points) == [MyPoint (), MyPoint ()]
147
+
148
+ @test ! GeoInterface. issimple (geom)
95
149
end
96
150
97
151
@testset " MultiLineString" begin
@@ -116,6 +170,17 @@ using Test
116
170
@test collect (polygons) == [MyPolygon (), MyPolygon ()]
117
171
end
118
172
173
+ @testset " Surface" begin
174
+ geom = MyTIN ()
175
+ @test testgeometry (geom)
176
+
177
+ @test GeoInterface. npatch (geom) == 2
178
+ polygons = GeoInterface. getpatch (geom)
179
+ polygon = GeoInterface. getpatch (geom, 1 )
180
+ @test GeoInterface. coordinates (geom) == [[[[1 , 2 ], [1 , 2 ]], [[1 , 2 ], [1 , 2 ]], [[1 , 2 ], [1 , 2 ]]], [[[1 , 2 ], [1 , 2 ]], [[1 , 2 ], [1 , 2 ]], [[1 , 2 ], [1 , 2 ]]]]
181
+ @test collect (polygons) == [MyTriangle (), MyTriangle ()]
182
+ end
183
+
119
184
@testset " GeometryCollection" begin
120
185
geom = MyCollection ()
121
186
@test testgeometry (geom)
131
196
132
197
@testset " Defaults" begin
133
198
@test GeoInterface. subtrait (TINTrait ()) == TriangleTrait
199
+ @test GeoInterface. nring (QuadTrait (), ()) == 1
200
+ @test GeoInterface. npoint (QuadTrait (), ()) == 4
134
201
end
135
202
136
203
@testset " Feature" begin
@@ -158,10 +225,68 @@ end
158
225
Base. convert (:: Type{XCurve} , :: LineStringTrait , geom:: XCurve ) = geom # fast fallthrough
159
226
Base. convert (:: Type{XCurve} , :: LineStringTrait , geom) = geom
160
227
161
- Base. convert (T:: Type{XPolygon} , geom:: X ) where {X} = Base. convert (T, geomtype (geom), geom)
162
-
163
228
geom = MyCurve ()
164
229
@test ! isnothing (convert (MyCurve, geom))
165
230
231
+ Base. convert (T:: Type{XPolygon} , geom:: X ) where {X} = Base. convert (T, geomtype (geom), geom)
166
232
@test_throws Exception convert (MyPolygon, geom)
167
233
end
234
+
235
+ @testset " Operations" begin
236
+ struct XGeom end
237
+
238
+ GeoInterface. isgeometry (:: XGeom ) = true
239
+ GeoInterface. geomtype (:: XGeom ) = PointTrait ()
240
+ GeoInterface. ncoord (:: PointTrait , geom:: XGeom ) = 2
241
+ GeoInterface. getcoord (:: PointTrait , geom:: XGeom , i) = [1 , 2 ][i]
242
+
243
+ GeoInterface. equals (:: PointTrait , :: PointTrait , :: XGeom , :: XGeom ) = true
244
+ GeoInterface. disjoint (:: PointTrait , :: PointTrait , :: XGeom , :: XGeom ) = true
245
+ GeoInterface. intersects (:: PointTrait , :: PointTrait , :: XGeom , :: XGeom ) = true
246
+ GeoInterface. touches (:: PointTrait , :: PointTrait , :: XGeom , :: XGeom ) = true
247
+ GeoInterface. within (:: PointTrait , :: PointTrait , :: XGeom , :: XGeom ) = true
248
+ GeoInterface. contains (:: PointTrait , :: PointTrait , :: XGeom , :: XGeom ) = true
249
+ GeoInterface. overlaps (:: PointTrait , :: PointTrait , :: XGeom , :: XGeom ) = true
250
+ GeoInterface. crosses (:: PointTrait , :: PointTrait , :: XGeom , :: XGeom ) = true
251
+
252
+ GeoInterface. relate (:: PointTrait , :: PointTrait , :: XGeom , :: XGeom , matrix) = true
253
+
254
+ GeoInterface. symdifference (:: PointTrait , :: PointTrait , a:: XGeom , :: XGeom ) = a
255
+ GeoInterface. difference (:: PointTrait , :: PointTrait , a:: XGeom , :: XGeom ) = a
256
+ GeoInterface. intersection (:: PointTrait , :: PointTrait , a:: XGeom , :: XGeom ) = a
257
+ GeoInterface. union (:: PointTrait , :: PointTrait , :: XGeom , a:: XGeom ) = a
258
+
259
+ GeoInterface. distance (:: PointTrait , :: PointTrait , :: XGeom , :: XGeom ) = rand ()
260
+
261
+ GeoInterface. buffer (:: PointTrait , a:: XGeom , distance) = a
262
+ GeoInterface. convexhull (:: PointTrait , a:: XGeom ) = a
263
+
264
+ GeoInterface. astext (:: PointTrait , :: XGeom ) = " POINT (1 2)"
265
+ GeoInterface. asbinary (:: PointTrait , :: XGeom ) = [0x0 , 0x0 ]
266
+
267
+ geom = XGeom ()
268
+
269
+ @test GeoInterface. equals (geom, geom)
270
+ @test GeoInterface. disjoint (geom, geom)
271
+ @test GeoInterface. intersects (geom, geom)
272
+ @test GeoInterface. touches (geom, geom)
273
+ @test GeoInterface. within (geom, geom)
274
+ @test GeoInterface. contains (geom, geom)
275
+ @test GeoInterface. overlaps (geom, geom)
276
+ @test GeoInterface. crosses (geom, geom)
277
+
278
+ @test GeoInterface. relate (geom, geom, [" a" ])
279
+
280
+ @test GeoInterface. isgeometry (GeoInterface. symdifference (geom, geom))
281
+ @test GeoInterface. isgeometry (GeoInterface. difference (geom, geom))
282
+ @test GeoInterface. isgeometry (GeoInterface. intersection (geom, geom))
283
+ @test GeoInterface. isgeometry (GeoInterface. union (geom, geom))
284
+
285
+ @test GeoInterface. distance (geom, geom) isa Number
286
+
287
+ @test GeoInterface. isgeometry (GeoInterface. buffer (geom, 1.0 ))
288
+ @test GeoInterface. isgeometry (GeoInterface. convexhull (geom))
289
+
290
+ @test GeoInterface. astext (geom) isa String
291
+ @test GeoInterface. asbinary (geom) isa Vector{UInt8}
292
+ end
0 commit comments