BUG: IllegalArgumentException: Geometry must be a Point or LineString when exporting certain geometry to json
See original GitHub issue-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of geopandas.
-
(optional) I have confirmed this bug exists on the master branch of geopandas.
Code Sample, a copy-pastable example
ISOCHRONES_FILE='kz_test_isochrone_driving_30.json'
gdf = gpd.read_file(ISOCHRONES_FILE)
gdf.to_json()
# Errors, with results
gdf.to_file('test_output.json', driver='GeoJSON')
# Errors, with results
stats = zonal_stats(gdf, tiff, stats="sum")
# Errors, with seemingly valid results
Gist with sample data using a single feature: https://gist.github.com/yuletide/a0291717fd132c3619fc7f327b68647a
Problem description
When loading isochrones created from the Mapbox API, and converting to JSON, multiple “IllegalArgumentException: Geometry must be a Point or LineString” errors appear, even thought he JSON looks fine on manual inspection. This error also occurs when passing a gdf into rasterstats
(this was how I found it originally).
What does this error mean? The only mentions I could find when googling were shapely errors. Is this due to invalid geometry or library versions? Would love any guidance!
Original input compared to output from pandas:
To rule out library or environment issues I tested with sample geopandas data and saw no errors.
Expected Output
Not erroring, or more descriptive error.
Output of geopandas.show_versions()
SYSTEM INFO
python : 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:20) [Clang 11.0.1 ] executable : /Users/alexyule/anaconda3/envs/geopandas/bin/python machine : macOS-10.15.7-x86_64-i386-64bit GEOS, GDAL, PROJ INFO
GEOS : 3.9.1 GEOS lib : /Users/alexyule/anaconda3/envs/geopandas/lib/libgeos_c.dylib GDAL : 3.1.4 GDAL data dir: /Users/alexyule/anaconda3/envs/geopandas/share/gdal PROJ : 8.0.0 PROJ data dir: /Users/alexyule/anaconda3/envs/geopandas/share/proj PYTHON DEPENDENCIES
geopandas : 0.9.0 pandas : 1.2.4 fiona : 1.8.18 numpy : 1.20.2 shapely : 1.8a1 rtree : 0.9.7 pyproj : 3.0.1 matplotlib : 3.4.1 mapclassify: None geopy : None psycopg2 : None geoalchemy2: None pyarrow : None pygeos : 0.9
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (7 by maintainers)
@yuletide this will be fixed in 1.8a2. The error messages correspond to empty geometries. It’s the fault of GEOS that they are so cryptic. Until 1.8a2 comes out, the work around is to filter out empty shapes.
Thanks for the debugging and leads on the bug @jorisvandenbossche !
Here’s the problem: https://github.com/Toblerity/Shapely/pull/995/files#diff-0cfd418bbccae3cd182953f575a205d0bc8bde442f40041187b6016668cbefdeL306. In 1.7 (and in 2.0) we short-circuit instead of using the CoordinateSequence constructor. I’m looking into a fix now.