invalid polygon

Open
#222 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp, r

Research direction

Start with the reproducible R example using s2_geog_from_text(), s2_rebuild(), and s2_is_valid(), then compare its result with the GEOS validity check shown through sf. Determine whether the differing validity result reflects S2's validity rules or package handling; done means the behavior and any required change are clearly established.

Written by the indexing model from the issue text.

Description

I was hoping that this polygon:

x

would be made valid by:

library(s2)
x = s2_geog_from_text("POLYGON ((0 0, 3 0, 3 2, 1 1, 2 1, 0 2, 0 0))", check = FALSE)
o = s2_options(split_crossing_edges = TRUE)
s2_rebuild(x, o) |> s2_is_valid()
# [1] FALSE

Zooming in, the resulting geometry

library(sf)
# Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.1; sf_use_s2() is TRUE
s2_rebuild(x, o) |> st_as_sfc() -> y
y[[1]]
# POLYGON ((0 0, 3 0, 3 2, 1.5 1.250243, 0 2, 0 0), (2 1, 1 1, 1.5 1.250243, 2 1))

seems valid (inner ring CW, touches outer ring in a point), and

st_crs(y) = NA # so that GEOS is_valid is called:
st_is_valid(y)
# [1] TRUE

is considered valid by GEOS. Does s2geometry have a different concept of valid, or does the package handle this?

Dominant language
C++
Stars
81
Forks
19
Avg merge
20h 25m
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-spatial/s2

All issues in r-spatial/s2

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.