Skip to content

Commit 66fafee

Browse files
authored
Merge pull request #437 from martinfleis/shapely18
REF: update for shapely 2.0
2 parents a86520c + 475967a commit 66fafee

File tree

6 files changed

+86
-73
lines changed

6 files changed

+86
-73
lines changed

libpysal/cg/alpha_shapes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def build_faces(faces, triangles_is, num_triangles, num_faces_single):
257257

258258
@jit
259259
def nb_mask_faces(mask, faces):
260-
""" Run over each row in `faces`, if the face in the following row is the
260+
"""Run over each row in `faces`, if the face in the following row is the
261261
same, then mark both as False on `mask`
262262
263263
Parameters
@@ -472,7 +472,7 @@ def alpha_shape(xys, alpha):
472472
if xys.shape[0] < 4:
473473
from shapely import ops, geometry as geom
474474

475-
return ops.cascaded_union([geom.Point(xy) for xy in xys]).convex_hull.buffer(0)
475+
return ops.unary_union([geom.Point(xy) for xy in xys]).convex_hull.buffer(0)
476476
triangulation = spat.Delaunay(xys)
477477
triangles = xys[triangulation.simplices]
478478
a_pts = triangles[:, 0, :]

libpysal/cg/shapely_ext.py

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@
5151
def to_wkb(shape):
5252
if not hasattr(shape, GEO_INTERFACE_ATTR):
5353
raise TypeError(SHAPE_TYPE_ERR % shape)
54-
o = geom.asShape(shape)
54+
o = geom.shape(shape)
5555
return o.to_wkb()
5656

5757

5858
def to_wkt(shape):
5959
if not hasattr(shape, GEO_INTERFACE_ATTR):
6060
raise TypeError(SHAPE_TYPE_ERR % shape)
61-
o = geom.asShape(shape)
61+
o = geom.shape(shape)
6262
return o.to_wkt()
6363

6464

@@ -67,7 +67,7 @@ def to_wkt(shape):
6767
def area(shape):
6868
if not hasattr(shape, GEO_INTERFACE_ATTR):
6969
raise TypeError(SHAPE_TYPE_ERR % shape)
70-
o = geom.asShape(shape)
70+
o = geom.shape(shape)
7171
return o.area
7272

7373

@@ -76,15 +76,15 @@ def distance(shape, other):
7676
raise TypeError(SHAPE_TYPE_ERR % shape)
7777
if not hasattr(other, GEO_INTERFACE_ATTR):
7878
raise TypeError(SHAPE_TYPE_ERR % shape)
79-
o = geom.asShape(shape)
80-
o2 = geom.asShape(other)
79+
o = geom.shape(shape)
80+
o2 = geom.shape(other)
8181
return o.distance(o2)
8282

8383

8484
def length(shape):
8585
if not hasattr(shape, GEO_INTERFACE_ATTR):
8686
raise TypeError(SHAPE_TYPE_ERR % shape)
87-
o = geom.asShape(shape)
87+
o = geom.shape(shape)
8888
return o.length
8989

9090

@@ -93,62 +93,62 @@ def length(shape):
9393
def boundary(shape):
9494
if not hasattr(shape, GEO_INTERFACE_ATTR):
9595
raise TypeError(SHAPE_TYPE_ERR % shape)
96-
o = geom.asShape(shape)
96+
o = geom.shape(shape)
9797
res = o.boundary
9898
return asShape(res)
9999

100100

101101
def bounds(shape):
102102
if not hasattr(shape, GEO_INTERFACE_ATTR):
103103
raise TypeError(SHAPE_TYPE_ERR % shape)
104-
o = geom.asShape(shape)
104+
o = geom.shape(shape)
105105
return o.bounds
106106

107107

108108
def centroid(shape):
109109
if not hasattr(shape, GEO_INTERFACE_ATTR):
110110
raise TypeError(SHAPE_TYPE_ERR % shape)
111-
o = geom.asShape(shape)
111+
o = geom.shape(shape)
112112
res = o.centroid
113113
return asShape(res)
114114

115115

