question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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: a5ae8936-94ec-43ce-85f8-e85853e04db1

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:closed
  • Created 2 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
sgilliescommented, May 14, 2021

@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 !

2reactions
sgilliescommented, May 14, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR:shapely.geos:IllegalArgumentException: Geometry ...
Steps to reproduce the problem. Define a geometric object that isn't Point or LineString; Example: {'type': 'Polygon', 'coordinates': [[[ ...
Read more >
Geometry must be a Point or LineString error using Cartopy
The problem is a wrong version of shapely, with Cartopy the binary package shoudn't be used, it should be built from source instead....
Read more >
Points of LinearRing do not form a closed linestring
Show activity on this post. I'm trying to index geojson data using elasticsearch. There is some kind of polygons that causing an error:...
Read more >
Add a GeoJSON export to Briefcase and Aggregate - Features
As a data manager, I would like to export data from Briefcase and Aggregate ... Each geometric object will have key and name...
Read more >
TLcdGeoJsonModelEncoder (LuciadLightspeed API ...
GeoJson is a text-format to represent geographic vector data. It may represent a geometry, a feature or a collection of features.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found