utils_shapefile: Import/export shapefiles.

utils_shapefileR Documentation

Import/export shapefiles.

Description

  • shapefile_input() creates or importes a shapefile and optionally convert it to an sf object.

  • shapefile_export() exports an object (sf or SpatVector) to a file

  • shapefile_view() is a simple wrapper around mapview() to plot a shapefile.

Usage

shapefile_input(shapefile, info = TRUE, as_sf = TRUE, ...)

shapefile_export(shapefile, filename, ...)

shapefile_view(
  shapefile,
  attribute = NULL,
  color_regions = custom_palette(c("red", "yellow", "forestgreen")),
  ...
)

Arguments

shapefile

For shapefile_input(), character (filename), or an object that can be coerced to a SpatVector, such as an sf (simple features) object. See terra::vect() for more details.

For shapefile_export(), SpatVector or an sf object to be exported as a shapefile.

info

Logical value indicating whether to print information about the imported shapefile (default is TRUE).

as_sf

Logical value indicating whether to convert the imported shapefile to an sf object (default is TRUE).

...

Additional arguments to be passed to terra::vect() (shapefile_input()), terra::writeVector() (shapefile_export()) or mapview::mapview() (shapefile_view()).

filename

The path to the output shapefile.

attribute

The attribute to be shown in the color key. It must be a variable present in shapefile.

color_regions

The color palette to represent attribute.

Value

  • shapefile_input() returns an object of class sf (default) representing the imported shapefile.

  • shapefile_export() returns a NULL object.

  • shapefile_view() returns an object of class mapview.

Examples

library(pliman)
shp <- system.file("ex/lux.shp", package="terra")
shp_file <- shapefile_input(shp, as_sf = FALSE)
shapefile_view(shp_file)


TiagoOlivoto/pliman documentation built on Sept. 14, 2024, 2:24 a.m.