Skip to content

Commit 773ff33

Browse files
committed
Add Line convert method
1 parent cd363a9 commit 773ff33

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ext/GeometryBasicsGeoInterfaceExt.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ function GeoInterface.convert(::Type{Point}, type::PointTrait, geom)
112112
return Point{2,T}(x, y)
113113
end
114114
end
115+
function GeoInterface.convert(::Type{Line}, type::LineTrait, geom)
116+
g1, g2 = GeoInterface.getgeom(geom)
117+
x, y = GeoInterface.x(g1), GeoInterface.y(g1)
118+
if GeoInterface.is3d(geom)
119+
z = GeoInterface.z(g1)
120+
T = promote_type(typeof(x), typeof(y), typeof(z))
121+
return Line{3,T}(Point{3,T}(x, y, z), Point{3,T}(GeoInterface.x(g2), GeoInterface.y(g2), GeoInterface.z(g2)))
122+
else
123+
T = promote_type(typeof(x), typeof(y))
124+
return Line{2,T}(Point{2,T}(x, y), Point{2,T}(GeoInterface.x(g2), GeoInterface.y(g2)))
125+
end
126+
end
115127
function GeoInterface.convert(::Type{LineString}, type::Union{LineStringTrait, LinearRingTrait}, geom)
116128
g1 = getgeom(geom, 1)
117129
x, y = GeoInterface.x(g1), GeoInterface.y(g1)

0 commit comments

Comments
 (0)