Skip to content

Commit d8e9986

Browse files
rafaqzevetion
andauthored
Add is3d method (#195)
Co-authored-by: Maarten Pronk <[email protected]>
1 parent d0b0aa8 commit d8e9986

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/geo_interface.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ GeoInterface.ngeom(t::AbstractGeometryTrait, geom::PreparedGeometry) =
3131
GeoInterface.ngeom(::AbstractPointTrait, geom::Point) = 0
3232
GeoInterface.ngeom(::AbstractPointTrait, geom::PreparedGeometry) = 0
3333

34+
GI.is3d(::AbstractGeometryTrait, geom::AbstractGeometry) = hasZ(geom)
3435
GI.getexterior(::AbstractPolygonTrait, geom::Polygon) = exteriorRing(geom)
3536
GI.gethole(::AbstractPolygonTrait, geom::Polygon, n) = interiorRing(geom, n)
3637

src/geos_functions.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,8 @@ function hasZ(obj::Geometry, context::GEOSContext = get_context(obj))
11881188
end
11891189
result != 0x00
11901190
end
1191+
hasZ(obj::PreparedGeometry, context::GEOSContext = get_context(obj)) =
1192+
hasZ(obj.ownedby, context)
11911193

11921194
# Call only on LINESTRING (return 2 on exception, 1 on true, 0 on false)
11931195
function isClosed(obj::LineString, context::GEOSContext = get_context(obj))

test/test_geo_interface.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const LG = LibGEOS
1111
@test GeoInterface.ncoord(pt) == 2
1212
@test GeoInterface.getcoord(pt, 1) 1.0
1313
@test GeoInterface.testgeometry(pt)
14+
@test GeoInterface.is3d(pt) == false
1415
@test GeoInterface.extent(pt) == Extent(X=(1.0, 1.0), Y=(2.0, 2.0))
1516
plot(pt)
1617

@@ -22,6 +23,7 @@ const LG = LibGEOS
2223
@test GeoInterface.ncoord(pt) == 3
2324
@test GeoInterface.getcoord(pt, 3) 3.0
2425
@test GeoInterface.testgeometry(pt)
26+
@test GeoInterface.is3d(pt) == true
2527
# This doesn't return the Z extent
2628
@test_broken GeoInterface.extent(pt) ==
2729
Extent(X = (1.0, 1.0), Y = (2.0, 2.0), Z = (3.0, 3.0))
@@ -33,6 +35,7 @@ const LG = LibGEOS
3335
@test GeoInterface.testgeometry(pt)
3436
@test GeoInterface.x(pt) == 1
3537
@test GeoInterface.y(pt) == 2
38+
@test GeoInterface.is3d(pt) == false
3639
@test isnan(GeoInterface.z(pt))
3740

3841
@inferred GeoInterface.ncoord(pt)
@@ -47,6 +50,7 @@ const LG = LibGEOS
4750
@test GeoInterface.coordinates(pt) Float64[] atol = 1e-5
4851
@test GeoInterface.geomtrait(pt) == PointTrait()
4952
@test GeoInterface.ncoord(pt) == 0
53+
@test GeoInterface.is3d(pt) == false
5054
@test GeoInterface.testgeometry(pt)
5155

5256
mpt = LibGEOS.readgeom("MULTIPOINT(0 0, 10 0, 10 10, 11 10)")
@@ -58,6 +62,7 @@ const LG = LibGEOS
5862
@test p isa LibGEOS.Point
5963
@test GeoInterface.coordinates(p) == [10, 0]
6064
@test GeoInterface.testgeometry(mpt)
65+
@test GeoInterface.is3d(mpt) == false
6166
plot(mpt)
6267

6368
@inferred GeoInterface.ncoord(mpt)
@@ -74,6 +79,7 @@ const LG = LibGEOS
7479
@test p isa LibGEOS.Point
7580
@test GeoInterface.coordinates(p) == [9, 2]
7681
@test GeoInterface.testgeometry(ls)
82+
@test GeoInterface.is3d(ls) == false
7783
plot(ls)
7884

7985
@inferred GeoInterface.ncoord(ls)
@@ -91,6 +97,7 @@ const LG = LibGEOS
9197
@test GeoInterface.geomtrait(mls) == MultiLineStringTrait()
9298
@test GeoInterface.ngeom(mls) == 2
9399
@test GeoInterface.testgeometry(mls)
100+
@test GeoInterface.is3d(mls) == false
94101
plot(mls)
95102

96103
@inferred GeoInterface.ncoord(mls)
@@ -106,6 +113,7 @@ const LG = LibGEOS
106113
p = GeoInterface.getgeom(lr, 3)
107114
@test p isa LibGEOS.Point
108115
@test GeoInterface.coordinates(p) == [9, 2]
116+
@test GeoInterface.is3d(lr) == false
109117
@test GeoInterface.testgeometry(lr)
110118
# Cannot convert LinearRingTrait to series data for plotting
111119
# plot(lr)
@@ -128,6 +136,7 @@ const LG = LibGEOS
128136
@test ls isa LibGEOS.LinearRing
129137
@test GeoInterface.coordinates(ls) == coords[2]
130138
@test GeoInterface.testgeometry(polygon)
139+
@test GeoInterface.is3d(polygon) == false
131140
plot(polygon)
132141

133142
@inferred GeoInterface.ncoord(polygon)
@@ -151,6 +160,7 @@ const LG = LibGEOS
151160
]]]
152161
@test GeoInterface.geomtrait(multipolygon) == MultiPolygonTrait()
153162
@test GeoInterface.testgeometry(multipolygon)
163+
@test GeoInterface.is3d(multipolygon) == false
154164
@test GeoInterface.extent(multipolygon) == Extent(X=(0.0, 10.0), Y=(0.0, 10.0))
155165
plot(multipolygon)
156166

@@ -162,6 +172,7 @@ const LG = LibGEOS
162172
pmultipolygon = LibGEOS.prepareGeom(multipolygon)
163173
@test GeoInterface.geomtrait(pmultipolygon) == MultiPolygonTrait()
164174
@test GeoInterface.testgeometry(pmultipolygon)
175+
@test GeoInterface.is3d(pmultipolygon) == false
165176
@test GeoInterface.extent(pmultipolygon) == Extent(X=(0.0, 10.0), Y=(0.0, 10.0))
166177
LibGEOS.destroyGeom(pmultipolygon)
167178

@@ -235,6 +246,7 @@ const LG = LibGEOS
235246
end
236247
@test GeoInterface.geomtrait(geomcollection) == GeometryCollectionTrait()
237248
@test GeoInterface.testgeometry(geomcollection)
249+
@test GeoInterface.is3d(geomcollection) == false
238250
plot(geomcollection)
239251

240252
@inferred GeoInterface.ncoord(geomcollection)
@@ -267,6 +279,7 @@ const LG = LibGEOS
267279
geomcollection = LibGEOS.readgeom("GEOMETRYCOLLECTION EMPTY")
268280
@test GeoInterface.ngeom(geomcollection) == 0
269281
@test GeoInterface.geomtrait(geomcollection) == GeometryCollectionTrait()
282+
@test GeoInterface.is3d(geomcollection) == false
270283
@test GeoInterface.testgeometry(geomcollection)
271284

272285
@testset "Conversion" begin

0 commit comments

Comments
 (0)