116116
def representative_point(shape):
117117
if not hasattr(shape, GEO_INTERFACE_ATTR):
118118
raise TypeError(SHAPE_TYPE_ERR % shape)
119-
o = geom.asShape(shape)
119+
o = geom.shape(shape)
120120
res = o.representative_point()
121121
return asShape(res)
122122

123123

124124
def convex_hull(shape):
125125
if not hasattr(shape, GEO_INTERFACE_ATTR):
126126
raise TypeError(SHAPE_TYPE_ERR % shape)
127-
o = geom.asShape(shape)
127+
o = geom.shape(shape)
128128
res = o.convex_hull
129129
return asShape(res)
130130

131131

132132
def envelope(shape):
133133
if not hasattr(shape, GEO_INTERFACE_ATTR):
134134
raise TypeError(SHAPE_TYPE_ERR % shape)
135-
o = geom.asShape(shape)
135+
o = geom.shape(shape)
136136
res = o.envelope
137137
return asShape(res)
138138

139139

140140
def buffer(shape, radius, resolution=16):
141141
if not hasattr(shape, GEO_INTERFACE_ATTR):
142142
raise TypeError(SHAPE_TYPE_ERR % shape)
143-
o = geom.asShape(shape)
143+
o = geom.shape(shape)
144144
res = o.buffer(radius, resolution)
145145
return asShape(res)
146146

147147

148148
def simplify(shape, tolerance, preserve_topology=True):
149149
if not hasattr(shape, GEO_INTERFACE_ATTR):
150150
raise TypeError(SHAPE_TYPE_ERR % shape)
151-
o = geom.asShape(shape)
151+
o = geom.shape(shape)
152152
res = o.simplify(tolerance, preserve_topology)
153153
return asShape(res)
154154

@@ -160,8 +160,8 @@ def difference(shape, other):
160160
raise TypeError(SHAPE_TYPE_ERR % shape)
161161
if not hasattr(other, GEO_INTERFACE_ATTR):
162162
raise TypeError(SHAPE_TYPE_ERR % shape)
163-
o = geom.asShape(shape)
164-
o2 = geom.asShape(other)
163+
o = geom.shape(shape)
164+
o2 = geom.shape(other)
165165
res = o.difference(o2)
166166
return asShape(res)
167167

@@ -171,8 +171,8 @@ def intersection(shape, other):
171171
raise TypeError(SHAPE_TYPE_ERR % shape)
172172
if not hasattr(other, GEO_INTERFACE_ATTR):
173173
raise TypeError(SHAPE_TYPE_ERR % shape)
174-
o = geom.asShape(shape)
175-
o2 = geom.asShape(other)
174+
o = geom.shape(shape)
175+
o2 = geom.shape(other)
176176
res = o.intersection(o2)
177177
return asShape(res)
178178

@@ -182,8 +182,8 @@ def symmetric_difference(shape, other):
182182
raise TypeError(SHAPE_TYPE_ERR % shape)
183183
if not hasattr(other, GEO_INTERFACE_ATTR):
184184
raise TypeError(SHAPE_TYPE_ERR % shape)
185-
o = geom.asShape(shape)
186-
o2 = geom.asShape(other)
185+
o = geom.shape(shape)
186+
o2 = geom.shape(other)
187187
res = o.symmetric_difference(o2)
188188
return asShape(res)
189189

@@ -193,8 +193,8 @@ def union(shape, other):
193193
raise TypeError(SHAPE_TYPE_ERR % shape)
194194
if not hasattr(other, GEO_INTERFACE_ATTR):
195195
raise TypeError(SHAPE_TYPE_ERR % shape)
196-
o = geom.asShape(shape)
197-
o2 = geom.asShape(other)
196+
o = geom.shape(shape)
197+
o2 = geom.shape(other)
198198
res = o.union(o2)
199199
return asShape(res)
200200

@@ -204,8 +204,8 @@ def cascaded_union(shapes):
204204
for shape in shapes:
205205
if not hasattr(shape, GEO_INTERFACE_ATTR):
206206
raise TypeError(SHAPE_TYPE_ERR % shape)
207-
o.append(geom.asShape(shape))
208-
res = shops.cascaded_union(o)
207+
o.append(geom.shape(shape))
208+
res = shops.unary_union(o)
209209
return asShape(res)
210210

211211

