filter_by_polygon: Filter FORCIS data by a spatial polygon

View source: R/filter_by_polygon.R

filter_by_polygonR Documentation

Filter FORCIS data by a spatial polygon

Description

Filters FORCIS data by a spatial polygon.

Usage

filter_by_polygon(data, polygon)

Arguments

data

a data.frame. One obtained by ⁠read_*_data()⁠ functions.

polygon

an ⁠sf POLYGON⁠ object.

Value

A data.frame containing a subset of data for the desired spatial polygon.

Examples

# Attach the package ----
library("forcis")

# Import example dataset ----
file_name <- system.file(file.path("extdata", "FORCIS_net_sample.csv"), 
                         package = "forcis")

net_data <- read.table(file_name, dec = ".", sep = ";")

# Add 'data_type' column ----
net_data$"data_type" <- "Net"

# Dimensions of the data.frame ----
dim(net_data)

# Import Indian Ocean spatial polygons ----
file_name <- system.file(file.path("extdata", 
                         "IHO_Indian_ocean_polygon.gpkg"), 
                         package = "forcis")

indian_ocean <- sf::st_read(file_name)

# Filter by polygon ----
net_data_sub <- filter_by_polygon(net_data, polygon = indian_ocean)

# Dimensions of the data.frame ----
dim(net_data_sub)

FRBCesab/forcis documentation built on Oct. 25, 2024, 9:26 a.m.