Skip to content

Commit d42b960

Browse files
authored
Add ncoord for WrapperGeometry (#124)
This was omitted earlier. * Add `ncoord` for arbitrary `WrapperGeometry` This does actually compile down, see: ```julia julia> x = GI.Point(1, 2, 3, 4) GeoInterface.Wrappers.Point{true, true, NTuple{4, Int64}, Nothing}((1, 2, 3, 4), nothing) julia> @code_typed GI.ncoord(x) CodeInfo( 1 ─ return 4 ) => Int64 ``` * Add tests
1 parent 7adf735 commit d42b960

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/wrappers.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ abstract type WrapperGeometry{Z,M,T,C} end
6363
isgeometry(::Type{<:WrapperGeometry}) = true
6464
is3d(::WrapperGeometry{Z}) where Z = Z
6565
ismeasured(::WrapperGeometry{<:Any,M}) where M = M
66+
ncoord(::WrapperGeometry{Z, M}) where {Z, M} = 2 + Z + M
6667

6768
Base.parent(geom::WrapperGeometry) = geom.geom
6869

test/test_wrappers.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ point = GI.Point(1, 2)
77
GI.getcoord(point, 1)
88
@test !GI.ismeasured(point)
99
@test !GI.is3d(point)
10+
@test GI.ncoord(point) == 2
1011
@test GI.extent(point) == Extent(X=(1, 1), Y=(2, 2))
1112
@test point == GI.Point(point)
1213
@test (GI.x(point), GI.y(point)) == (1, 2)
@@ -23,6 +24,7 @@ point_crs = GI.Point(point; crs=EPSG(4326))
2324
pointz = GI.Point(1, 2, 3)
2425
@test !GI.ismeasured(pointz)
2526
@test GI.is3d(pointz)
27+
@test GI.ncoord(pointz) == 3
2628
@test (GI.x(pointz), GI.y(pointz), GI.z(pointz)) == (1, 2, 3)
2729
@test GI.testgeometry(pointz)
2830
@test GI.convert(GI, pointz) === pointz
@@ -34,6 +36,7 @@ pointzm = GI.Point(; X=1, Y=2, Z=3, M=4)
3436
@test pointzm != GI.Point(1, 2, 3)
3537
@test GI.ismeasured(pointzm)
3638
@test GI.is3d(pointzm)
39+
@test GI.ncoord(pointzm) == 4
3740
@test pointzm == GI.Point(pointzm)
3841
@test point != GI.Point(pointzm)
3942
@test (GI.x(pointzm), GI.y(pointzm), GI.z(pointzm), GI.m(pointzm)) == (1, 2, 3, 4)
@@ -48,6 +51,7 @@ pointm = GI.Point((X=1, Y=2, M=3))
4851
@test_throws MethodError GI.Point(; X=1, Y=2, T=3)
4952
@test GI.ismeasured(pointm)
5053
@test !GI.is3d(pointm)
54+
@test GI.ncoord(pointm) == 3
5155
@test pointm == GI.Point(pointm)
5256
@test point != GI.Point(pointm)
5357
@test (GI.x(pointm), GI.y(pointm), GI.m(pointm)) == (1, 2, 3)
@@ -62,6 +66,7 @@ pointtm = GI.Point{false,true}(1, 2, 3)
6266
@test_throws ArgumentError GI.Point{false,true}(1, 2, 3, 4)
6367
@test GI.ismeasured(pointtm)
6468
@test !GI.is3d(pointtm)
69+
@test GI.ncoord(pointtm) == 3
6570
@test (GI.x(pointtm), GI.y(pointtm), GI.m(pointtm)) == (1, 2, 3)
6671
@test_throws ArgumentError GI.z(pointtm)
6772
@test GI.testgeometry(pointtm)
@@ -73,25 +78,29 @@ pointtm_crs = GI.Point{false,true}(1, 2, 3; crs=EPSG(4326))
7378
pointa = GI.Point([1, 2])
7479
@test !GI.ismeasured(pointa)
7580
@test !GI.is3d(pointa)
81+
@test GI.ncoord(pointa) == 2
7682
@test (GI.x(pointa), GI.y(pointa)) == (1, 2)
7783
@test GI.testgeometry(pointa)
7884

7985
pointaz = GI.Point([1, 2, 3])
8086
@test !GI.ismeasured(pointaz)
8187
@test GI.is3d(pointaz)
88+
@test GI.ncoord(pointaz) == 3
8289
@test (GI.x(pointaz), GI.y(pointaz), GI.z(pointaz)) == (1, 2, 3)
8390
@test GI.testgeometry(pointaz)
8491

8592
pointazm = GI.Point([1, 2, 3, 4])
8693
@test GI.ismeasured(pointazm)
8794
@test GI.is3d(pointazm)
95+
@test GI.ncoord(pointazm) == 4
8896
@test (GI.x(pointazm), GI.y(pointazm), GI.z(pointazm), GI.m(pointazm)) == (1, 2, 3, 4)
8997
@test GI.testgeometry(pointazm)
9098

9199
# We can force a vector point to be measured
92100
pointam = GI.Point{false,true}([1, 2, 3])
93101
@test GI.ismeasured(pointam)
94102
@test !GI.is3d(pointam)
103+
@test GI.ncoord(pointam) == 3
95104
@test (GI.x(pointam), GI.y(pointam), GI.m(pointam)) == (1, 2, 3)
96105
@test_throws ArgumentError GI.z(pointam)
97106
@test GI.testgeometry(pointam)
@@ -104,6 +113,7 @@ line = GI.Line([(1, 2), (3, 4)])
104113
@test GI.getgeom(line) == [(1, 2), (3, 4)]
105114
@test GI.testgeometry(line)
106115
@test !GI.is3d(line)
116+
@test GI.ncoord(line) == 2
107117
@test GI.extent(line) == Extent(X=(1, 3), Y=(2, 4))
108118
@test_throws ArgumentError GI.Line(point)
109119
@test_throws ArgumentError GI.Line([(1, 2)])
@@ -119,6 +129,7 @@ linestring = GI.LineString([(1, 2), (3, 4)])
119129
@test GI.getgeom(linestring) == [(1, 2), (3, 4)]
120130
@test GI.testgeometry(linestring)
121131
@test !GI.is3d(linestring)
132+
@test GI.ncoord(linestring) == 2
122133
@test @inferred(GI.extent(linestring)) == Extent(X=(1, 3), Y=(2, 4))
123134
@test_throws ArgumentError GI.LineString([(1, 2)])
124135
linestring_crs = GI.LineString(linestring; crs=EPSG(4326))
@@ -132,6 +143,7 @@ linearring = GI.LinearRing([(1, 2), (3, 4), (5, 6), (1, 2)])
132143
@test GI.getgeom(linearring) == [(1, 2), (3, 4), (5, 6), (1, 2)]
133144
@test GI.testgeometry(linearring)
134145
@test !GI.is3d(linearring)
146+
@test GI.ncoord(linearring) == 2
135147
@test @inferred(GI.extent(linearring)) == Extent(X=(1, 5), Y=(2, 6))
136148
@test_throws ArgumentError GI.LinearRing([(1, 2)])
137149
linearring_crs = GI.LinearRing(linearring; crs=EPSG(4326))
@@ -146,6 +158,7 @@ polygon = GI.Polygon([linearring, linearring])
146158
@test collect(GI.getpoint(polygon)) == vcat(collect(GI.getpoint(linearring)), collect(GI.getpoint(linearring)))
147159
@test GI.testgeometry(polygon)
148160
@test !GI.is3d(polygon)
161+
@test GI.ncoord(polygon) == 2
149162
@test @inferred(GI.extent(polygon)) == Extent(X=(1, 5), Y=(2, 6))
150163
@test GI.convert(GI, MyPolygon()) isa GI.Polygon
151164
@test GI.convert(GI, polygon) === polygon
@@ -160,13 +173,15 @@ polygon = GI.Polygon([linestring, linestring])
160173
linearring3d = GI.LinearRing([(1, 2, 3), (3, 4, 5), (5, 6, 7), (1, 2, 3)])
161174
polygon3d = GI.Polygon([linearring3d, linearring3d])
162175
@test GI.is3d(polygon3d)
176+
@test GI.ncoord(polygon3d) == 3
163177
@test GI.extent(polygon3d) == Extents.Extent(X=(1, 5), Y=(2, 6), Z=(3, 7))
164178

165179
# MultiPoint
166180
multipoint = GI.MultiPoint([(1, 2), (3, 4), (3, 2), (1, 4), (7, 8), (9, 10)])
167181
@test multipoint == GI.MultiPoint(multipoint)
168182
@test GI.getgeom(multipoint, 1) === (1, 2)
169183
@test !GI.is3d(multipoint)
184+
@test GI.ncoord(multipoint) == 2
170185
@test @inferred(GI.extent(multipoint)) == Extent(X=(1, 9), Y=(2, 10))
171186
@test_throws ArgumentError GI.MultiPoint([[(1, 2), (3, 4), (3, 2), (1, 4), (7, 8), (9, 10)]])
172187
@test GI.testgeometry(multipoint)
@@ -181,6 +196,7 @@ collection = GI.GeometryCollection(geoms)
181196
@test GI.getgeom(collection) == geoms
182197
@test GI.testgeometry(collection)
183198
@test !GI.is3d(collection)
199+
@test GI.ncoord(collection) == 2
184200
@test GI.extent(collection) == reduce(Extents.union, map(GI.extent, geoms))
185201
collection_crs = GI.GeometryCollection(collection; crs=EPSG(4326))
186202
@test parent(collection_crs) == parent(collection)
@@ -192,6 +208,7 @@ multicurve = GI.MultiCurve([linestring, linearring])
192208
@test multicurve == GI.MultiCurve(multicurve)
193209
@test GI.getgeom(multicurve, 1) === linestring
194210
@test !GI.is3d(multicurve)
211+
@test GI.ncoord(multicurve) == 2
195212
@test GI.extent(multicurve) == Extent(X=(1, 5), Y=(2, 6))
196213
@test_throws ArgumentError GI.MultiCurve([pointz, polygon])
197214
@test GI.testgeometry(multicurve)
@@ -206,6 +223,7 @@ multipolygon = GI.MultiPolygon([polygon])
206223
@test multipolygon == GI.MultiPolygon(multipolygon)
207224
@test GI.getgeom(multipolygon, 1) === polygon
208225
@test !GI.is3d(multipolygon)
226+
@test GI.ncoord(multipolygon) == 2
209227
@show polygon
210228
@show GI.getgeom(polygon, 1)
211229
# MultiPolygon extent does not infer, maybe due to nesting
@@ -221,6 +239,7 @@ multipolygon_crs = GI.MultiPolygon(multipolygon; crs=EPSG(4326))
221239
polyhedralsurface = GI.PolyhedralSurface([polygon, polygon])
222240
@test polyhedralsurface == GI.PolyhedralSurface(polyhedralsurface)
223241
@test !GI.is3d(polyhedralsurface)
242+
@test GI.ncoord(polyhedralsurface) == 2
224243
@test @inferred(GI.extent(polyhedralsurface)) == Extent(X=(1, 5), Y=(2, 6))
225244
@test GI.getgeom(polyhedralsurface, 1) === polygon
226245
@test collect(GI.getgeom(polyhedralsurface)) == [polygon, polygon]

0 commit comments

Comments
 (0)