perrygeo/python-rasterstats

array_interface_base incompatibility with Shapely 1.8.0

fitnr opened this issue · 0 comments

fitnr commented

Describe the bug

When running gen_point_query with Shapely 1.8.0 installed, rasterstats throws a TypeError when trying to use array_interface_base. This error doesn't occur with Shapely 1.7.1.

The error looks like this:

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/rasterstats/point.py:84: ShapelyDeprecationWarning: The 'array_interface_base' property is deprecated and will be removed in Shapely 2.0.
  arr = g.array_interface_base['data']
Traceback (most recent call last):
  File "query.py", line 5, in <module>
    result = point_query(feature, 'sample.tiff')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/rasterstats/point.py", line 97, in point_query
    return list(gen_point_query(*args, **kwargs))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/rasterstats/point.py", line 172, in gen_point_query
    for x, y in geom_xys(geom):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/rasterstats/point.py", line 84, in geom_xys
    arr = g.array_interface_base['data']
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/shapely/geometry/base.py", line 326, in array_interface_base
    return self._array_interface_base()
TypeError: 'dict' object is not callable

To Reproduce

  1. How did you install rasterstats and its dependencies?

Bug was encountered when running in a Docker image built from osgeo/gdal:ubuntu-small-latest. Rasterstats was installed with pip, but without specifying a version requirement for Shapely. I have reproduced on MacOS, where GDAL was installed with homebrew, and python packages installed with pip. I can produce the error in both Python 3.7 and 3.8

  1. What datasets are necessary to reproduce the bug?

The error can produced by the script below, where sample.tiff is created with:

gdal_create -burn 1 -ot byte -of GTiff -a_srs EPSG:4236 -a_ullr 0 1 1 0 -outsize 1 1 -a_nodata 0 sample.tiff
  1. What code is necessary to reproduce the bug?

I encountered the error when opening geodata files with Fiona, this minimal example will produce the exception:

from rasterstats import point_query
import shapely.geometry

feature = shapely.geometry.Point(0.5, 0.5)
result = point_query(feature, 'sample.tiff')
print([x for x in result])

Running with Shapely==1.8.0 gives the above error. Running with Shapely==1.7.1 gives the (correct) result: [1].