Skip to content

Commit 75d6ef0

Browse files
authored
Merge pull request #250 from perrygeo/pre-0-16
fix shapely deprecation warnings
2 parents f41f5f3 + ade5936 commit 75d6ef0

File tree

8 files changed

+50
-19
lines changed

8 files changed

+50
-19
lines changed

CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.16.0
2+
- Fix deprecation warning with shapely 1.8+ #250
3+
14
0.15.0
25
- Fix deprecation warning with Affine #211
36
- Avoid unnecessary memory copy operation #213

src/rasterstats/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.15.0"
1+
__version__ = "0.16.0"

src/rasterstats/io.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import
33
from __future__ import division
4-
import sys
54
import json
65
import math
76
import fiona
@@ -12,29 +11,27 @@
1211
from rasterio.enums import MaskFlags
1312
from affine import Affine
1413
import numpy as np
14+
from shapely import wkt, wkb
15+
1516
try:
1617
from shapely.errors import ReadingError
17-
except:
18+
except ImportError: # pragma: no cover
1819
from shapely.geos import ReadingError
20+
1921
try:
2022
from json.decoder import JSONDecodeError
21-
except ImportError:
23+
except ImportError: # pragma: no cover
2224
JSONDecodeError = ValueError
23-
from shapely import wkt, wkb
25+
2426
try:
2527
from collections.abc import Iterable, Mapping
26-
except:
28+
except ImportError: # pragma: no cover
2729
from collections import Iterable, Mapping
2830

2931

3032
geom_types = ["Point", "LineString", "Polygon",
3133
"MultiPoint", "MultiLineString", "MultiPolygon"]
3234

33-
PY3 = sys.version_info[0] >= 3
34-
if PY3:
35-
string_types = str, # pragma: no cover
36-
else:
37-
string_types = basestring, # pragma: no cover
3835

3936
def wrap_geom(geom):
4037
""" Wraps a geometry dict in an GeoJSON Feature
@@ -85,8 +82,7 @@ def parse_feature(obj):
8582

8683
def read_features(obj, layer=0):
8784
features_iter = None
88-
89-
if isinstance(obj, string_types):
85+
if isinstance(obj, str):
9086
try:
9187
# test it as fiona data source
9288
with fiona.open(obj, 'r', layer=layer) as src:

src/rasterstats/point.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ def geom_xys(geom):
7979
geoms = [geom]
8080

8181
for g in geoms:
82-
arr = g.array_interface_base['data']
83-
for pair in zip(arr[::2], arr[1::2]):
84-
yield pair
82+
if hasattr(g, "exterior"):
83+
yield from geom_xys(g.exterior)
84+
for interior in g.interiors:
85+
yield from geom_xys(interior)
86+
else:
87+
for pair in g.coords:
88+
yield pair
8589

8690

8791
def point_query(*args, **kwargs):

tests/test_io.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
[1, 1, 1],
2424
[1, 1, 1]]])
2525

26+
eps = 1e-6
27+
2628
with fiona.open(polygons, 'r') as src:
2729
target_features = [f for f in src]
2830

@@ -31,7 +33,7 @@
3133

3234
def _compare_geomlists(aa, bb):
3335
for a, b in zip(aa, bb):
34-
assert a.almost_equals(b)
36+
assert a.equals_exact(b, eps)
3537

3638

3739
def _test_read_features(indata):
@@ -44,7 +46,7 @@ def _test_read_features(indata):
4446
def _test_read_features_single(indata):
4547
# single (first target geom)
4648
geom = shape(list(read_features(indata))[0]['geometry'])
47-
assert geom.almost_equals(target_geoms[0])
49+
assert geom.equals_exact(target_geoms[0], eps)
4850

4951

5052
def test_fiona_path():
@@ -375,3 +377,9 @@ def test_geodataframe():
375377
except ImportError:
376378
pytest.skip("Can't import geopands")
377379
assert list(read_features(df))
380+
381+
382+
# TODO # io.parse_features on a feature-only geo_interface
383+
# TODO # io.parse_features on a feature-only geojson-like object
384+
# TODO # io.read_features on a feature-only
385+
# TODO # io.Raster.read() on an open rasterio dataset

tests/test_point.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,30 @@ def test_geom_xys():
122122
Polygon, MultiPolygon)
123123
pt = Point(0, 0)
124124
assert list(geom_xys(pt)) == [(0, 0)]
125+
125126
mpt = MultiPoint([(0, 0), (1, 1)])
126127
assert list(geom_xys(mpt)) == [(0, 0), (1, 1)]
128+
127129
line = LineString([(0, 0), (1, 1)])
128130
assert list(geom_xys(line)) == [(0, 0), (1, 1)]
131+
129132
mline = MultiLineString([((0, 0), (1, 1)), ((-1, 0), (1, 0))])
130133
assert list(geom_xys(mline)) == [(0, 0), (1, 1), (-1, 0), (1, 0)]
131-
poly = Polygon([(0, 0), (1, 1), (1, 0)])
134+
135+
poly = Polygon([(0, 0), (1, 1), (1, 0), (0, 0)])
132136
assert list(geom_xys(poly)) == [(0, 0), (1, 1), (1, 0), (0, 0)]
137+
133138
ring = poly.exterior
134139
assert list(geom_xys(ring)) == [(0, 0), (1, 1), (1, 0), (0, 0)]
140+
135141
mpoly = MultiPolygon([poly, Polygon([(2, 2), (3, 3), (3, 2)])])
136142
assert list(geom_xys(mpoly)) == [(0, 0), (1, 1), (1, 0), (0, 0),
137143
(2, 2), (3, 3), (3, 2), (2, 2)]
144+
138145
mpt3d = MultiPoint([(0, 0, 1), (1, 1, 2)])
139146
assert list(geom_xys(mpt3d)) == [(0, 0), (1, 1)]
147+
148+
149+
# TODO # gen_point_query(interpolation="fake")
150+
# TODO # gen_point_query(interpolation="bilinear")
151+
# TODO # gen_point_query(<features_without_props>)

tests/test_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_get_percentile():
3333
assert get_percentile('percentile_100') == 100.0
3434
assert get_percentile('percentile_13.2') == 13.2
3535

36+
3637
def test_get_bad_percentile():
3738
with pytest.raises(ValueError):
3839
get_percentile('foo')
@@ -63,3 +64,6 @@ def test_boxify_non_point():
6364
line = LineString([(0, 0), (1, 1)])
6465
with pytest.raises(ValueError):
6566
boxify_points(line, None)
67+
68+
# TODO # def test_boxify_multi_point
69+
# TODO # def test_boxify_point

tests/test_zonal.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,7 @@ def test_geodataframe_zonal():
567567
expected = zonal_stats(polygons, raster)
568568
assert zonal_stats(df, raster) == expected
569569

570+
# TODO # gen_zonal_stats(<features_without_props>)
571+
# TODO # gen_zonal_stats(stats=nodata)
572+
# TODO # gen_zonal_stats(<raster with non-integer dtype>)
573+
# TODO # gen_zonal_stats(transform AND affine>)

0 commit comments

Comments
 (0)