tests/area.R

library(s2)

u = s2_union(
   "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
   "POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))",
   s2_options(snap = s2_snap_level(30))
)
s2_area(u, radius = 1)
s2_area("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", radius = 1) +
s2_area("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))", radius = 1) -
s2_area("POLYGON ((5 5, 10 5, 10 15, 5 10, 5 5))", radius = 1)
s2_area("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", radius = 1)
s2_area("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))", radius = 1)
s2_area("POLYGON ((5 5, 10 5, 10 15, 5 10, 5 5))", radius = 1)

df = s2_difference(
   "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
   "POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))",
   s2_options(snap = s2_snap_level(30))
)
s2_area(df, radius = 1) -
  (s2_area("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", radius = 1) -
    s2_area("POLYGON ((5 5, 10 5, 10 15, 5 10, 5 5))", radius = 1))

Try the s2 package in your browser

Any scripts or data that you put into this service are public.

s2 documentation built on May 31, 2023, 9:33 p.m.