repair_geometry: Identify and repair invalid geometry in spatial polygons data...

View source: R/spatial_manipulation.R

repair_geometryR Documentation

Identify and repair invalid geometry in spatial polygons data frames

Description

Using functions from sf, check the geometry of a set of polygons. If the geometry invalid, it attempts to buffer the polygons with sf::st_buffer(dist = 0). If the geometry is corrupt or fine, it does nothing.

Usage

repair_geometry(
  polygons,
  verbose = FALSE,
  force = FALSE,
  use_spherical_geometry = TRUE
)

Arguments

polygons

Spatial polygons (either sf or spatial polygons data frame). The polygons to be checked. Note that the function will halt if the geometry is corrupt and not return a value.

verbose

Logical. If TRUE then the function will produce informative messages as it executes its steps. Useful for debugging. Defaults to FALSE.

force

Logical. If TRUE then both valid and invalid polygons will be buffered by 0. This shouldn't be necessary, but is a feature for the paranoid.

use_spherical_geometry

Logical. USE AT YOUR OWN RISK. Controls if sf uses spherical geometry or not. For particularly wonky sf objects, this may be necessary to effect any kind of repair but can have unintended consequences for the resulting geometry. If TRUE then sf::sf_use_s2() will be set to TRUE which is the default for the package. Defaults to TRUE.

Value

The spatial polygons data frame polygons1. This will be unchanged if the geometry was valid or repaired if it was invalid.


nstauffer/aim.analysis documentation built on Nov. 20, 2024, 8:38 a.m.