get_data: Get data points that lie inside a polygon

View source: R/get_data.R

get_dataR Documentation

Get data points that lie inside a polygon

Description

This function extracts points from a provided dataset that lie inside a given polygon.

Usage

get_data(polygon, xy.dat)

Arguments

polygon

A data frame of 2 columns ("x","y") that contain coordinates of polygon vertices.

xy.dat

A data frame, containing "x" and "y" columns. Other columns may also be present.

Value

A filtered data frame.

Note

This function excludes points that are strictly outside the given polygon. Points lying on the edges or vertices of the polygon (if the polygon is not closed) will be included in the filtered data frame.

Author(s)

Liudas Daumantas

Examples

#Creating data.frame of a polygon
poly<- data.frame(c(3.38,3.30,1.70,0.78,-0.06,-2.30,-2.94,-3.97,-1.61,-0.39,0.68,1.28,1.60,3.38),
c(-0.12,-0.31,-2.73,-3.22,-3.29,-2.19,-1.62,0.94,3.10,3.00,2.91,2.49,2.20,-0.12))

#Creating a data set of points
xy.dat<-data.frame(x=runif(250,-4,4),y=runif(250,-4,4))
plot(poly,type='l',xlab="X",ylab="Y")
points(xy.dat)

#Extracting points that lie inside a polygon
points(get_data(poly,xy.dat),pch=19,col=2)

hespdiv documentation built on May 21, 2026, 5:09 p.m.