assign_areas: Assign point locations to polygons

Description Usage Arguments Value See Also Examples

View source: R/assign_areas.r

Description

Given a set of polygons and a set of point locations (given in decimal degrees), finds in which polygon those locations fall. Finds, for example, in which ASD the given fishing locations occurred.

Usage

1
2
3
4
5
6
7
8
assign_areas(
  Input,
  Polys,
  AreaNameFormat = "GAR_Long_Label",
  Buffer = 0,
  NamesOut = NULL,
  NamesIn = NULL
)

Arguments

Input

dataframe containing - at the minimum - Latitudes and Longitudes to be assigned to polygons.

If NamesIn is not provided, the columns in the Input must be in the following order: Latitude, Longitude, Variable 1, Variable 2, ... Variable x..

Polys

character vector of spatial objects names (e.g., Polys=c('ASDs','RBs')).

Must be matching the names of the pre-loaded spatial objects (loaded via e.g., ASDs=load_ASDs())

AreaNameFormat

dependent on the polygons loaded. For the Secretariat's spatial objects loaded via 'load_' functions, we have the following:

'GAR_Name' e.g., 'Subarea 88.2'

'GAR_Short_Label' e.g., '882'

'GAR_Long_Label' (default) e.g., '88.2'

Several values may be entered if desired (if several Polys are used), e.g.:

c('GAR_Short_Label','GAR_Name'), in which case AreaNameFormat must be given in the same order as Polys.

Buffer

distance in nautical miles to be added around the Polys of interest. Can be specified for each of the spatial objects named in Polys (e.g., Buffer=c(2,5)). Useful to determine whether locations are within Buffer nautical miles of a polygon.

NamesOut

names of the resulting area columns in the output dataframe, with order matching that of Polys (e.g., NamesOut=c('Recapture_ASD','Recapture_RB')). If not provided will be set as equal to Polys.

NamesIn

character vector of length 2 specifying the column names of Latitude and Longitude fields in the Input. Latitudes name must be given first, e.g.:

NamesIn=c('MyLatitudes','MyLongitudes').

Value

dataframe with the same structure as the Input, with additional columns corresponding to the Polys used and named after NamesOut.

See Also

load_ASDs, load_SSRUs, load_RBs, load_SSMUs, load_MAs, load_MPAs, load_EEZs.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#Generate a dataframe
MyData=data.frame(Lat=runif(100,min=-65,max=-50),
                  Lon=runif(100,min=20,max=40))

#Assign ASDs and SSRUs to these locations (first load ASDs and SSRUs)
ASDs=load_ASDs()
SSRUs=load_SSRUs()

MyData=assign_areas(Input=MyData,Polys=c('ASDs','SSRUs'),NamesOut=c('MyASDs','MySSRUs'))

#View(MyData)
table(MyData$MyASDs) #count of locations per ASD
table(MyData$MySSRUs) #count of locations per SSRU

CCAMLRGIS documentation built on Sept. 8, 2021, 9:09 a.m.