Skip to content

Commit

Permalink
faster context
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Jan 2, 2024
1 parent eb7e25b commit 98f1ca4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/geo_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ GeoInterface.ngeom(::AbstractPointTrait, geom::Point) = 0
GeoInterface.ngeom(::AbstractPointTrait, geom::PreparedGeometry) = 0

GI.is3d(::AbstractGeometryTrait, geom::AbstractGeometry) = hasZ(geom)
GI.getexterior(::AbstractPolygonTrait, geom::Polygon) = exteriorRing(geom)
GI.gethole(::AbstractPolygonTrait, geom::Polygon, n) = interiorRing(geom, n)

function GeoInterface.getgeom(
::AbstractGeometryCollectionTrait,
Expand All @@ -41,6 +43,7 @@ function GeoInterface.getgeom(
getGeometry(geom, i)
end
GeoInterface.getgeom(::MultiPointTrait, geom::MultiPoint, i) = getGeometry(geom, i)::Point
GeoInterface.getgeom(::MultiPointTrait, geom::MultiPoint) = getGeometry(geom, i)::Point
GeoInterface.getgeom(::MultiLineStringTrait, geom::MultiLineString, i) =
getGeometry(geom, i)::LineString
GeoInterface.getgeom(::MultiPolygonTrait, geom::MultiPolygon, i) =
Expand All @@ -51,14 +54,14 @@ function GeoInterface.getgeom(::AbstractGeometryTrait, geom::Union{LineString,Li
_get_tuple_point(geom, seq, ref, i)
end
function GeoInterface.getgeom(::AbstractGeometryTrait, geom::Union{LineString,LinearRing})
n = GeoInterface.ngeom(geom)
seq = getCoordSeq(geom::Union{LineString, LinearRing})
context = get_global_context()
seq = getCoordSeq(geom, context)
n = getSize(seq, context) # Faster thatn `GI.ngeom(geom)` when we already have `seq`
ref = Ref{Float64}()
return (_get_tuple_point(geom, seq, ref, i) for i in 1:n)
return (_get_tuple_point(geom, seq, ref, i, context) for i in 1:n)
end

function _get_tuple_point(geom, seq, ref, i)
context = get_global_context()
function _get_tuple_point(geom, seq, ref, i, context = get_global_context())
if GeoInterface.is3d(geom)
GC.@preserve ref begin
GEOSCoordSeq_getX_r(context, seq, i - 1, ref)
Expand Down

0 comments on commit 98f1ca4

Please sign in to comment.