From cd363a97d0ee31fcd2b81a1b110b63c77e750716 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Sat, 26 Jul 2025 00:09:06 -0400 Subject: [PATCH 1/3] Collect all LinearRingTrant to LineStringTrait --- ext/GeometryBasicsGeoInterfaceExt.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/GeometryBasicsGeoInterfaceExt.jl b/ext/GeometryBasicsGeoInterfaceExt.jl index ed5da70b..c77c46d0 100644 --- a/ext/GeometryBasicsGeoInterfaceExt.jl +++ b/ext/GeometryBasicsGeoInterfaceExt.jl @@ -34,6 +34,7 @@ geointerface_geomtype(::GeoInterface.PointTrait) = Point geointerface_geomtype(::GeoInterface.MultiPointTrait) = MultiPoint geointerface_geomtype(::GeoInterface.LineTrait) = Line geointerface_geomtype(::GeoInterface.LineStringTrait) = LineString +geointerface_geomtype(::GeoInterface.LinearRingTrait) = LineString geointerface_geomtype(::GeoInterface.MultiLineStringTrait) = MultiLineString geointerface_geomtype(::GeoInterface.PolygonTrait) = Polygon geointerface_geomtype(::GeoInterface.MultiPolygonTrait) = MultiPolygon @@ -111,7 +112,7 @@ function GeoInterface.convert(::Type{Point}, type::PointTrait, geom) return Point{2,T}(x, y) end end -function GeoInterface.convert(::Type{LineString}, type::LineStringTrait, geom) +function GeoInterface.convert(::Type{LineString}, type::Union{LineStringTrait, LinearRingTrait}, geom) g1 = getgeom(geom, 1) x, y = GeoInterface.x(g1), GeoInterface.y(g1) if GeoInterface.is3d(geom) From 773ff33eea204a6d147e850f7cfc7136c0ff7991 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Sat, 26 Jul 2025 01:22:34 -0400 Subject: [PATCH 2/3] Add Line convert method --- ext/GeometryBasicsGeoInterfaceExt.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ext/GeometryBasicsGeoInterfaceExt.jl b/ext/GeometryBasicsGeoInterfaceExt.jl index c77c46d0..38d83aef 100644 --- a/ext/GeometryBasicsGeoInterfaceExt.jl +++ b/ext/GeometryBasicsGeoInterfaceExt.jl @@ -112,6 +112,18 @@ function GeoInterface.convert(::Type{Point}, type::PointTrait, geom) return Point{2,T}(x, y) end end +function GeoInterface.convert(::Type{Line}, type::LineTrait, geom) + g1, g2 = GeoInterface.getgeom(geom) + x, y = GeoInterface.x(g1), GeoInterface.y(g1) + if GeoInterface.is3d(geom) + z = GeoInterface.z(g1) + T = promote_type(typeof(x), typeof(y), typeof(z)) + return Line{3,T}(Point{3,T}(x, y, z), Point{3,T}(GeoInterface.x(g2), GeoInterface.y(g2), GeoInterface.z(g2))) + else + T = promote_type(typeof(x), typeof(y)) + return Line{2,T}(Point{2,T}(x, y), Point{2,T}(GeoInterface.x(g2), GeoInterface.y(g2))) + end +end function GeoInterface.convert(::Type{LineString}, type::Union{LineStringTrait, LinearRingTrait}, geom) g1 = getgeom(geom, 1) x, y = GeoInterface.x(g1), GeoInterface.y(g1) From 83f41f38e094ed390f5b930e49f5e7fa2563fb7f Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Tue, 9 Jun 2026 15:59:50 -0700 Subject: [PATCH 3/3] Add tests for Line and LinearRing GeoInterface conversions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests the new GeoInterface.convert for LineTrait → Line (2D and 3D) and LinearRingTrait → LineString (2D and 3D) to improve codecov. Co-Authored-By: Claude Sonnet 4.6 --- test/geointerface.jl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/geointerface.jl b/test/geointerface.jl index b72b16d6..5f0b9e9e 100644 --- a/test/geointerface.jl +++ b/test/geointerface.jl @@ -210,3 +210,31 @@ end @test mls isa MultiLineString{2, Float64} @test length(mls) == 2 end + +@testset "Convert Line and LinearRing" begin + # Line (2D) + gi_line_2d = GeoInterface.Line([(1.0, 2.0), (3.0, 4.0)]) + line_2d = GeoInterface.convert(GeometryBasics, gi_line_2d) + @test line_2d isa Line{2, Float64} + @test line_2d[1] == Point(1.0, 2.0) + @test line_2d[2] == Point(3.0, 4.0) + + # Line (3D) + gi_line_3d = GeoInterface.Line([(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)]) + line_3d = GeoInterface.convert(GeometryBasics, gi_line_3d) + @test line_3d isa Line{3, Float64} + @test line_3d[1] == Point(1.0, 2.0, 3.0) + @test line_3d[2] == Point(4.0, 5.0, 6.0) + + # LinearRing → LineString (2D) + gi_ring = GeoInterface.LinearRing([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]) + ls_from_ring = GeoInterface.convert(GeometryBasics, gi_ring) + @test ls_from_ring isa LineString{2, Float64} + @test length(ls_from_ring) == 4 + + # LinearRing → LineString (3D) + gi_ring_3d = GeoInterface.LinearRing([(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 1.0, 0.0), (0.0, 0.0, 0.0)]) + ls_from_ring_3d = GeoInterface.convert(GeometryBasics, gi_ring_3d) + @test ls_from_ring_3d isa LineString{3, Float64} + @test length(ls_from_ring_3d) == 4 +end