@@ -219,7 +219,7 @@ def unary_union(shapes):
219219
for shape in shapes:
220220
if not hasattr(shape, GEO_INTERFACE_ATTR):
221221
raise TypeError(SHAPE_TYPE_ERR % shape)
222-
o.append(geom.asShape(shape))
222+
o.append(geom.shape(shape))
223223
res = shops.unary_union(o)
224224
return asShape(res)
225225

@@ -229,35 +229,35 @@ def unary_union(shapes):
229229
def has_z(shape):
230230
if not hasattr(shape, GEO_INTERFACE_ATTR):
231231
raise TypeError(SHAPE_TYPE_ERR % shape)
232-
o = geom.asShape(shape)
232+
o = geom.shape(shape)
233233
return o.has_z
234234

235235

236236
def is_empty(shape):
237237
if not hasattr(shape, GEO_INTERFACE_ATTR):
238238
raise TypeError(SHAPE_TYPE_ERR % shape)
239-
o = geom.asShape(shape)
239+
o = geom.shape(shape)
240240
return o.is_empty
241241

242242

243243
def is_ring(shape):
244244
if not hasattr(shape, GEO_INTERFACE_ATTR):
245245
raise TypeError(SHAPE_TYPE_ERR % shape)
246-
o = geom.asShape(shape)
246+
o = geom.shape(shape)
247247
return o.is_ring
248248

249249

250250
def is_simple(shape):
251251
if not hasattr(shape, GEO_INTERFACE_ATTR):
252252
raise TypeError(SHAPE_TYPE_ERR % shape)
253-
o = geom.asShape(shape)
253+
o = geom.shape(shape)
254254
return o.is_simple
255255

256256

257257
def is_valid(shape):
258258
if not hasattr(shape, GEO_INTERFACE_ATTR):
259259
raise TypeError(SHAPE_TYPE_ERR % shape)
260-
o = geom.asShape(shape)
260+
o = geom.shape(shape)
261261
return o.is_valid
262262

263263

@@ -268,8 +268,8 @@ def relate(shape, other):
268268
raise TypeError(SHAPE_TYPE_ERR % shape)
269269
if not hasattr(other, GEO_INTERFACE_ATTR):
270270
raise TypeError(SHAPE_TYPE_ERR % shape)
271-
o = geom.asShape(shape)
272-
o2 = geom.asShape(other)
271+
o = geom.shape(shape)
272+
o2 = geom.shape(other)
273273
return o.relate(o2)
274274

275275

@@ -278,8 +278,8 @@ def contains(shape, other):
278278
raise TypeError(SHAPE_TYPE_ERR % shape)
279279
if not hasattr(other, GEO_INTERFACE_ATTR):
280280
raise TypeError(SHAPE_TYPE_ERR % shape)
281-
o = geom.asShape(shape)
282-
o2 = geom.asShape(other)
281+
o = geom.shape(shape)
282+
o2 = geom.shape(other)
283283
return o.contains(o2)
284284

285285

@@ -288,8 +288,8 @@ def crosses(shape, other):
288288
raise TypeError(SHAPE_TYPE_ERR % shape)
289289
if not hasattr(other, GEO_INTERFACE_ATTR):
290290
raise TypeError(SHAPE_TYPE_ERR % shape)
291-
o = geom.asShape(shape)
292-
o2 = geom.asShape(other)
291+
o = geom.shape(shape)
292+
o2 = geom.shape(other)
293293
return o.crosses(o2)
294294

295295

@@ -298,8 +298,8 @@ def disjoint(shape, other):
298298
raise TypeError(SHAPE_TYPE_ERR % shape)
299299
if not hasattr(other, GEO_INTERFACE_ATTR):
300300
raise TypeError(SHAPE_TYPE_ERR % shape)
301-
o = geom.asShape(shape)
302-
o2 = geom.asShape(other)
301+
o = geom.shape(shape)
302+
o2 = geom.shape(other)
303303
return o.disjoint(o2)
304304

305305

@@ -308,8 +308,8 @@ def equals(shape, other):
308308
raise TypeError(SHAPE_TYPE_ERR % shape)
309309
if not hasattr(other, GEO_INTERFACE_ATTR):
310310
raise TypeError(SHAPE_TYPE_ERR % shape)
311-
o = geom.asShape(shape)
312-
o2 = geom.asShape(other)
311+
o = geom.shape(shape)
312+
o2 = geom.shape(other)
313313
return o.equals(o2)
314314

