# NOT RUN {
# returns the boundary:
# empty for point, endpoints of a linestring,
# perimeter of a polygon
s2_boundary("POINT (-64 45)")
s2_boundary("LINESTRING (0 0, 10 0)")
s2_boundary("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")
# returns the area-weighted centroid, element-wise
s2_centroid("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")
s2_centroid("LINESTRING (0 0, 10 0)")
# returns the unweighted centroid of the entire input
s2_centroid_agg(c("POINT (0 0)", "POINT (10 0)"))
# returns the closest point on x to y
s2_closest_point(
"POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
"POINT (0 90)" # north pole!
)
# returns the shortest possible line between x and y
s2_minimum_clearance_line_between(
"POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
"POINT (0 90)" # north pole!
)
# binary operations: difference, symmetric difference, intersection and union
s2_difference(
"POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
"POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))",
# 32 bit platforms may need to set snap rounding
s2_options(snap = s2_snap_level(30))
)
s2_sym_difference(
"POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
"POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))",
# 32 bit platforms may need to set snap rounding
s2_options(snap = s2_snap_level(30))
)
s2_intersection(
"POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
"POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))",
# 32 bit platforms may need to set snap rounding
s2_options(snap = s2_snap_level(30))
)
s2_union(
"POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
"POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))",
# 32 bit platforms may need to set snap rounding
s2_options(snap = s2_snap_level(30))
)
# use s2_union_agg() to aggregate geographies in a vector
s2_union_agg(
c(
"POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
"POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"
),
# 32 bit platforms may need to set snap rounding
s2_options(snap = s2_snap_level(30))
)
# snap to grid rounds coordinates to a specified grid size
s2_snap_to_grid("POINT (0.333333333333 0.666666666666)", 1e-2)
# }
Run the code above in your browser using DataCamp Workspace