shapefile_input()
creates or imports a shapefile and optionally converts it to ansf
object. It can also castPOLYGON
orMULTIPOLYGON
geometries toMULTILINESTRING
if required.shapefile_export()
exports an object (sf
orSpatVector
) to a file.shapefile_view()
is a simple wrapper aroundmapview()
to plot a shapefile.
Usage
shapefile_input(
shapefile,
info = TRUE,
as_sf = TRUE,
multilinestring = FALSE,
...
)
shapefile_export(shapefile, filename, ...)
shapefile_view(
shapefile,
attribute = NULL,
type = c("shape", "centroid"),
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 ansf
(simple features) object. Seeterra::vect()
for more details.For
shapefile_export()
, aSpatVector
or ansf
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 isTRUE
).- multilinestring
Logical value indicating whether to cast polygon geometries to
MULTILINESTRING
geometries (default isFALSE
).- ...
Additional arguments to be passed to
terra::vect()
(shapefile_input()
),terra::writeVector()
(shapefile_export()
) ormapview::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
.- type
A character string specifying whether to visualize the shapefile as
"shape"
or as"centroid"
. Partial matching is allowed. If set to"centroid"
, the function will convert the shapefile's geometry to centroids before displaying. Defaults to"shape"
.- color_regions
The color palette to represent
attribute
.
Value
shapefile_input()
returns an object of classsf
(default) representing the imported shapefile.shapefile_export()
returns aNULL
object.shapefile_view()
returns an object of classmapview
.
Examples
if(interactive()){
library(pliman)
shp <- system.file("ex/lux.shp", package="terra")
shp_file <- shapefile_input(shp, as_sf = FALSE)
shapefile_view(shp_file)
}