Skip to content

Commit 5491a72

Browse files
committed
improve GeoInterface conversion performance
1 parent e9c83ec commit 5491a72

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/geointerface.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ function GeoInterface.convert(::Type{Point}, type::PointTrait, geom)
105105
end
106106
end
107107

108+
# without a function barrier you get a lot of allocations from runtime types
109+
function _collect_with_type(::Type{PT}, geom) where {PT <: Point{2}}
110+
return [PT(GeoInterface.x(p), GeoInterface.y(p)) for p in getgeom(geom)]
111+
end
112+
108113
function GeoInterface.convert(::Type{LineString}, type::LineStringTrait, geom)
109114
g1 = getgeom(geom, 1)
110115
x, y = GeoInterface.x(g1), GeoInterface.y(g1)
@@ -114,7 +119,7 @@ function GeoInterface.convert(::Type{LineString}, type::LineStringTrait, geom)
114119
return LineString([Point{3,T}(GeoInterface.x(p), GeoInterface.y(p), GeoInterface.z(p)) for p in getgeom(geom)])
115120
else
116121
T = promote_type(typeof(x), typeof(y))
117-
return LineString([Point{2,T}(GeoInterface.x(p), GeoInterface.y(p)) for p in getgeom(geom)])
122+
return LineString(_collect_with_type(Point{2, T}, geom))
118123
end
119124
end
120125

0 commit comments

Comments
 (0)