petern48 commented on code in PR #2772:
URL: https://github.com/apache/sedona/pull/2772#discussion_r2969876271
##########
python/sedona/spark/geopandas/base.py:
##########
@@ -489,9 +489,36 @@ def is_ring(self):
"""
return _delegate_to_geometry_column("is_ring", self)
- # @property
- # def is_ccw(self):
- # raise NotImplementedError("This method is not implemented yet.")
+ @property
+ def is_ccw(self):
+ """Return True for Polygon/MultiPolygon geometries whose exterior ring
+ is counter-clockwise oriented.
+
+ Returns False for non-polygon geometry types (e.g. LineString, Point).
+
+ Notes
+ -----
+ Unlike geopandas, which also supports LinearRing inputs, this
+ implementation uses Sedona's ``ST_IsPolygonCCW`` which only recognises
+ Polygon and MultiPolygon geometries. All other geometry types return
+ ``False``.
Review Comment:
We actually had a previous contribution attempt for `is_ccw()`, and
encountered this problem, and we agreed not to implement it for now
(https://github.com/apache/sedona/pull/2386#discussion_r2422383890), given it's
not easy to replicate the full desired behavior. We're not just missing proper
behavior for LinearRings (which are rare), but we would have the incorrect
behavior for `LineString`s, which are very common. As you can see in the code
snippet below, `LineString` can evaluate to True here too, but our existing
`ST_IsPolygonCCW()` isn't capable of determining that at the moment.
```python
import shapely
from shapely import LineString
from geopandas import GeoSeries
ls = LineString([[0, 0], [1, 0], [1, 1], [2, 2]])
gs = GeoSeries(ls)
print(gs.is_ccw)
```
In order to implement proper support for `is_ccw()`, I think we would need
to investigate doing some more changes in the actual Java code and potentially
look into the upstream JTS library. Given that complexity, I would rather skip
implementing it entirely for now (or at least in a separate PR if you really
want to investigate it, though it would be harder). Could we remove it for now?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]