@@ -47,11 +47,33 @@ GeoInterface.getgeom(::MultiLineStringTrait, geom::MultiLineString, i) =
4747 getGeometry (geom, i):: LineString
4848GeoInterface. getgeom (:: MultiPolygonTrait , geom:: MultiPolygon , i) =
4949 getGeometry (geom, i):: Polygon
50- GeoInterface. getgeom (
51- :: Union{LineStringTrait,LinearRingTrait} ,
52- geom:: Union{LineString,LinearRing} ,
53- i,
54- ) = getPoint (geom, i)
50+ function GeoInterface. getgeom (:: AbstractGeometryTrait , geom:: Union{LineString,LinearRing} , i)
51+ refs = Ref {Float64} (), Ref {Float64} (), Ref {Float64} () # 3 Refs is faster than a Vector
52+ seq = getCoordSeq (geom:: Union{LineString, LinearRing} )
53+ return _get_tuple_point (geom, seq, refs, i)
54+ end
55+ function GeoInterface. getgeom (:: AbstractGeometryTrait , geom:: Union{LineString,LinearRing} )
56+ context = get_context (geom)
57+ seq = getCoordSeq (geom, context)
58+ n = getSize (seq, context) # Faster thatn `GI.ngeom(geom)` when we already have `seq`
59+ # Preallocate refse
60+ refs = Ref {Float64} (), Ref {Float64} (), Ref {Float64} ()
61+ # Pretetermin if there is a z coordinate
62+ hasz = hasZ (geom, context)
63+ # We specify Unit32 in the generator to avoid unnecesary conversion later
64+ return (_get_tuple_point (geom, seq, refs, i, context, hasz) for i in UInt32 (1 ): UInt32 (n))
65+ end
66+
67+ function _get_tuple_point (geom, seq, (x, y, z), i, context= get_context (geom), hasz= hasZ (geom, context))
68+ if hasz
69+ GEOSCoordSeq_getXYZ_r (context, seq, i - UInt32 (1 ), x, y, z)
70+ return x[], y[], Z[]
71+ else
72+ GEOSCoordSeq_getXY_r (context, seq, i - UInt32 (1 ), x, y)
73+ return x[], y[]
74+ end
75+ end
76+
5577GeoInterface. getgeom (t:: AbstractPointTrait , geom:: PreparedGeometry ) = nothing
5678function GeoInterface. getgeom (:: PolygonTrait , geom:: Polygon , i:: Int )
5779 if i == 1
0 commit comments