Skip to content

Example B19730_04_14-shapely.py broken #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
RyanBurnside opened this issue Apr 30, 2025 · 1 comment
Open

Example B19730_04_14-shapely.py broken #3

RyanBurnside opened this issue Apr 30, 2025 · 1 comment

Comments

@RyanBurnside
Copy link

Hello, when running the example B19730_04_14-shapely.py there is an error that lib.to_wkt()
can only be called with ndarray object.

I first cat the file's contents so you can see it's not tampered with.

Error trace below:

(lgawp4) ryan@ryan-laptop:~/Desktop/GIS/Learning-Geospatial-Analysis-with-Python-Fourth-Edition/B19730_04_Asset_Files$ cat B19730_04_14-shapely.py 
import shapely.wkt
wktPoly = "POLYGON((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))"
poly = shapely.wkt.loads(wktPoly)
print(poly.area)
print(poly.wkt)
(lgawp4) ryan@ryan-laptop:~/Desktop/GIS/Learning-Geospatial-Analysis-with-Python-Fourth-Edition/B19730_04_Asset_Files$ python B19730_04_14-shapely.py 
15.0
Traceback (most recent call last):
  File "/home/ryan/Desktop/GIS/Learning-Geospatial-Analysis-with-Python-Fourth-Edition/B19730_04_Asset_Files/B19730_04_14-shapely.py", line 5, in <module>
    print(poly.wkt)
  File "/home/ryan/miniconda3/envs/lgawp4/lib/python3.10/site-packages/shapely/geometry/base.py", line 275, in wkt
    return shapely.to_wkt(self, rounding_precision=-1)
  File "/home/ryan/miniconda3/envs/lgawp4/lib/python3.10/site-packages/shapely/io.py", line 109, in to_wkt
    return lib.to_wkt(
TypeError: can only be called with ndarray object
(lgawp4) ryan@ryan-laptop:~/Desktop/GIS/Learning-Geospatial-Analysis-with-Python-Fourth-Edition/B19730_04_Asset_Files$ 

@RyanBurnside
Copy link
Author

I managed to regress shapley back to 2.0.3 which seems to have resolved this.

Possible solution: Do a listing on your Book's environment to suggest the proper book versions of assorted libraries in both pip and conda. Then for the next version of the book update them to modern stable variants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant