omanges / turfpy

A Python library for performing geospatial data analysis which reimplements turf.js.
MIT License
121 stars 27 forks source link

Bugfix: intersection may be GeometryCollection #84

Closed shepik closed 3 years ago

shepik commented 3 years ago

When intersection has type=GeometryCollection, coordinates is undefined.

sackh commented 3 years ago

@shepik Thanks, Will you please write a test for this and fix the linting errors.

shepik commented 3 years ago

@shepik Thanks, Will you please write a test for this and fix the linting errors.

Sure, i'll do it in a couple of days.

omanges commented 3 years ago

Please update your PR with latest changes

kapitan-iglu commented 3 years ago

Last week I run into strange error (same code, same input, same libs but different results) and today I found that it was caused by this bug. I'm using last v0.0.5 release.

I suggest to fix this in more general way by using is_empty:

--- transformation.py
+++ transformation.py
@@ -155,11 +155,11 @@
     for shape_value in shapes:
         intersection = shape_value.intersection(intersection)

-    intersection = mapping(intersection)
-
-    if (
-        len(intersection.get("coordinates", [])) == 0
-        and len(intersection.get('geometries', [])) == 0
-    ):
+    if intersection.is_empty:
         return None

+    intersection = mapping(intersection)
+
     properties = merge_dict(properties_list)

     intersection_feature = Feature(geometry=intersection, properties=properties)

@omanges what do you think?

sackh commented 3 years ago

Thanks, @kapitan-iglu, will you please share the test example. yes is_empty seems to be good option.