st_repair_geometry {wdpar} | R Documentation |
Repair geometry
Description
Repair the geometry of a sf::st_sf()
object.
Usage
st_repair_geometry(x, geometry_precision = 1500)
Arguments
x |
|
geometry_precision |
|
Details
This function works by first using the sf::st_make_valid()
function
to attempt to fix geometry issues. Since the sf::st_make_valid()
function
sometimes produce incorrect geometries in rare cases
(e.g. when fixing invalid geometries that cross the dateline),
this function then uses the st_prepair()
function from the prepr
package to fix those geometries instead
(see https://github.com/dickoa/prepr for details).
Installation
This function uses the prepr package to help repair geometries in certain cases. Because the prepr package is not available on the Comprehensive R Archive Network (CRAN), it must be installed from its online code repository. To achieve this, please use the following code:
if (!require(remotes)) install.packages("remotes") remotes::install_github("dickoa/prepr")
Note that the prepr package has system dependencies that need to be installed before the package itself can be installed (see package README file for platform-specific instructions).
Examples
# create sf object
p1 <- st_sf(
id = 1,
geometry = st_as_sfc("POLYGON((0 0, 0 10, 10 0, 10 10, 0 0))", crs = 3857)
)
# repair geometry
p2 <- st_repair_geometry(p1)
# print object
print(p2)