merge_intersecting_polygons: Merge polygons

View source: R/m.R

merge_intersecting_polygonsR Documentation

Merge polygons

Description

This function merges intersecting polygons by inserting the sub-polygon into the main polygon where they intersect.

Usage

merge_intersecting_polygons(
  main_poly,
  sub_poly,
  cvars = c("x_orig", "y_orig"),
  col_rm = TRUE
)

Arguments

main_poly

The main polygon(s) as a data frame.

sub_poly

The sub-polygon(s) as a data frame.

cvars

A character vector specifying the column names of the x and y coordinates in the main and sub-polygons.

col_rm

Logical indicating whether to remove additional columns added during processing.

Details

The function iterates through each vertex of the sub-polygon and checks if it lies within the main polygon using sp::point.in.polygon.It then identifies the segments of the main polygon where the sub-polygon intersects and inserts the sub-polygon accordingly. Finally, it adjusts the direction of the sub-polygon if necessary and removes any extra columns if specified.

Value

A data frame representing the merged polygons.

Examples

main_poly <- data.frame(x = c(0, 1, 1, 0), y = c(0, 0, 1, 1))
sub_poly <- data.frame(x = c(0.5, 1.5, 1.5, 0.5), y = c(0.5, 0.5, 1.5, 1.5))
merge_intersecting_polygon(main_poly, sub_poly)


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