clip_by_poly: clip_by_poly

View source: R/clip_by_poly.r

clip_by_polyR Documentation

clip_by_poly

Description

This function takes a dataframe and a polygon, and clips the dataframe using the the extent of the polygon. The polygon can be buffered as required to select nearby data as well.

Usage

clip_by_poly(
  df = NULL,
  lat.field = "LATITUDE",
  lon.field = "LONGITUDE",
  clip.poly = NULL,
  buffer.m = NULL,
  invert = F,
  return.sf = T
)

Arguments

df

default is NULL. This is the dataframe/sf object that will be altered. It can be a dataframe, sp::spatial* object or an sf object (point, line or polygon).

lat.field

the default is "LATITUDE". This is the name of the field holding latitude values (in decimal degrees). This is only necessary if input is a non spatial df.

lon.field

the default is "LONGITUDE". This is the name of the field holding longitude values (in decimal degrees). This is only necessary if input is a non spatial df.

clip.poly

default is NULL. This is either an sf polygon, an sp:spatialPolygons object, or the full path to a shapefile (including the '.shp' extension). This is the polygon that will be used to clip the input object.

buffer.m

default is NULL. This is the distance in meters to buffer the border of clip.poly

invert

default is FALSE. By default, input will be clipped such that

  • points only those points within the clip.poly are returned

  • lines only those lines that cross or are contained by the clip.poly are returned

  • polygons only those polygons that cross or are contained by the clip.poly are returned

However, if invert is set to TRUE, than any points/lines/polygons that intersect/ are contained by the clip.poly will be removed.

return.sf

default is TRUE. By default, the returned object will be an sf object. Set to FALSE to return a dataframe only.

Value

sf object

Note

If the input polygon has no projection assigned, it will be assumed to be in Geographic, WGS84. FYI, during buffering, the polygon is briefly converted to UTMZone20 since the use of distances requires projecting the data.

Author(s)

Mike McMahon, Mike.McMahon@dfo-mpo.gc.ca

See Also

Other general_use: DDMMSS_to_DD(), DDMMx_to_DD(), aggregator(), combine_lists(), df_qc_spatial(), df_sf_to_gpkg(), df_to_sf(), drop_cols(), prepare_shape_fields(), subset_by_time(), updateCheck()


Maritimes/Mar.utils documentation built on Feb. 12, 2024, 11:38 p.m.