Skip to content

Commit 7ea504e

Browse files
authored
Fix shapely deprecation warnings (#85)
* Fix shapely deprecation warnings * Minor changes
1 parent b6809e7 commit 7ea504e

File tree

12 files changed

+22
-19
lines changed

12 files changed

+22
-19
lines changed
File renamed without changes.
File renamed without changes.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'codecov',
88
'flake8',
99
'hilbertcurve',
10-
'geopandas-base',
10+
'geopandas',
1111
'hypothesis',
1212
'pytest-cov',
1313
'pytest',

spatialpandas/geometry/basefixed.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ def invalid_array():
146146
pass
147147
elif isinstance(el, GeometryFixed):
148148
array[i] = el.flat_values.tobytes()
149-
else:
149+
elif isinstance(el, list) or isinstance(el, np.ndarray):
150150
array[i] = np.asarray(el, dtype=numpy_dtype).tobytes()
151+
else:
152+
array[i] = np.asarray(el.coords, dtype=numpy_dtype).tobytes()
151153
else:
152154
if dtype:
153155
array = array.astype(dtype)

spatialpandas/geometry/line.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _shapely_to_coordinates(cls, shape):
3030
import shapely.geometry as sg
3131
if isinstance(shape, (sg.LineString, sg.LinearRing)):
3232
# Single line
33-
return np.asarray(shape.ctypes)
33+
return np.asarray(shape.coords).ravel()
3434
else:
3535
raise ValueError("""
3636
Received invalid value of type {typ}. Must be an instance of LineString

spatialpandas/geometry/multiline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ def construct_array_type(cls):
3131
def _shapely_to_coordinates(cls, shape):
3232
import shapely.geometry as sg
3333
if isinstance(shape, sg.MultiLineString):
34-
shape = list(shape)
34+
shape = shape.geoms
3535
line_parts = []
3636
if len(shape) == 0:
3737
# Add single empty line so we have the right number of nested levels
3838
line_parts.append([])
3939
else:
4040
for line in shape:
41-
line_parts.append(np.asarray(line.ctypes))
41+
line_parts.append(np.asarray(line.coords).ravel())
4242
return line_parts
4343
elif isinstance(shape, (sg.LineString, sg.LinearRing)):
44-
return [np.asarray(shape.ctypes)]
44+
return [np.asarray(shape.coords).ravel()]
4545
else:
4646
raise ValueError("""
4747
Received invalid value of type {typ}. Must be an instance of MultiLineString

spatialpandas/geometry/multipoint.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ def construct_array_type(cls):
2727
@classmethod
2828
def _shapely_to_coordinates(cls, shape):
2929
import shapely.geometry as sg
30-
if isinstance(shape, (sg.Point, sg.MultiPoint)):
31-
# Single line
32-
return np.asarray(shape.ctypes)
30+
if isinstance(shape, sg.Point):
31+
return np.asarray(shape.coords).ravel()
32+
elif isinstance(shape, sg.MultiPoint):
33+
return np.hstack([g.coords for g in shape.geoms]).ravel()
3334
else:
3435
raise ValueError("""
3536
Received invalid value of type {typ}. Must be an instance of Point,

spatialpandas/geometry/multipolygon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _shapely_to_coordinates(cls, shape):
3939
import shapely.geometry as sg
4040
if isinstance(shape, sg.MultiPolygon):
4141
multipolygon = []
42-
for polygon in shape:
42+
for polygon in shape.geoms:
4343
polygon_coords = Polygon._shapely_to_coordinates(polygon)
4444
multipolygon.append(polygon_coords)
4545

@@ -93,7 +93,7 @@ def from_shapely(cls, shape, orient=True):
9393
if isinstance(shape, sg.Polygon):
9494
shape = sg.polygon.orient(shape)
9595
elif isinstance(shape, sg.MultiPolygon):
96-
shape = sg.MultiPolygon([sg.polygon.orient(poly) for poly in shape])
96+
shape = sg.MultiPolygon([sg.polygon.orient(poly) for poly in shape.geoms])
9797

9898
shape_parts = cls._shapely_to_coordinates(shape)
9999
return cls(shape_parts)

spatialpandas/geometry/point.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _shapely_to_coordinates(cls, shape):
2828
import shapely.geometry as sg
2929
if isinstance(shape, sg.Point):
3030
# Single point
31-
return np.asarray(shape.ctypes)
31+
return np.asarray(shape.coords).ravel()
3232
else:
3333
raise ValueError("""
3434
Received invalid value of type {typ}. Must be an instance of Point,

spatialpandas/geometry/polygon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def _shapely_to_coordinates(cls, shape):
3838
import shapely.geometry as sg
3939
if isinstance(shape, sg.Polygon):
4040
if shape.exterior is not None:
41-
exterior = np.asarray(shape.exterior.ctypes)
41+
exterior = np.asarray(shape.exterior.coords).ravel()
4242
polygon_coords = [exterior]
4343
else:
4444
polygon_coords = [np.array([])]
4545
for ring in shape.interiors:
46-
interior = np.asarray(ring.ctypes)
46+
interior = np.asarray(ring.coords).ravel()
4747
polygon_coords.append(interior)
4848

4949
return polygon_coords

0 commit comments

Comments
 (0)