mark_inside_polygon {psyosphere}R Documentation

Mark coordinates within a polygon

Description

A column will be created that indicates whether a coordinate lies within a polygon or not. See also point.in.polygon.

Usage

mark_inside_polygon(
  tracks, polygon, bind = TRUE, drop = TRUE, cname = "in_polygon"
)

Arguments

tracks

psyo. Data frame with tracks.

polygon

list. A list with the column lon (numeric) and lat (numeric).

bind

logical. Return the distance as list (FALSE) or add it to tracks (TRUE).

drop

logical. If TRUE and only one observation is returned drop the data frame and collapse the return value to a vector.

cname

character. The name of the new column.

Value

psyo

Credit

If you use Psyosphere for commercial use or research, please support us by include one off the following references:

Author(s)

Benjamin Ziepert. Please send feedback to: feedback-psyosphere@analyse-gps.com.

See Also

point.in.polygon

Examples

# Create polygon
lon <- c(4.92, 4.93, 4.93, 4.92, 4.92)
lat <- c(52.311, 52.311, 52.308, 52.308, 52.311)
poly <- data.frame(lon, lat)
remove(lon, lat)

# Get data
data(psyo)
data(psyo_map)

# Plot polygon and data
plot <- psyosphere::plot_tracks(psyo, t_id = "", plot = psyo_map)
# plot <- psyosphere::plot_tracks(psyo, t_id = "")
plot <- psyosphere::plot_polygon(poly, plot = plot)
plot

# Mark coordinates within plygon
psyo <- psyosphere::mark_inside_polygon(psyo, poly)

# Plot inside polygon in different color
in_poly <- psyo[ psyo[,"in_polygon"] != 0,]
in_poly[,"dot_color"] <- "red"
psyosphere::plot_tracks(in_poly, plot = plot)

[Package psyosphere version 0.1 Index]