spherely icon indicating copy to clipboard operation
spherely copied to clipboard

Allow constructing a Polygon(..) with repeated first / last coordinate pair

Open jorisvandenbossche opened this issue 1 year ago • 2 comments

Currently we get:

In [35]: spherely.Polygon([(0, 0), (1, 1), (0, 1), (0, 0)])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[35], line 1
----> 1 spherely.Polygon([(0, 0), (1, 1), (0, 1), (0, 0)])

ValueError: loop is not valid: Edge 3 is degenerate (duplicate vertex)

I am used from shapely that explicitly passing the closing point (which is the same as the first point) is allowed (also because the GEOS data model actually stores this in the coordinates), but this currently fails in spherely. Also because things like WKT or GeoJSON show this, I think it is a common pattern to pass this.

We can probably detect that the last coordinate pair is the same as the first and drop it for the user.

jorisvandenbossche avatar Aug 30 '24 08:08 jorisvandenbossche

In #51 both closing vs. non-closing are supported, although this is fragile as it relies on strict equality of the 1st and last computed vertices (S2Point). We'll certainly need to revisit that as well as uniformize the API with #49 and #50 (i.e., add oriented and planar arguments).

benbovy avatar Oct 11 '24 14:10 benbovy

although this is fragile as it relies on strict equality of the 1st and last computed vertices (S2Point).

I think that is fine (at least for now), AFAIK in GEOS / shapely we also rely on exact floating point equality (that can give problems in corner cases, eg after transforming coordinates, but it's not that common)

jorisvandenbossche avatar Oct 12 '24 09:10 jorisvandenbossche

This is now supported (#51 has been merged).

benbovy avatar Nov 14 '24 15:11 benbovy