Skip to content

Commit

Permalink
Implement GeoInterface astext and asbinary.
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion committed Jul 11, 2024
1 parent 15ffc2c commit 9940365
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/wkb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,5 @@ function typesize(T::GI.GeometryCollectionTrait, geom, n::Integer)
end
return size
end

GI.asbinary(::GI.AbstractGeometryTrait, geom) = WellKnownGeometry.getwkb(geom)
2 changes: 2 additions & 0 deletions src/wkt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,5 @@ function GI.getgeom(
end
return WKTtype(gftgeom, data)
end

GI.astext(::GI.AbstractGeometryTrait, geom) = getwkt(geom)
26 changes: 26 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,30 @@ import LibGEOS
wkt = GFT.WellKnownText(GFT.Geom(), "POINT(30 10)")
@test GI.testgeometry(wkt)
end

@testset "GeoInterface piracy" begin
@test GI.astext((1.0, 2.0)) == GFT.WellKnownText(GFT.Geom(), "POINT (1.0 2.0)")
@test GI.asbinary((1.0, 2.0)).val == UInt8[
0x01,
0x01,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0xf0,
0x3f,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x40]
end
end

0 comments on commit 9940365

Please sign in to comment.