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

Forward GeoInterface.centroid #365

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions src/geointerface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ let pointtypes = (wkbPoint, wkbPoint25D, wkbPointM, wkbPointZM),
end
end

function GeoInterface.centroid(::GeometryTraits, geom::AbstractGeometry)
return centroid(geom)
end

function GeoInterface.asbinary(::GeometryTraits, geom::AbstractGeometry)
return toWKB(geom)
end
Expand Down
8 changes: 7 additions & 1 deletion test/test_geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ArchGDAL as AG
import GeoFormatTypes as GFT

@testset "test_geometry.jl" begin
@testset "GeoInterface" begin
@testset "GeoInterface" begin
AG.createpoint(100, 70) do point
@test GI.geomtrait(point) == GI.PointTrait()
@test GI.testgeometry(point)
Expand Down Expand Up @@ -400,6 +400,9 @@ import GeoFormatTypes as GFT
atol = 1e-6,
)
@test AG.toWKT(geom) == "POLYGON ((1 4,2 5,3 6))"
@test_throws "Points of LinearRing do not form a closed linestring" GI.centroid(geom)
AG.closerings!(geom)
@test all(GI.coordinates(GI.centroid(geom)) .== (2, 5))
end
AG.createpolygon(
[1.0, 2.0, 3.0],
Expand Down Expand Up @@ -542,6 +545,9 @@ import GeoFormatTypes as GFT
"((0 0,0 4,4 4,4 0),(1 1,1 3,3 3,3 1))," *
"((10 0,10 4,14 4,14 0),(11 1,11 3,13 3,13 1)))"
end
@test_throws "Points of LinearRing do not form a closed linestring" GI.centroid(geom)
AG.closerings!(geom)
@test all(GI.coordinates(GI.centroid(geom)) .== (7, 2))
end

@testset "circularstring" begin
Expand Down