@@ -163,8 +163,8 @@ cpdef points_from_xy(np.ndarray[double, ndim=1, cast=True] x,
163
163
@ cython.boundscheck (False )
164
164
@ cython.wraparound (False )
165
165
cpdef prepared_binary_predicate(str op,
166
- np.ndarray[np.uintp_t, ndim= 1 , cast= True ] geoms,
167
- object other):
166
+ np.ndarray[np.uintp_t, ndim= 1 , cast= True ] geoms,
167
+ object other):
168
168
"""
169
169
Apply predicate to a GeometryArray and an individual shapely object
170
170
@@ -185,6 +185,7 @@ cpdef prepared_binary_predicate(str op,
185
185
cdef Py_ssize_t idx
186
186
cdef GEOSContextHandle_t handle
187
187
cdef GEOSGeometry * geom
188
+ cdef uintptr_t other_pointer
188
189
cdef GEOSGeometry * other_geom
189
190
cdef GEOSPreparedGeometry * prepared_geom
190
191
cdef GEOSPreparedPredicate predicate
@@ -193,16 +194,10 @@ cpdef prepared_binary_predicate(str op,
193
194
cdef np.ndarray[np.uint8_t, ndim= 1 , cast= True ] out = np.empty(n, dtype = np.bool_)
194
195
195
196
handle = get_geos_context_handle()
196
- other_geom = < GEOSGeometry * > other.__geom__
197
-
198
- # Prepare the geometry if it hasn't already been prepared.
199
- # TODO: why can't we do the following instead?
200
- # prepared_geom = GEOSPrepare_r(handle, other_geom)
201
- if not isinstance (other, shapely.prepared.PreparedGeometry):
202
- other = shapely.prepared.prep(other)
197
+ other_pointer = < np.uintp_t> other.__geom__
198
+ other_geom = < GEOSGeometry * > other_pointer
203
199
204
- geos_handle = get_geos_context_handle()
205
- prepared_geom = geos_from_prepared(other)
200
+ prepared_geom = GEOSPrepare_r(handle, other_geom)
206
201
207
202
predicate = get_prepared_predicate(op)
208
203
@@ -214,8 +209,10 @@ cpdef prepared_binary_predicate(str op,
214
209
else :
215
210
out[idx] = 0
216
211
212
+ GEOSPreparedGeom_destroy_r(handle, prepared_geom)
217
213
return out
218
214
215
+
219
216
cdef GEOSPreparedPredicate get_prepared_predicate(str op) except NULL :
220
217
if op == ' contains' :
221
218
func = GEOSPreparedContains_r
@@ -413,8 +410,8 @@ cpdef unary_predicate(str op, np.ndarray[np.uintp_t, ndim=1, cast=True] geoms):
413
410
@ cython.boundscheck (False )
414
411
@ cython.wraparound (False )
415
412
cpdef binary_predicate(str op,
416
- np.ndarray[np.uintp_t, ndim= 1 , cast= True ] geoms,
417
- object other):
413
+ np.ndarray[np.uintp_t, ndim= 1 , cast= True ] geoms,
414
+ object other):
418
415
"""
419
416
Apply predicate to an array of GEOSGeometry pointers and a shapely object
420
417
0 commit comments