315315

@@ -318,8 +318,8 @@ def intersects(shape, other):
318318
raise TypeError(SHAPE_TYPE_ERR % shape)
319319
if not hasattr(other, GEO_INTERFACE_ATTR):
320320
raise TypeError(SHAPE_TYPE_ERR % shape)
321-
o = geom.asShape(shape)
322-
o2 = geom.asShape(other)
321+
o = geom.shape(shape)
322+
o2 = geom.shape(other)
323323
return o.intersects(o2)
324324

325325

@@ -328,8 +328,8 @@ def overlaps(shape, other):
328328
raise TypeError(SHAPE_TYPE_ERR % shape)
329329
if not hasattr(other, GEO_INTERFACE_ATTR):
330330
raise TypeError(SHAPE_TYPE_ERR % shape)
331-
o = geom.asShape(shape)
332-
o2 = geom.asShape(other)
331+
o = geom.shape(shape)
332+
o2 = geom.shape(other)
333333
return o.overlaps(o2)
334334

335335

@@ -338,8 +338,8 @@ def touches(shape, other):
338338
raise TypeError(SHAPE_TYPE_ERR % shape)
339339
if not hasattr(other, GEO_INTERFACE_ATTR):
340340
raise TypeError(SHAPE_TYPE_ERR % shape)
341-
o = geom.asShape(shape)
342-
o2 = geom.asShape(other)
341+
o = geom.shape(shape)
342+
o2 = geom.shape(other)
343343
return o.touches(o2)
344344

345345

@@ -348,8 +348,8 @@ def within(shape, other):
348348
raise TypeError(SHAPE_TYPE_ERR % shape)
349349
if not hasattr(other, GEO_INTERFACE_ATTR):
350350
raise TypeError(SHAPE_TYPE_ERR % shape)
351-
o = geom.asShape(shape)
352-
o2 = geom.asShape(other)
351+
o = geom.shape(shape)
352+
o2 = geom.shape(other)
353353
return o.within(o2)
354354

355355

@@ -358,8 +358,8 @@ def equals_exact(shape, other, tolerance):
358358
raise TypeError(SHAPE_TYPE_ERR % shape)
359359
if not hasattr(other, GEO_INTERFACE_ATTR):
360360
raise TypeError(SHAPE_TYPE_ERR % shape)
361-
o = geom.asShape(shape)
362-
o2 = geom.asShape(other)
361+
o = geom.shape(shape)
362+
o2 = geom.shape(other)
363363
return o.equals_exact(o2, tolerance)
364364

365365

@@ -368,8 +368,8 @@ def almost_equals(shape, other, decimal=6):
368368
raise TypeError(SHAPE_TYPE_ERR % shape)
369369
if not hasattr(other, GEO_INTERFACE_ATTR):
370370
raise TypeError(SHAPE_TYPE_ERR % shape)
371-
o = geom.asShape(shape)
372-
o2 = geom.asShape(other)
371+
o = geom.shape(shape)
372+
o2 = geom.shape(other)
373373
return o.almost_equals(o2, decimal)
374374

375375

@@ -380,15 +380,15 @@ def project(shape, other, normalized=False):
380380
raise TypeError(SHAPE_TYPE_ERR % shape)
381381
if not hasattr(other, GEO_INTERFACE_ATTR):
382382
raise TypeError(SHAPE_TYPE_ERR % shape)
383-
o = geom.asShape(shape)
384-
o2 = geom.asShape(other)
383+
o = geom.shape(shape)
384+
o2 = geom.shape(other)
385385
return o.project(o2, normalized)
386386

387387

388388
def interpolate(shape, distance, normalized=False):
389389
if not hasattr(shape, GEO_INTERFACE_ATTR):
390390
raise TypeError(SHAPE_TYPE_ERR % shape)
391-
o = geom.asShape(shape)
391+
o = geom.shape(shape)
392392
res = o.interpolate(distance, normalized)
393393
return asShape(res)
394394

0 commit comments

Comments
 (0)