Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s2_simplify() #51

Closed
paleolimbot opened this issue Jun 21, 2020 · 3 comments
Closed

s2_simplify() #51

paleolimbot opened this issue Jun 21, 2020 · 3 comments

Comments

@paleolimbot
Copy link
Collaborator

It's possible to get some simplification using s2_options(snap_radius = <radians>), but it doesn't truly simplify in the same way that sf::st_simplify() does. Also, BigQuery ST_SIMPLIFY() is a thing, so it must be possible somewhere.

library(s2)
s2_union(
  "LINESTRING (0 0, 0 1, 0 2, 0 3, 0 4)",
  options = s2_options(snap_radius = 1.5 * pi / 180)
)
#> <s2_geography[1]>
#> [1] <LINESTRING (0 0, 0 2, 0 4)>

Created on 2020-06-21 by the reprex package (v0.3.0)

Points can probably be simplified by snap + union, there is a dedicated class for simplifying polylines, but I haven't seen a polygon simplifier yet.

@edzer
Copy link
Member

edzer commented Jun 21, 2020

Doesn't S2Builder::set_simplify_edge_chains(true) do this? The snap radius then is the simplification parameter, as dTolerance in sf::st_simplify. We could pass this in options?

@paleolimbot
Copy link
Collaborator Author

!!!!

Very cool, definitely the way to go.

@paleolimbot
Copy link
Collaborator Author

Still working on the details, but this is looking really good in #70!

library(s2)
library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
st_as_sfc.s2_geography <- function(x) st_as_sfc(s2_as_binary(x))

germany <- s2_data_countries("Germany")
germany %>% st_as_sfc() %>% plot()

withr::with_par(list(mfrow = c(2, 2)), {
  s2_simplify(germany, 1e2) %>% st_as_sfc() %>% plot(main = "0.1 km")
  s2_simplify(germany, 1e3) %>% st_as_sfc() %>% plot(main = "1 km")
  s2_simplify(germany, 1e4) %>% st_as_sfc() %>% plot(main = "10 km")
  s2_simplify(germany, 1e5) %>% st_as_sfc() %>% plot(main = "100 km")
})

Created on 2020-07-08 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants