# create point geographies using coordinate values:
s2_geog_point(-64, 45)
# create line geographies using coordinate values:
s2_make_line(c(-64, 8), c(45, 71))
# optionally, separate features using feature_id:
s2_make_line(
c(-64, 8, -27, -27), c(45, 71, 0, 45),
feature_id = c(1, 1, 2, 2)
)
# create polygon geographies using coordinate values:
# (rings can be open or closed)
s2_make_polygon(c(-45, 8, 0), c(64, 71, 90))
# optionally, separate rings and/or features using
# ring_id and/or feature_id
s2_make_polygon(
c(20, 10, 10, 30, 45, 30, 20, 20, 40, 20, 45),
c(35, 30, 10, 5, 20, 20, 15, 25, 40, 45, 30),
feature_id = c(rep(1, 8), rep(2, 3)),
ring_id = c(1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1)
)
# import and export well-known text
(geog <- s2_geog_from_text("POINT (-64 45)"))
s2_as_text(geog)
# import and export well-known binary
(geog <- s2_geog_from_wkb(wk::as_wkb("POINT (-64 45)")))
s2_as_binary(geog)
# import geometry from planar space
s2_geog_from_text(
"POLYGON ((0 0, 1 0, 0 1, 0 0))",
planar = TRUE,
tessellate_tol_m = 1
)
# export geographies into planar space
geog <- s2_make_polygon(c(179, -179, 179), c(10, 10, 11))
s2_as_text(geog, planar = TRUE)
# polygons containing a pole need an extra step
geog <- s2_data_countries("Antarctica")
geom <- s2_as_text(
s2_intersection(geog, s2_world_plate_carree()),
planar = TRUE
)
Run the code above in your browser using DataLab