Skip to content

Commit

Permalink
Add is3d method (#195)
Browse files Browse the repository at this point in the history
Co-authored-by: Maarten Pronk <8655030+evetion@users.noreply.github.com>
  • Loading branch information
rafaqz and evetion committed Jan 7, 2024
1 parent c5f3889 commit 1cac960
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/geos_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,8 @@ function hasZ(obj::Geometry, context::GEOSContext = get_context(obj))
end
result != 0x00
end
hasZ(obj::PreparedGeometry, context::GEOSContext = get_context(obj)) =
hasZ(obj.ownedby, context)

# Call only on LINESTRING (return 2 on exception, 1 on true, 0 on false)
function isClosed(obj::LineString, context::GEOSContext = get_context(obj))
Expand Down
13 changes: 13 additions & 0 deletions test/test_geo_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const LG = LibGEOS
@test GeoInterface.ncoord(pt) == 2
@test GeoInterface.getcoord(pt, 1) 1.0
@test GeoInterface.testgeometry(pt)
@test GeoInterface.is3d(pt) == false
@test GeoInterface.extent(pt) == Extent(X=(1.0, 1.0), Y=(2.0, 2.0))
plot(pt)

Expand All @@ -22,6 +23,7 @@ const LG = LibGEOS
@test GeoInterface.ncoord(pt) == 3
@test GeoInterface.getcoord(pt, 3) 3.0
@test GeoInterface.testgeometry(pt)
@test GeoInterface.is3d(pt) == true
# This doesn't return the Z extent
@test_broken GeoInterface.extent(pt) ==
Extent(X = (1.0, 1.0), Y = (2.0, 2.0), Z = (3.0, 3.0))
Expand All @@ -33,6 +35,7 @@ const LG = LibGEOS
@test GeoInterface.testgeometry(pt)
@test GeoInterface.x(pt) == 1
@test GeoInterface.y(pt) == 2
@test GeoInterface.is3d(pt) == false
@test isnan(GeoInterface.z(pt))

@inferred GeoInterface.ncoord(pt)
Expand All @@ -47,6 +50,7 @@ const LG = LibGEOS
@test GeoInterface.coordinates(pt) Float64[] atol = 1e-5
@test GeoInterface.geomtrait(pt) == PointTrait()
@test GeoInterface.ncoord(pt) == 0
@test GeoInterface.is3d(pt) == false
@test GeoInterface.testgeometry(pt)

mpt = LibGEOS.readgeom("MULTIPOINT(0 0, 10 0, 10 10, 11 10)")
Expand All @@ -58,6 +62,7 @@ const LG = LibGEOS
@test p isa LibGEOS.Point
@test GeoInterface.coordinates(p) == [10, 0]
@test GeoInterface.testgeometry(mpt)
@test GeoInterface.is3d(mpt) == false
plot(mpt)

@inferred GeoInterface.ncoord(mpt)
Expand All @@ -75,6 +80,7 @@ const LG = LibGEOS
@test GeoInterface.coordinates(p) == [9, 2]
@test GeoInterface.testgeometry(ls)
@test collect(GeoInterface.getpoint(ls)) == [(8, 1), (9, 1), (9, 2), (8, 2)]
@test GeoInterface.is3d(ls) == false
plot(ls)

@inferred GeoInterface.ncoord(ls)
Expand All @@ -92,6 +98,7 @@ const LG = LibGEOS
@test GeoInterface.geomtrait(mls) == MultiLineStringTrait()
@test GeoInterface.ngeom(mls) == 2
@test GeoInterface.testgeometry(mls)
@test GeoInterface.is3d(mls) == false
plot(mls)

@inferred GeoInterface.ncoord(mls)
Expand All @@ -107,6 +114,7 @@ const LG = LibGEOS
p = GeoInterface.getgeom(lr, 3)
@test p isa Tuple{Float64,Float64}
@test GeoInterface.coordinates(p) == [9, 2]
@test GeoInterface.is3d(lr) == false
@test GeoInterface.testgeometry(lr)
@test collect(GeoInterface.getpoint(lr)) == [(8, 1), (9, 1), (9, 2), (8, 2), (8, 1)]
# Cannot convert LinearRingTrait to series data for plotting
Expand All @@ -130,6 +138,7 @@ const LG = LibGEOS
@test ls isa LibGEOS.LinearRing
@test GeoInterface.coordinates(ls) == coords[2]
@test GeoInterface.testgeometry(polygon)
@test GeoInterface.is3d(polygon) == false
plot(polygon)

@inferred GeoInterface.ncoord(polygon)
Expand All @@ -153,6 +162,7 @@ const LG = LibGEOS
]]]
@test GeoInterface.geomtrait(multipolygon) == MultiPolygonTrait()
@test GeoInterface.testgeometry(multipolygon)
@test GeoInterface.is3d(multipolygon) == false
@test GeoInterface.extent(multipolygon) == Extent(X=(0.0, 10.0), Y=(0.0, 10.0))
plot(multipolygon)

Expand All @@ -164,6 +174,7 @@ const LG = LibGEOS
pmultipolygon = LibGEOS.prepareGeom(multipolygon)
@test GeoInterface.geomtrait(pmultipolygon) == MultiPolygonTrait()
@test GeoInterface.testgeometry(pmultipolygon)
@test GeoInterface.is3d(pmultipolygon) == false
@test GeoInterface.extent(pmultipolygon) == Extent(X=(0.0, 10.0), Y=(0.0, 10.0))
LibGEOS.destroyGeom(pmultipolygon)

Expand Down Expand Up @@ -237,6 +248,7 @@ const LG = LibGEOS
end
@test GeoInterface.geomtrait(geomcollection) == GeometryCollectionTrait()
@test GeoInterface.testgeometry(geomcollection)
@test GeoInterface.is3d(geomcollection) == false
plot(geomcollection)

@inferred GeoInterface.ncoord(geomcollection)
Expand Down Expand Up @@ -269,6 +281,7 @@ const LG = LibGEOS
geomcollection = LibGEOS.readgeom("GEOMETRYCOLLECTION EMPTY")
@test GeoInterface.ngeom(geomcollection) == 0
@test GeoInterface.geomtrait(geomcollection) == GeometryCollectionTrait()
@test GeoInterface.is3d(geomcollection) == false
@test GeoInterface.testgeometry(geomcollection)

@testset "Conversion" begin
Expand Down

0 comments on commit 1cac960

Please sign in to comment.