paleolimbot / wk

Lightweight Well-Known Geometry Parsing
https://paleolimbot.github.io/wk
Other
47 stars 7 forks source link

Polygon winding order / orientation #169

Closed anthonynorth closed 1 year ago

anthonynorth commented 1 year ago

Would you be open to adding support for computing polygon orientation and re-orienting polygon features?

I'm aware of 2 packages which implement this: sf::st_sfc(check_ring_dir=TRUE) (requires all polygon/multipolygon, sets counterclockwise winding) and lwgeom::st_force_polygon_cw() (clockwise winding). So this is not strictly necessary, but it would be convenient to not require the following back-and-forth:

# ccw
wkb_polys <- wkb_polys |>
  sf::st_as_sfc() |>
  sf::st_sfc(check_ring_dir = TRUE) |>
  wk::as_wkb()

# or, cw
wkb_polys <- wkb_polys |>
  sf::st_as_sfc() |>
  lwgeom::st_force_polygon_cw() |>
  wk::as_wkb()

The current geoparquet spec has optional metadata for orientation, so it would be handy to have this facility for known polygon winding in geoparquet files written by {geoarrow}.

paleolimbot commented 1 year ago

Sorry for letting this sit for a while!

You probably already know that that winding order can be obtained from the signed area (e.g., https://dewey.dunnington.ca/post/2021/wk-version-0.5.0/#dplyr-integration ). You could in theory write a "filter" that accomplishes this...one of the reasons I never got here is that "filters" are hard and perhaps not as well thought-out as readers/writers. It's probably easier to write in C++ than in C (e.g., start from the WKT writer).