Skip to content

[GH-2385] Implement is_ccw - #2386

Closed
yunchipang wants to merge 3 commits into
apache:masterfrom
yunchipang:2385-impl-geopandas-is_ccw
Closed

yunchipang wants to merge 3 commits into
apache:masterfrom
yunchipang:2385-impl-geopandas-is_ccw

Conversation

@yunchipang

Copy link
Copy Markdown
Contributor

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

Implements is_ccw

How was this patch tested?

Tests added

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation.

@petern48 petern48 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again! I have some more feedback this time. But the PR looks great aside from a few more cases I'd like us to test.

s = GeoSeries(
[
LinearRing([(0, 0), (0, 1), (1, 1), (0, 0)]),
LinearRing([(0, 0), (1, 1), (0, 1), (0, 0)]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LinearRing([(0, 0), (1, 1), (0, 1), (0, 0)]),
LinearRing([(0, 0), (1, 1), (0, 1), (0, 0)]),
LineString([(0, 0), (1, 1), (0, 1), (-1, -1)]),

Let's add a line that isn't a full ring that should return True.

LinearRing([(0, 0), (0, 1), (1, 1), (0, 0)]),
LinearRing([(0, 0), (1, 1), (0, 1), (0, 0)]),
LineString([(0, 0), (1, 1), (0, 1)]),
Point(3, 3),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Point(3, 3),
Point(3, 3),
LineString(),
MultiLineString([LineString([(0, 0), (1, 1), (0, 1), (-1, -1)])]),
GeometryCollection([LineString([(0, 0), (1, 1), (0, 1), (-1, -1)])]),

A few more cases, I'd like to test. The first is LINESTRING EMPTY. The other two are all collections of a single linestring that would return True. Make sure to validate that the expected result is the same as geopandas.


def test_is_ccw(self):
pass
for geom in self.linestrings:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for geom in self.linestrings:
for geom in self.geoms:

Since the docs explicitly specify the expected result for non-linear geometries is False, then we should test that they do correctly return that result.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't catch it originally (totally my bad), but the same goes for your other PR for is_closed since the docstring mentions the result should be False. Could you try updating it to self.geoms there too? I think it would pass, but it fails, we can instead leave alone and file a new (bug) issue to fix the implementation in a separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petern48 thanks for the heads up! sorry I was not aware of the situation. I've raised #2387 to fix this for is_closed and I'm going to close this PR. please lmk which ones in #2230 could be easier to implement if you have some in mind. i'd love to help!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I think in general, most should be pretty easy. As I just mentioned in the issue, I updated the list with corresponding Sedona functions. I'd recommend any of those, since I expect them to be straightforward. It's possible that some are not, but the only way to be sure is to try it out. I think most cases will be as simple as your is_closed PR.

"is_ccw",
"Tests if LinearRing geometries are oriented counter-clockwise.",
)
spark_expr = stf.ST_IsPolygonCCW(self.spark.column)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After seeing the test failures, I took a look at the documentation and implementation of ST_IsPolygonCCW function. Unfortunately, it doesn't look like ST_IsPolygonCCW will not work for us, since it only handles Polygons and returns False for all linestrings. Looking at the shapely implementation (which geopandas uses) is_ccw is a function with some custom logic, so there doesn't seem to be a direct function equivalent in Sedona currently.

This doesn't seem very easy to implement, so I think it's better to skip this one for now. Sorry about that @yunchipang

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Geopandas: Implement is_ccw

2 participants