polygon_inside_polygon: Check polygon containment and intersection

View source: R/i.R

polygon_inside_polygonR Documentation

Check polygon containment and intersection

Description

This set of functions checks whether one polygon is completely inside another, or whether two polygons intersect.

Usage

polygon_inside_polygon(a, b, strictly = TRUE)

polygon_intersects_polygon(a, b, strictly = TRUE)

Arguments

a

A data frame or matrix with two columns named x and y, representing the vertices of the first polygon.

b

A data frame or matrix with two columns named x and y, representing the vertices of the second polygon.

strictly

Logical, if TRUE, the functions perform strict checks (i.e., points on the edges of the polygons are excluded). If FALSE, points on the edges are considered as inside or intersecting.

Details

These functions help in determining spatial relationships between two polygons. They work with data frames or matrices where the columns represent the x and y coordinates of the polygon's vertices.

  • polygon_inside_polygon(): Checks whether all points of polygon a lie inside polygon b.

  • polygon_intersects_polygon(): Checks whether the polygons a and b intersect, considering their vertices.

  • If strictly = TRUE, the checks exclude points that lie on the edges of the polygons. If strictly = FALSE, points on the edges are considered inside or intersecting.

Value

  • polygon_inside_polygon(): A logical value TRUE if all points of polygon a are inside polygon b, FALSE otherwise.

  • polygon_intersects_polygon(): A logical value TRUE if the polygons intersect, FALSE otherwise.

Examples

polygon_a <- data.frame(x = c(1, 2, 2, 1), y = c(1, 1, 2, 2))
polygon_b <- data.frame(x = c(0, 3, 3, 0), y = c(0, 0, 3, 3))

# Check if polygon_a is completely inside polygon_b
polygon_inside_polygon(polygon_a, polygon_b) # TRUE

# Check if polygon_a intersects with polygon_b
polygon_intersects_polygon(polygon_a, polygon_b) # TRUE


theMILOlab/SPATA2 documentation built on Feb. 8, 2025, 11:41 p.m.