cleangeo quickstart guide

The goal of this document is to get you up and running with cleangeo as quickly as possible.

cleangeo was initially born from some assistance provided to users that were facing issues in processing spatial data in R (see the original post at https://gis.stackexchange.com/questions/113964/fixing-orphaned-holes-in-r).

The main problem with their data is that some spatial objects did not have valid geometries, exposing different types of geometry errors, preventing any easy spatial data processing. Then, cleangeo was built in order to facilitate handling and catching geometry issues, and provide an utility to clean the spatial objects.

This short document shows you how to inspect spatial objects, and clean them with cleangeo.

Install cleangeo

cleangeo is available for download from CRAN. To get the latest cleangeo you can install it from its development repository hosted in Github. For this, you will need the devtools package and run:

remotes::install_github("eblondel/cleangeo")

Load cleangeo

To load the package in R, do the following:

library(cleangeo)

Work with cleangeo

Let's load the package and read some some test spatial objects.

file <- system.file("extdata", "example.shp", package = "cleangeo")

require(sf)
sf <- sf::st_read(file)
sp <- as(sf, "Spatial")

The next step is to inspect these spatial objects, in order to detect potential geometry issues, and make a summary:

report <- clgeo_CollectionReport(sp)
clgeo_SummaryReport(report)

By analysing this report, you will see that 2 of the 3 spatial objects are not valid. The issues deal with a problem of geometry validity. Quite interesting to have such comprehensive report, but how to fix these issues? This is where cleangeo can really help you! so let's try to clean these spatial objects.

The below one-line code uses clgeo_Clean on our spatial objects.

sp.clean <- clgeo_Clean(sp)

And now? Well, let's check the new spatial objects!

report.clean <- clgeo_CollectionReport(sp.clean)
clgeo_SummaryReport(report.clean)


Try the cleangeo package in your browser

Any scripts or data that you put into this service are public.

cleangeo documentation built on Sept. 1, 2023, 5:08 p.m.