match_points_to_polygons | R Documentation |
Generate a listing of matches between a set of points and a set of polygons.
match_points_to_polygons(pts, poly, form = "string")
pts |
sf POINT table with one or more records (rows) |
poly |
sf POLYGON or sf MULTIPOLYGON with one or more records (rows) |
form |
character, identifies desired output format (default 'string')
|
match listing as described by form
## Not run:
v <- volcano_multi(what = "bands")
pts <- volcano_points(x = v)
y1 <- volcano_polygon()
y2 <- st_rotate(y1, pi/4)
y3 <- st_translate(y1, c(-250, 120))
poly <- dplyr::bind_rows(y1, y2, y3)
m1 <- match_points_to_polygons(pts, poly, form = 'matrix')
head(m1)
m2 <- match_points_to_polygons(pts, poly, form = 'sparse')
m2
m3 <- match_points_to_polygons(pts, poly, form = 'string')
head(m3)
pts <- dplyr::mutate(pts, polygon = m3)
plot(v[,,,1], axes = TRUE, reset = FALSE)
plot(sf::st_geometry(pts), color = 'pink',
add = TRUE, pch = 19, cex = 0.5)
plot(y1, col = NA, border = 'purple', add = TRUE)
plot(sf::st_geometry(pts |> dplyr::filter(grepl("1", polygon))),
pch = 1, col = 'purple', add = TRUE)
plot(y2, col = NA, border = 'orange', add = TRUE)
plot(sf::st_geometry(pts |> dplyr::filter(grepl("2", polygon))),
pch = 2, col = 'orange', add = TRUE, cex = 1.5)
plot(y3, col = NA, border = 'cornflowerblue', add = TRUE)
plot(sf::st_geometry(pts |> dplyr::filter(grepl("3", polygon))),
pch = 0, col = 'cornflowerblue', add = TRUE, cex = 1.5)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.