Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GeoInterface x y z #164

Merged
merged 3 commits into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/geo_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ GeoInterface.getgeom(t::AbstractGeometryTrait, geom::PreparedGeometry, i) =
GeoInterface.getgeom(t, geom.ownedby, i)
GeoInterface.getgeom(t::AbstractPointTrait, geom::PreparedGeometry, i) = 0

GeoInterface.x(::AbstractPointTrait, geom::AbstractGeometry) = getX(geom.ptr, 1, get_context(geom))
GeoInterface.y(::AbstractPointTrait, geom::AbstractGeometry) = getY(geom.ptr, 1, get_context(geom))
GeoInterface.z(::AbstractPointTrait, geom::AbstractGeometry) = getZ(geom.ptr, 1, get_context(geom))

GeoInterface.ncoord(::AbstractGeometryTrait, geom::AbstractGeometry) =
isEmpty(geom) ? 0 : getCoordinateDimension(geom)
GeoInterface.getcoord(::AbstractGeometryTrait, geom::AbstractGeometry, i) =
Expand All @@ -67,6 +63,7 @@ GeoInterface.ncoord(t::AbstractGeometryTrait, geom::PreparedGeometry) =
GeoInterface.getcoord(t::AbstractGeometryTrait, geom::PreparedGeometry, i) =
GeoInterface.getcoord(t, geom.ownedby, i)

# FIXME this doesn't work for 3d geoms, Z is missing
function GeoInterface.extent(::AbstractGeometryTrait, geom::AbstractGeometry)
# minx, miny, maxx, maxy = getExtent(geom)
env = envelope(geom)
Expand Down
14 changes: 14 additions & 0 deletions test/test_geo_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const LG = LibGEOS

@testset "Geo interface" begin
pt = LibGEOS.Point(1.0, 2.0)
@test GeoInterface.x(pt) == 1.0
@test GeoInterface.y(pt) == 2.0
@test GeoInterface.coordinates(pt) ≈ [1, 2] atol = 1e-5
@test GeoInterface.geomtrait(pt) == PointTrait()
@test GeoInterface.ncoord(pt) == 2
Expand All @@ -12,6 +14,18 @@ const LG = LibGEOS
@test GeoInterface.extent(pt) == Extent(X = (1.0, 1.0), Y = (2.0, 2.0))
plot(pt)

pt = LibGEOS.Point(1.0, 2.0, 3.0)
@test GeoInterface.x(pt) == 1.0
@test GeoInterface.y(pt) == 2.0
@test GeoInterface.z(pt) == 3.0
@test GeoInterface.coordinates(pt) ≈ [1, 2, 3] atol = 1e-5
@test GeoInterface.ncoord(pt) == 3
@test GeoInterface.getcoord(pt, 3) ≈ 3.0
@test GeoInterface.testgeometry(pt)
# 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))
plot(pt)

pt = LibGEOS.Point(1, 2)
@test GeoInterface.coordinates(pt) ≈ [1, 2] atol = 1e-5
@test GeoInterface.geomtrait(pt) == PointTrait()
Expand Down