Reads a spatial file (.zip containing a single shapefile, .shp, .gpkg,
or .geojson), drops Z/M dimensions, replaces non-ASCII characters in every
attribute column, reprojects the geometry to a target CRS and writes the
result to a user-provided output path. The output format is determined by
the extension of output and may differ from the input format (for example,
a .shp can be cleaned and written as .gpkg).
clean_geo(path, output, crs = 4326, encoding = "ISO-8859-1", quiet = FALSE)Path to the input spatial file. Must be .zip (containing
exactly one shapefile), .shp, .gpkg, or .geojson.
Path to the output file. Required. The extension determines
the output format and must also be one of .zip, .shp, .gpkg, or
.geojson. Existing files at output are overwritten.
Target coordinate reference system passed to
sf::st_transform(). Defaults to EPSG:4326 (WGS84).
Encoding string used when writing shapefile attribute
tables (passed as layer_options = "ENCODING=<encoding>"). Applies only
to .shp and .zip outputs. Defaults to "ISO-8859-1".
Logical. If TRUE, suppress progress messages.
Invisibly returns the normalized output path (character).
This function replaces a standalone batch script that cleaned shapefiles
from a client geospatial portal. The non-ASCII replacement step relies on
textclean::replace_non_ascii(); textclean lives in Suggests:, so the
function stops with an informative error if it is not installed.
Other geo-io:
read_gdb(),
read_geo(),
read_kmz(),
read_sf_zip()
# \donttest{
if (requireNamespace("textclean", quietly = TRUE)) {
z <- system.file("extdata", "misc_example.zip", package = "misc")
if (nzchar(z) && file.exists(z)) {
out <- tempfile(fileext = ".zip")
clean_geo(z, out)
out_gpkg <- tempfile(fileext = ".gpkg")
clean_geo(z, out_gpkg)
}
}
# }