arrange.SpatVector()
orders the geometries of a SpatVector
by the
values of selected columns.
Usage
# S3 method for class 'SpatVector'
arrange(.data, ..., .by_group = FALSE)
Arguments
- .data
A
SpatVector
created withterra::vect()
.- ...
<
data-masking
> Variables, or functions of variables. Usedesc()
to sort a variable in descending order.- .by_group
If
TRUE
, will sort first by grouping variable. Applies to groupedSpatVector
only (seegroup_by.SpatVector()
).
terra equivalent
Methods
Implementation of the generic dplyr::arrange()
function for
SpatVector
class.
See also
Other single table verbs:
filter.Spat
,
mutate.Spat
,
rename.Spat
,
select.Spat
,
slice.Spat
,
summarise.SpatVector()
Other dplyr verbs that operate on rows:
distinct.SpatVector()
,
filter.Spat
,
slice.Spat
Other dplyr methods:
bind_cols.SpatVector
,
bind_rows.SpatVector
,
count.SpatVector()
,
distinct.SpatVector()
,
filter-joins.SpatVector
,
filter.Spat
,
glimpse.Spat
,
group-by.SpatVector
,
mutate-joins.SpatVector
,
mutate.Spat
,
pull.Spat
,
relocate.Spat
,
rename.Spat
,
rowwise.SpatVector()
,
select.Spat
,
slice.Spat
,
summarise.SpatVector()
Examples
library(terra)
#> terra 1.8.5
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:terra':
#>
#> intersect, union
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
v <- vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
# Single variable
v %>%
arrange(desc(iso2))
#> class : SpatVector
#> geometry : polygons
#> dimensions : 9, 3 (geometries, attributes)
#> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035)
#> names : iso2 cpro name
#> type : <chr> <chr> <chr>
#> values : ES-ZA 49 Zamora
#> ES-VA 47 Valladolid
#> ES-SO 42 Soria
# Two variables
v %>%
mutate(even = as.double(cpro) %% 2 == 0, ) %>%
arrange(desc(even), desc(iso2))
#> class : SpatVector
#> geometry : polygons
#> dimensions : 9, 4 (geometries, attributes)
#> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035)
#> names : iso2 cpro name even
#> type : <chr> <chr> <chr> <logical>
#> values : ES-SO 42 Soria TRUE
#> ES-SG 40 Segovia TRUE
#> ES-P 34 Palencia TRUE
# With new variables
v %>%
mutate(area_geom = terra::expanse(v)) %>%
arrange(area_geom)
#> class : SpatVector
#> geometry : polygons
#> dimensions : 9, 4 (geometries, attributes)
#> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035)
#> names : iso2 cpro name area_geom
#> type : <chr> <chr> <chr> <num>
#> values : ES-SG 40 Segovia 6.921e+09
#> ES-P 34 Palencia 8.042e+09
#> ES-AV 05 Avila 8.053e+09