@@ -2,11 +2,12 @@ abstract type AbstractGeometry end
22
33mutable struct Point <: AbstractGeometry
44 ptr:: GEOSGeom
5+ context:: GEOSContext
56 # create a point from a pointer - only makese sense if it is a pointer to a point, otherwise error
67 function Point (ptr:: GEOSGeom , context:: GEOSContext = _context)
78 id = LibGEOS. geomTypeId (ptr, context)
89 point = if id == GEOS_POINT
9- point = new (cloneGeom (ptr, context))
10+ point = new (cloneGeom (ptr, context), context )
1011 else
1112 error (" LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a point (yet).
1213 Please open an issue if you think this conversion makes sense." )
2526
2627mutable struct MultiPoint <: AbstractGeometry
2728 ptr:: GEOSGeom
29+ context:: GEOSContext
2830 # create a multipoint from a pointer - only makes sense if it is a pointer to a multipoint
2931 # or to a point, otherwise error
3032 function MultiPoint (ptr:: GEOSGeom , context:: GEOSContext = _context)
3133 id = LibGEOS. geomTypeId (ptr, context)
3234 multipoint = if id == GEOS_MULTIPOINT
33- new (cloneGeom (ptr, context))
35+ new (cloneGeom (ptr, context), context )
3436 elseif id == GEOS_POINT
3537 new (createCollection (GEOS_MULTIPOINT,
3638 GEOSGeom[cloneGeom (ptr, context)],
37- context))
39+ context),
40+ context
41+ )
3842 else
3943 error (" LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a multipoint (yet).
4044 Please open an issue if you think this conversion makes sense." )
6266
6367mutable struct LineString <: AbstractGeometry
6468 ptr:: GEOSGeom
69+ context:: GEOSContext
6570 # create a linestring from a linestring pointer, otherwise error
6671 function LineString (ptr:: GEOSGeom , context:: GEOSContext = _context)
6772 id = LibGEOS. geomTypeId (ptr, context)
6873 line = if id == GEOS_LINESTRING
69- new (cloneGeom (ptr, context))
74+ new (cloneGeom (ptr, context), context )
7075 else
7176 error (" LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a linestring (yet).
7277 Please open an issue if you think this conversion makes sense." )
@@ -76,23 +81,24 @@ mutable struct LineString <: AbstractGeometry
7681 end
7782 # create a linestring from a list of coordiantes
7883 function LineString (coords:: Vector{Vector{Float64}} , context:: GEOSContext = _context)
79- line = new (createLineString (coords, context))
84+ line = new (createLineString (coords, context), context )
8085 finalizer (destroyGeom, line)
8186 line
8287 end
8388end
8489
8590mutable struct MultiLineString <: AbstractGeometry
8691 ptr:: GEOSGeom
92+ context:: GEOSContext
8793 # create a multiline string from a multilinestring or a linestring pointer, else error
8894 function MultiLineString (ptr:: GEOSGeom , context:: GEOSContext = _context)
8995 id = LibGEOS. geomTypeId (ptr, context)
9096 multiline = if id == GEOS_MULTILINESTRING
91- new (cloneGeom (ptr, context))
97+ new (cloneGeom (ptr, context), context )
9298 elseif id == GEOS_LINESTRING
9399 new (createCollection (GEOS_MULTILINESTRING,
94100 GEOSGeom[cloneGeom (ptr, context)],
95- context))
101+ context), context )
96102 else
97103 error (" LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a multi-linestring (yet).
98104 Please open an issue if you think this conversion makes sense." )
@@ -112,11 +118,12 @@ end
112118
113119mutable struct LinearRing <: AbstractGeometry
114120 ptr:: GEOSGeom
121+ context:: GEOSContext
115122 # create a linear ring from a linear ring pointer, otherwise error
116123 function LinearRing (ptr:: GEOSGeom , context:: GEOSContext = _context)
117124 id = LibGEOS. geomTypeId (ptr, context)
118125 ring = if id == GEOS_LINEARRING
119- new (cloneGeom (ptr, context))
126+ new (cloneGeom (ptr, context), context )
120127 else
121128 error (" LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a linear ring (yet).
122129 Please open an issue if you think this conversion makes sense." )
@@ -127,7 +134,7 @@ mutable struct LinearRing <: AbstractGeometry
127134 # create linear ring from a list of coordinates -
128135 # first and last coordinates must be the same
129136 function LinearRing (coords:: Vector{Vector{Float64}} , context:: GEOSContext = _context)
130- ring = new (createLinearRing (coords, context))
137+ ring = new (createLinearRing (coords, context), context )
131138 finalizer (destroyGeom, ring)
132139 ring
133140 end
@@ -136,13 +143,14 @@ end
136143
137144mutable struct Polygon <: AbstractGeometry
138145 ptr:: GEOSGeom
146+ context:: GEOSContext
139147 # create polygon using GEOSGeom pointer - only makes sense if pointer points to a polygon or a linear ring to start with.
140148 function Polygon (ptr:: GEOSGeom , context:: GEOSContext = _context)
141149 id = LibGEOS. geomTypeId (ptr, context)
142150 polygon = if id == GEOS_POLYGON
143- new (cloneGeom (ptr, context))
151+ new (cloneGeom (ptr, context), context )
144152 elseif id == GEOS_LINEARRING
145- new (cloneGeom (createPolygon (ptr, context), context))
153+ new (cloneGeom (createPolygon (ptr, context), context), context )
146154 else
147155 error (" LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a polygon (yet).
148156 Please open an issue if you think this conversion makes sense." )
@@ -155,7 +163,7 @@ mutable struct Polygon <: AbstractGeometry
155163 function Polygon (coords:: Vector{Vector{Vector{Float64}}} , context:: GEOSContext = _context)
156164 exterior = createLinearRing (coords[1 ], context)
157165 interiors = GEOSGeom[createLinearRing (lr, context) for lr in coords[2 : end ]]
158- polygon = new (createPolygon (exterior, interiors, context))
166+ polygon = new (createPolygon (exterior, interiors, context), context )
159167 finalizer (destroyGeom, polygon)
160168 polygon
161169 end
@@ -173,16 +181,19 @@ end
173181
174182mutable struct MultiPolygon <: AbstractGeometry
175183 ptr:: GEOSGeom
184+ context:: GEOSContext
176185 # create multipolygon using a multipolygon or polygon pointer, else error
177186 function MultiPolygon (ptr:: GEOSGeom , context:: GEOSContext = _context)
178187 id = LibGEOS. geomTypeId (ptr, context)
179188 multipolygon = if id == GEOS_MULTIPOLYGON
180- new (cloneGeom (ptr, context))
189+ new (cloneGeom (ptr, context), context )
181190 elseif id == GEOS_POLYGON
182191 new (createCollection (
183192 GEOS_MULTIPOLYGON,
184193 GEOSGeom[cloneGeom (ptr, context)],
185- context))
194+ context),
195+ context
196+ )
186197 else
187198 error (" LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a multi-polygon (yet).
188199 Please open an issue if you think this conversion makes sense." )
@@ -217,11 +228,12 @@ end
217228
218229mutable struct GeometryCollection <: AbstractGeometry
219230 ptr:: GEOSGeom
231+ context:: GEOSContext
220232 # create a geometric collection from a pointer to a geometric collection, else error
221233 function GeometryCollection (ptr:: GEOSGeom , context:: GEOSContext = _context)
222234 id = LibGEOS. geomTypeId (ptr, context)
223235 geometrycollection = if id == GEOS_GEOMETRYCOLLECTION
224- new (cloneGeom (ptr, context))
236+ new (cloneGeom (ptr, context), context )
225237 else
226238 error (" LibGEOS: Can't convert a pointer to an element with a GeomType ID of $id to a geometry collection (yet).
227239 Please open an issue if you think this conversion makes sense." )
@@ -250,7 +262,9 @@ const Geometry = Union{
250262 GeometryCollection,
251263}
252264
253- function destroyGeom (obj:: Geometry , context:: GEOSContext = _context)
265+ get_context (obj:: Geometry ) = obj. context
266+ function destroyGeom (obj:: Geometry )
267+ context = get_context (obj)
254268 destroyGeom (obj. ptr, context)
255269 obj. ptr = C_NULL
256270end
@@ -260,7 +274,10 @@ mutable struct PreparedGeometry{G<:AbstractGeometry} <: AbstractGeometry
260274 ownedby:: G
261275end
262276
263- function destroyGeom (obj:: PreparedGeometry , context:: GEOSContext = _context)
277+ get_context (obj:: PreparedGeometry ) = get_context (obj. ownedby)
278+
279+ function destroyGeom (obj:: PreparedGeometry )
280+ context = get_context (obj)
264281 destroyPreparedGeom (obj. ptr, context)
265282 obj. ptr = C_NULL
266283end
0 commit comments