From 50b2140a3c78b8cdbf1a7bc6faf2ae38c2df722e Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Jan 2025 23:37:08 +0100 Subject: [PATCH 1/6] bugfix missing or wrongly named variables --- src/wrappers.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wrappers.jl b/src/wrappers.jl index 4c15c8d..c4d6991 100644 --- a/src/wrappers.jl +++ b/src/wrappers.jl @@ -234,7 +234,7 @@ for (geomtype, trait, childtype, child_trait, length_check, nesting) in ( str *= "]" else - str *= _nice_geom_str(g, false, compact, screen_ncols - currently_used_space) + str *= _nice_geom_str(geom, false, compact, screen_ncols - currently_used_space) end str *= extent_str @@ -652,9 +652,9 @@ _child_feature_error() = throw(ArgumentError("child objects must be features")) isfeaturecollection(fc::Type{<:FeatureCollection}) = true trait(fc::FeatureCollection) = FeatureCollectionTrait() -nfeature(::FeatureCollectionTrait, fc::FeatureCollection) = +nfeature(t::FeatureCollectionTrait, fc::FeatureCollection) = _parent_is_fc(fc) ? nfeature(t, parent(fc)) : length(parent(fc)) -getfeature(::FeatureCollectionTrait, fc::FeatureCollection) = +getfeature(t::FeatureCollectionTrait, fc::FeatureCollection) = _parent_is_fc(fc) ? getfeature(t, parent(fc)) : parent(fc) getfeature(t::FeatureCollectionTrait, fc::FeatureCollection, i::Integer) = _parent_is_fc(fc) ? getfeature(t, parent(fc), i) : parent(fc)[i] From 2244667db99f5fb0de2aad4de4eb069eadc2ebd7 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 6 Jan 2025 23:56:48 +0100 Subject: [PATCH 2/6] bugfix show --- src/wrappers.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wrappers.jl b/src/wrappers.jl index c4d6991..348cc05 100644 --- a/src/wrappers.jl +++ b/src/wrappers.jl @@ -172,7 +172,9 @@ for (geomtype, trait, childtype, child_trait, length_check, nesting) in ( # But not if geom is already a WrapperGeometry convert(::Type{$geomtype}, ::$trait, geom::$geomtype) = geom - function Base.show(io::IO, ::MIME"text/plain", geom::$geomtype{Z, M, T, E, C}; show_mz::Bool = true, screen_ncols::Int = displaysize(io)[2]) where {Z, M, T, E <: Union{Nothing,Extents.Extent}, C} + function Base.show(io::IO, ::MIME"text/plain", geom::$geomtype{Z, M, T, E, C}; + show_mz::Bool = true, screen_ncols::Int = displaysize(io)[2] + ) where {Z, M, T, E <: Union{Nothing,Extents.Extent}, C} compact = get(io, :compact, false) spacing = compact ? "" : " " show_mz &= !compact @@ -188,7 +190,7 @@ for (geomtype, trait, childtype, child_trait, length_check, nesting) in ( end end - str = "$($geomtype)" + str = string($geomtype) if show_mz str *= "{$Z,$(spacing)$M}" end @@ -234,7 +236,7 @@ for (geomtype, trait, childtype, child_trait, length_check, nesting) in ( str *= "]" else - str *= _nice_geom_str(geom, false, compact, screen_ncols - currently_used_space) + str *= _nice_geom_str(parent(geom), false, compact, screen_ncols - currently_used_space) end str *= extent_str From ba8e1f790d5bf6462abdc5977460d94e71c533d5 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 16 Jan 2025 07:00:23 -0500 Subject: [PATCH 3/6] try fixing point show by adding kwarg --- src/wrappers.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wrappers.jl b/src/wrappers.jl index 348cc05..6a7b6b0 100644 --- a/src/wrappers.jl +++ b/src/wrappers.jl @@ -451,7 +451,7 @@ function Base.:(==)(g1::Point, g2::Point) end Base.:(!=)(g1::Point, g2::Point) = !(g1 == g2) -function Base.show(io::IO, ::MIME"text/plain", point::Point{Z, M, T, C}; show_mz::Bool = true) where {Z,M,T,C} +function Base.show(io::IO, ::MIME"text/plain", point::Point{Z, M, T, C}; show_mz::Bool = true, screen_ncols::Int = displaysize(io)[2]) where {Z,M,T,C} print(io, "Point") this_crs = crs(point) @@ -667,4 +667,4 @@ crs(fc::FeatureCollection) = _parent_is_fc(x) = isfeaturecollection(parent(x)) -end # module \ No newline at end of file +end # module From 7754124e0a056c812cff2ef3bae0e62c1a3d4800 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Sun, 19 Jan 2025 19:00:56 -0500 Subject: [PATCH 4/6] Use sprint() instead of global IO buffers in test_display --- test/test_wrappers.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/test_wrappers.jl b/test/test_wrappers.jl index f8e25e4..f5f550e 100644 --- a/test/test_wrappers.jl +++ b/test/test_wrappers.jl @@ -2,18 +2,18 @@ using Test, GeoFormatTypes, Extents import GeoInterface as GI using GeoInterface.Wrappers -# use this to test our string representations for geoms -buf = IOBuffer() -compact_buf = IOContext(buf, :compact => true) - # checks that our string display for geoms in regular/compact form is as expected function test_display(geom, expected_str, expected_compact_str) # checks non-compact string repr - show(buf, MIME"text/plain"(), geom) - @test expected_str == String(take!(buf)) + generated_str = sprint() do io + show(io, MIME"text/plain"(), geom) + end + @test expected_str == generated_str # checks compact string repr - show(compact_buf, MIME"text/plain"(), geom) - @test expected_compact_str == String(take!(buf)) + generated_compact_str = sprint() do io + show(IOContext(io, :compact => true), MIME"text/plain"(), geom) + end + @test expected_compact_str == generated_compact_str end # Point From 3cb9c5f445f6aaf5dd85c7e008e435e2e62e365f Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Sun, 19 Jan 2025 19:01:07 -0500 Subject: [PATCH 5/6] Test the printing of wrapped geometries --- test/test_wrappers.jl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test_wrappers.jl b/test/test_wrappers.jl index f5f550e..e9f2f35 100644 --- a/test/test_wrappers.jl +++ b/test/test_wrappers.jl @@ -365,6 +365,30 @@ test_display(fc, "FeatureCollection([Feature(MultiPolygon{false, false}([Polygon vecfc = GI.FeatureCollection([(geometry=(1,2), a=1, b=2)]) @test GI.getfeature(vecfc, 1) == (geometry=(1,2), a=1, b=2) +@testset "Wrapped geometry printing" begin + struct MyPoint + x::Float64 + y::Float64 + end + GI.geomtrait(::MyPoint) = GI.PointTrait() + GI.ncoord(::GI.PointTrait, ::MyPoint) = 2 + GI.x(::GI.PointTrait, p::MyPoint) = p.x + GI.y(::GI.PointTrait, p::MyPoint) = p.y + + + test_display(GI.Point(MyPoint(1.0, 2.0)), "Point{false, false}((1.0, 2.0))", "Point((1.0,2.0))") + + GI.geomtrait(::Vector{MyPoint}) = GI.LineStringTrait() + GI.npoint(::GI.LineStringTrait, v::Vector{MyPoint}) = length(v) + GI.getpoint(::GI.LineStringTrait, v::Vector{MyPoint}, i::Integer) = v[i] + + test_display( + GI.LineString([MyPoint(1.0, 2.0), MyPoint(3.0, 4.0)]), + "LineString{false, false}([MyPoint(1.0, 2.0), MyPoint(3.0, 4.0)])", + "LineString([MyPoint(1.0,2.0),MyPoint(3.0,4.0)])" # FIXME: this should not show the point type! + ) +end + # TODO # # Triangle From c0c7558f5a7721773deb42160e0ecc8edb4da1b8 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Sun, 19 Jan 2025 20:51:48 -0500 Subject: [PATCH 6/6] we be rappin now this is probably the best example of a 9pm commit I've had so far... in all seriousness we could change the name --- test/test_wrappers.jl | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/test/test_wrappers.jl b/test/test_wrappers.jl index e9f2f35..26a783f 100644 --- a/test/test_wrappers.jl +++ b/test/test_wrappers.jl @@ -365,27 +365,31 @@ test_display(fc, "FeatureCollection([Feature(MultiPolygon{false, false}([Polygon vecfc = GI.FeatureCollection([(geometry=(1,2), a=1, b=2)]) @test GI.getfeature(vecfc, 1) == (geometry=(1,2), a=1, b=2) + + +struct MaPointRappa + x::Float64 + y::Float64 +end + @testset "Wrapped geometry printing" begin - struct MyPoint - x::Float64 - y::Float64 - end - GI.geomtrait(::MyPoint) = GI.PointTrait() - GI.ncoord(::GI.PointTrait, ::MyPoint) = 2 - GI.x(::GI.PointTrait, p::MyPoint) = p.x - GI.y(::GI.PointTrait, p::MyPoint) = p.y + + GI.geomtrait(::MaPointRappa) = GI.PointTrait() + GI.ncoord(::GI.PointTrait, ::MaPointRappa) = 2 + GI.x(::GI.PointTrait, p::MaPointRappa) = p.x + GI.y(::GI.PointTrait, p::MaPointRappa) = p.y - test_display(GI.Point(MyPoint(1.0, 2.0)), "Point{false, false}((1.0, 2.0))", "Point((1.0,2.0))") + test_display(GI.Point(MaPointRappa(1.0, 2.0)), "Point{false, false}((1.0, 2.0))", "Point((1.0,2.0))") - GI.geomtrait(::Vector{MyPoint}) = GI.LineStringTrait() - GI.npoint(::GI.LineStringTrait, v::Vector{MyPoint}) = length(v) - GI.getpoint(::GI.LineStringTrait, v::Vector{MyPoint}, i::Integer) = v[i] + GI.geomtrait(::Vector{MaPointRappa}) = GI.LineStringTrait() + GI.npoint(::GI.LineStringTrait, v::Vector{MaPointRappa}) = length(v) + GI.getpoint(::GI.LineStringTrait, v::Vector{MaPointRappa}, i::Integer) = v[i] test_display( - GI.LineString([MyPoint(1.0, 2.0), MyPoint(3.0, 4.0)]), - "LineString{false, false}([MyPoint(1.0, 2.0), MyPoint(3.0, 4.0)])", - "LineString([MyPoint(1.0,2.0),MyPoint(3.0,4.0)])" # FIXME: this should not show the point type! + GI.LineString([MaPointRappa(1.0, 2.0), MaPointRappa(3.0, 4.0)]), + "LineString{false, false}([MaPointRappa(1.0, 2.0), MaPointRappa(3.0, 4.0)])", + "LineString([MaPointRappa(1.0, 2.0),MaPointRappa(3.0, 4.0)])" # FIXME: this should not show the point type! ) end