This function determines whether points (observations) in a given data frame are located inside a specified polygon.

identify_obs_in_polygon(
  coords_df,
  polygon_df,
  strictly,
  opt = "keep",
  cvars = c("x", "y")
)

identify_obs_in_spat_ann(
  coords_df,
  outline_df,
  strictly,
  opt = "keep",
  cvars = c("x", "y")
)

Arguments

coords_df

A data frame containing the coordinates of the observations. Must contain columns specified in cvars.

polygon_df

A data frame containing the coordinates of the polygon's vertices. Must contain columns corresponding to those specified in cvars.

strictly

A logical value indicating whether to consider only points strictly inside the polygon (TRUE) or to include points on the border (FALSE).

opt

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.

cvars

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").

outline_df

A data.frame as returned by getSpatAnnOutlineDf().

Value

A modified version of coords_df based on the operation specified in opt.

Details

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.

Examples

# 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")