identify_obs_in_polygon.Rd
This function determines whether points (observations) in a given data frame are located inside a specified polygon.
A data frame containing the coordinates of the observations.
Must contain columns specified in cvars
.
A data frame containing the coordinates of the polygon's vertices.
Must contain columns corresponding to those specified in cvars
.
A logical value indicating whether to consider only points strictly inside the polygon (TRUE
)
or to include points on the border (FALSE
).
A character string specifying the operation to perform on identified points.
Options are "keep" (default), "remove", or any other string to create a new column in coords_df
indicating whether each point is inside (TRUE
) or outside (FALSE
) the polygon.
A character vector specifying the variable names in coords_df
and polygon_df
that represent the x and y coordinates. Defaults to c("x", "y")
.
A data.frame as returned by getSpatAnnOutlineDf()
.
A modified version of coords_df
based on the operation specified in opt
.
The function can be configured to strictly consider points within the polygon or to include points on the border. Additionally, the function allows for either keeping or removing the identified points, or marking them based on their position relative to the polygon.
# Example data frames
coords_df <- data.frame(x = c(1, 2, 3), y = c(3, 2, 1))
polygon_df <- data.frame(x = c(1, 2, 3, 1), y = c(1, 2, 3, 1))
# Identify and keep points inside the polygon
inside_points <- identify_obs_in_polygon(coords_df, polygon_df, strictly = TRUE)
# Identify and remove points inside the polygon
outside_points <- identify_obs_in_polygon(coords_df, polygon_df, strictly = TRUE, opt = "remove")