Skip to content

Commit dfc748d

Browse files
jw3126visr
authored andcommitted
improve show
1 parent aad0185 commit dfc748d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/geos_types.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
abstract type AbstractGeometry end
22

3+
function Base.show(io::IO, geo::AbstractGeometry)
4+
compact = get(io, :compact, false)
5+
if compact
6+
print(io, typeof(geo), "(...)")
7+
else
8+
s = writegeom(geo)
9+
print(io, s)
10+
end
11+
end
12+
313
"""
414
515
get_context(geom::AbstractGeometry)::GEOSContext

test/test_misc.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,25 @@ end
3636
@test_throws ArgumentError LibGEOS.intersects(p1, q2)
3737
@test_throws ArgumentError LibGEOS.intersects(p2, q1)
3838
end
39+
40+
@testset "show it like you build it" begin
41+
for geo in [
42+
readgeom("POINT(0 0)")
43+
readgeom("MULTIPOINT(0 0, 5 0, 10 0)")
44+
readgeom("LINESTRING (130 240, 650 240)")
45+
readgeom("POLYGON EMPTY")
46+
readgeom("POLYGON ((10 10, 20 40, 90 90, 90 10, 10 10))")
47+
readgeom("MULTILINESTRING ((5 0, 10 0), (0 0, 5 0))")
48+
readgeom("GEOMETRYCOLLECTION (LINESTRING (1 2, 2 2), LINESTRING (2 1, 1 1), POLYGON ((0.5 1, 1 2, 1 1, 0.5 1)), POLYGON ((9 2, 9.5 1, 2 1, 2 2, 9 2)))")
49+
]
50+
geo2 = readgeom(sprint(show, geo))
51+
@test LibGEOS.equals(geo, geo2)
52+
end
53+
p = Polygon([[[0.0, 0.0] for _ in 1:10000]])
54+
buf = IOBuffer()
55+
print(IOContext(buf, :compact=>true), p)
56+
seekstart(buf)
57+
s = read(buf, String)
58+
@test length(s) < 30
59+
@test occursin("Polygon(...)", s)
60+
end

0 commit comments

Comments
 (0)