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
library(pliman)
shp <- system.file("ex/lux.shp", package="terra")
shp_file <- shapefile_input(shp, as_sf = FALSE)
#> class : SpatVector
#> geometry : polygons
#> dimensions : 12, 6 (geometries, attributes)
#> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax)
#> source : lux.shp
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> names : ID_1 NAME_1 ID_2 NAME_2 AREA POP
#> type : <num> <chr> <num> <chr> <num> <int>
#> values : 1 Diekirch 1 Clervaux 312 18081
#> 1 Diekirch 2 Diekirch 218 32543
#> 1 Diekirch 3 Redange 259 18664
shapefile_view(shp_file)