tidyterra FAQs
- Source:vignettes/articles/faqs.Rmd
+ Source: vignettes/articles/faqs.Rmd
faqs.Rmd
Session info#> collate English_United States.utf8
#> ctype English_United States.utf8
#> tz UTC
-#> date 2025-01-07
+#> date 2025-01-08
#> pandoc 3.1.11 @ C:/HOSTED~1/windows/pandoc/31F387~1.11/x64/PANDOC~1.11/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
@@ -1038,7 +1038,7 @@ Session info#> tibble 3.2.1 2023-03-20 [1] RSPM
#> tidyr 1.3.1 2024-01-24 [1] RSPM
#> tidyselect 1.2.1 2024-03-11 [1] RSPM
-#> tidyterra * 0.6.2 2025-01-07 [1] local
+#> tidyterra * 0.6.2 2025-01-08 [1] local
#> units 0.8-5 2023-11-28 [1] RSPM
#> vctrs 0.6.5 2023-12-01 [1] RSPM
#> viridisLite 0.4.2 2023-05-02 [1] RSPM
diff --git a/articles/palettes.html b/articles/palettes.html
index 09a8bde7..57d7f330 100644
--- a/articles/palettes.html
+++ b/articles/palettes.html
@@ -92,7 +92,7 @@
Gradient palettes in tidyterra
- Source: vignettes/articles/palettes.Rmd
+ Source: vignettes/articles/palettes.Rmd
palettes.Rmd
Gradient palettes in tidyterra
- Source:vignettes/articles/palettes.Rmd
+ Source: vignettes/articles/palettes.Rmd
palettes.Rmd
Session info#> collate English_United States.utf8
#> ctype English_United States.utf8
#> tz UTC
-#> date 2025-01-07
+#> date 2025-01-08
#> pandoc 3.1.11 @ C:/HOSTED~1/windows/pandoc/31F387~1.11/x64/PANDOC~1.11/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
@@ -233,7 +233,7 @@ Session info#> tibble 3.2.1 2023-03-20 [1] RSPM
#> tidyr 1.3.1 2024-01-24 [1] RSPM
#> tidyselect 1.2.1 2024-03-11 [1] RSPM
-#> tidyterra * 0.6.2 2025-01-07 [1] local
+#> tidyterra * 0.6.2 2025-01-08 [1] local
#> units 0.8-5 2023-11-28 [1] RSPM
#> vctrs 0.6.5 2023-12-01 [1] RSPM
#> withr 3.0.2 2024-10-28 [1] RSPM
diff --git a/articles/tidyterra.html b/articles/tidyterra.html
index 2d45cd4a..a70f7832 100644
--- a/articles/tidyterra.html
+++ b/articles/tidyterra.html
@@ -94,7 +94,7 @@ Diego
2023-07-18
- Source: vignettes/tidyterra.Rmd
+ Source: vignettes/tidyterra.Rmd
tidyterra.Rmd
Diego
2023-07-18
- Source: vignettes/tidyterra.Rmd
+ Source: vignettes/tidyterra.Rmd
tidyterra.Rmd
tidyterra.Rmd
First steps with the tidyterra package
- Source:vignettes/welcome.Rmd
+ Source: vignettes/welcome.Rmd
welcome.Rmd
tidyterra in the wild
- Source:vignettes/articles/wild.Rmd
+ Source: vignettes/articles/wild.Rmd
wild.Rmd
Authors
Citation
-Source: inst/CITATION
Source: inst/CITATION
Hernangómez D (2023). “Using the tidyverse with terra objects: the tidyterra package.” diff --git a/news/index.html b/news/index.html index 8b12900d..02f30394 100644 --- a/news/index.html +++ b/news/index.html @@ -48,11 +48,11 @@
tidyterra 0.6.2
+tidyterra 0.6.2
CRAN release: 2025-01-08
- Add (limited) support for
SpatGraticule
(seeterra::graticule()
) #155. - New arguments in
geom_spatraster_rgb()
:stretch
andzlim
. Seeterra::plotRGB()
for clarification. -
diff --git a/pkgdown.yml b/pkgdown.yml
index a895d8c4..8c49928c 100644
--- a/pkgdown.yml
+++ b/pkgdown.yml
@@ -7,7 +7,7 @@ articles:
tidyterra: tidyterra.html
welcome: welcome.html
articles/wild: wild.html
-last_built: 2025-01-07T14:06Z
+last_built: 2025-01-08T10:50Z
urls:
reference: https://dieghernan.github.io/tidyterra/reference
article: https://dieghernan.github.io/tidyterra/articles
diff --git a/reference/arrange.SpatVector.html b/reference/arrange.SpatVector.html
index a70c1487..fa14b1e0 100644
--- a/reference/arrange.SpatVector.html
+++ b/reference/arrange.SpatVector.html
@@ -50,7 +50,7 @@
Order a
- Source:SpatVector
using column valuesR/arrange-SpatVector.R
+ Source:R/arrange-SpatVector.R
arrange.SpatVector.Rd
Get cell number, row and column from a
- Source:SpatRaster
R/as_coordinates.R
+ Source:R/as_coordinates.R
as_coordinates.Rd
diff --git a/reference/as_spatraster.html b/reference/as_spatraster.html index 55de8752..626d1e39 100644 --- a/reference/as_spatraster.html +++ b/reference/as_spatraster.html @@ -52,7 +52,7 @@ Coerce a data frame to
- Source:SpatRaster
R/as_spatraster.R
+ Source:R/as_spatraster.R
as_spatraster.Rd
Method for coercing objects to
- Source:SpatVector
R/as_spatvector.R
+ Source:R/as_spatvector.R
as_spatvector.Rd
Coerce a
- Source:SpatVector
orSpatRaster
object to data framesR/as_tibble-Spat.R
+ Source:R/as_tibble-Spat.R
as_tibble.Spat.Rd
Create a complete ggplot for
- Source:Spat*
objectsR/autoplot-Spat.R
+ Source:R/autoplot-Spat.R
autoplot.Spat.Rd
Bind multiple
- Source:SpatVector
sf
and data frames objects by columnR/bind-cols-SpatVector.R
+ Source:R/bind-cols-SpatVector.R
bind_cols.SpatVector.Rd
Bind multiple
- Source:SpatVector
,sf/sfc
and data frames objects by rowR/bind-rows-SpatVector.R
+ Source:R/bind-rows-SpatVector.R
bind_rows.SpatVector.Rd
Compare attributes of two
- Source:SpatRaster
objectsR/compare_spatrasters.R
+ Source:R/compare_spatrasters.R
compare_spatrasters.Rd
Count the observations in each
- Source:SpatVector
groupR/count-tally-SpatVector.R
+ Source:R/count-tally-SpatVector.R
count.SpatVector.Rd
Cross-blended hypsometric tints
- Source:R/data.R
+ Source:R/data.R
cross_blended_hypsometric_tints_db.Rd
Keep distinct/unique rows and geometries of
- Source:SpatVector
objectsR/distinct-SpatVector.R
+ Source:R/distinct-SpatVector.R
distinct.SpatVector.Rd
Drop attributes of
- Source:Spat*
objects containing missing valuesR/drop_na-Spat.R
+ Source:R/drop_na-Spat.R
drop_na.Spat.Rd
Fill in missing values with previous or next value on a
- Source:SpatVector
R/fill-SpatVector.R
+ Source:R/fill-SpatVector.R
fill.SpatVector.Rd
Filtering joins for
- Source:SpatVector
objectsR/join-SpatVector.R
+ Source:R/join-SpatVector.R
filter-joins.SpatVector.Rd
Subset cells/geometries of
- Source:Spat*
objectsR/filter-Spat.R
+ Source:R/filter-Spat.R
filter.Spat.Rd
diff --git a/reference/geom_spat_contour.html b/reference/geom_spat_contour.html index 7f288e12..cebc519e 100644 --- a/reference/geom_spat_contour.html +++ b/reference/geom_spat_contour.html @@ -60,7 +60,7 @@ Plot
- Source:SpatRaster
contoursR/geom_spat_contour.R
,R/geom_spat_contour_text.R
,R/geom_spat_contour_fill.R
+ Source:R/geom_spat_contour.R
,R/geom_spat_contour_text.R
,R/geom_spat_contour_fill.R
geom_spat_contour.Rd
Visualise
- Source:SpatRaster
objectsR/geom_spatraster.R
,R/stat_spatraster.R
+ Source:R/geom_spatraster.R
,R/stat_spatraster.R
geom_spatraster.Rd
Visualise
- Source:SpatRaster
objects as imagesR/geom_spatraster_rgb.R
+ Source:R/geom_spatraster_rgb.R
geom_spatraster_rgb.Rd
Visualise
- Source:SpatVector
objectsR/geom_spatvector.R
+ Source:R/geom_spatvector.R
ggspatvector.Rd
Get a nice glimpse of your
- Source:Spat*
objectsR/glimpse-Spat.R
+ Source:R/glimpse-Spat.R
glimpse.Spat.Rd
diff --git a/reference/group-by.SpatVector.html b/reference/group-by.SpatVector.html index 87e85229..60e2883a 100644 --- a/reference/group-by.SpatVector.html +++ b/reference/group-by.SpatVector.html @@ -52,7 +52,7 @@ Group a
- Source:SpatVector
by one or more variablesR/group-by-SpatVector.R
+ Source:R/group-by-SpatVector.R
group-by.SpatVector.Rd
Grouping metadata for
- Source:SpatVector
objectsR/group-data-SpatVector.R
+ Source:R/group-data-SpatVector.R
group_data.SpatVector.Rd
diff --git a/reference/is_grouped_spatvector.html b/reference/is_grouped_spatvector.html index c903b1b6..aad35717 100644 --- a/reference/is_grouped_spatvector.html +++ b/reference/is_grouped_spatvector.html @@ -58,7 +58,7 @@ A grouped
- Source:SpatVector
R/grouped-SpatVector.R
+ Source:R/grouped-SpatVector.R
is_grouped_spatvector.Rd
Check if x and y positions conforms a regular grid
- Source:R/is_regular_grid.R
+ Source:R/is_regular_grid.R
is_regular_grid.Rd
Mutating joins for
- Source:SpatVector
objectsR/join-SpatVector.R
+ Source:R/join-SpatVector.R
mutate-joins.SpatVector.Rd
Create, modify, and delete cell values/layers/attributes of
- Source:Spat*
objectsR/mutate-Spat.R
+ Source:R/mutate-Spat.R
mutate.Spat.Rd
diff --git a/reference/pivot_longer.SpatVector.html b/reference/pivot_longer.SpatVector.html index 31ecfd1d..96fda55a 100644 --- a/reference/pivot_longer.SpatVector.html +++ b/reference/pivot_longer.SpatVector.html @@ -54,7 +54,7 @@ Pivot
- Source:SpatVector
from wide to longR/pivot-long-SpatVector.R
+ Source:R/pivot-long-SpatVector.R
pivot_longer.SpatVector.Rd
Pivot
- Source:SpatVector
from long to wideR/pivot-wide-SpatVector.R
+ Source:R/pivot-wide-SpatVector.R
pivot_wider.SpatVector.Rd
diff --git a/reference/pull.Spat.html b/reference/pull.Spat.html index 8199f7c0..957619fe 100644 --- a/reference/pull.Spat.html +++ b/reference/pull.Spat.html @@ -58,7 +58,7 @@ diff --git a/reference/pull_crs.html b/reference/pull_crs.html index be9632a1..90cbdf2e 100644 --- a/reference/pull_crs.html +++ b/reference/pull_crs.html @@ -60,7 +60,7 @@ diff --git a/reference/reexports.html b/reference/reexports.html index 754986fd..561b5304 100644 --- a/reference/reexports.html +++ b/reference/reexports.html @@ -86,7 +86,7 @@ Objects exported from other packages
- Source:R/arrange-SpatVector.R
,R/as_tibble-Spat.R
,R/autoplot-Spat.R
, and 22 more + Source:R/arrange-SpatVector.R
,R/as_tibble-Spat.R
,R/autoplot-Spat.R
, and 22 morereexports.Rd
Change layer/attribute order
- Source:R/relocate-Spat.R
+ Source:R/relocate-Spat.R
relocate.Spat.Rd
diff --git a/reference/replace_na.Spat.html b/reference/replace_na.Spat.html index e6693239..2de814bc 100644 --- a/reference/replace_na.Spat.html +++ b/reference/replace_na.Spat.html @@ -48,7 +48,7 @@ Replace
- Source:NA
s with specified valuesR/replace_na-Spat.R
+ Source:R/replace_na-Spat.R
replace_na.Spat.Rd
Group
- Source:SpatVector
objects by rowsR/rowwise-SpatVector.R
+ Source:R/rowwise-SpatVector.R
rowwise.SpatVector.Rd
Discrete scales based in the color table of a
- Source:SpatRaster
R/scales_coltab.R
+ Source:R/scales_coltab.R
scale_coltab.Rd
Cross blended hypsometric tints scales
- Source:R/scales_cross_blended.R
+ Source:R/scales_cross_blended.R
scale_cross_blended.Rd
diff --git a/reference/scale_hypso.html b/reference/scale_hypso.html index 8d0fbd27..9b92fead 100644 --- a/reference/scale_hypso.html +++ b/reference/scale_hypso.html @@ -104,7 +104,7 @@ Gradient scales for representing hypsometry and bathymetry
- Source:R/scales_hypso.R
+ Source:R/scales_hypso.R
scale_hypso.Rd
Gradient scales from princess color schemes
- Source:R/scales_princess.R
+ Source:R/scales_princess.R
scale_princess.Rd
Terrain colour scales from grDevices
- Source:R/scales_terrain.R
+ Source:R/scales_terrain.R
scale_terrain.Rd
Gradient scales from WhiteboxTools color schemes
- Source:R/scales_whitebox.R
+ Source:R/scales_whitebox.R
scale_whitebox.Rd
Gradient scales from Wikipedia color schemes
- Source:R/scales_coltab.R
,R/scales_wiki.R
+ Source:R/scales_coltab.R
,R/scales_wiki.R
scale_wiki.Rd
Subset layers/attributes of
- Source:Spat*
objectsR/select-Spat.R
+ Source:R/select-Spat.R
select.Spat.Rd
Subset cells/rows/columns/geometries using their positions
- Source:R/slice-Spat.R
+ Source:R/slice-Spat.R
slice.Spat.Rd
Extract coordinates from
- Source:SpatVector
objectsR/stat_spat_coordinates.R
+ Source:R/stat_spat_coordinates.R
stat_spat_coordinates.Rd
Summarise each group of a
- Source:SpatVector
down to one geometryR/summarise-SpatVector.R
+ Source:R/summarise-SpatVector.R
summarise.SpatVector.Rd
tidyterra: 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' Objects
- Source:R/tidyterra-package.R
+ Source:R/tidyterra-package.R
tidyterra-package.Rd
Updated topographic information on Auckland's Maungawhau volcano
- Source:R/data.R
+ Source:R/data.R
volcano2.Rd
#> values : (147,183] 2 3.594e+05 244 #> (40.7,76.1] 1 4.819e+04 185 #> (4.99,40.7] 9 1.944e+05 209.8"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"spatrasters-1","dir":"Articles","previous_headings":"Plotting with ggplot2","what":"SpatRasters","title":"Welcome to tidyterra","text":"tidyterra provides several geom_* SpatRasters. SpatRaster CRS informed (.e. terra::crs(a_rast) != \"\"), geom uses ggplot2::coord_sf(), may also reprojected adjusting coordinates spatial layers: faceted SpatRaster Contour lines plot SpatRaster Contour filled plot SpatRaster tidyterra can also plot RGB SpatRasters add imagery plots: Plotting RGB SpatRaster tidyterra provides selected scales suitable creating hypsometric bathymetric maps: Hypsometric tints","code":"library(ggplot2) # A faceted SpatRaster ggplot() + geom_spatraster(data = temp) + facet_wrap(~lyr) + scale_fill_whitebox_c( palette = \"muted\", na.value = \"white\" ) # Contour lines for a specific layer f_volcano <- system.file(\"extdata/volcano2.tif\", package = \"tidyterra\") volcano2 <- rast(f_volcano) ggplot() + geom_spatraster(data = volcano2) + geom_spatraster_contour(data = volcano2, breaks = seq(80, 200, 5)) + scale_fill_whitebox_c() + coord_sf(expand = FALSE) + labs(fill = \"elevation\") # Contour filled ggplot() + geom_spatraster_contour_filled(data = volcano2) + scale_fill_whitebox_d(palette = \"atlas\") + labs(fill = \"elevation\") # Read a vector f_v <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- vect(f_v) # Read a tile f_rgb <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") r_rgb <- rast(f_rgb) rgb_plot <- ggplot(v) + geom_spatraster_rgb(data = r_rgb) + geom_spatvector(fill = NA, size = 1) rgb_plot asia <- rast(system.file(\"extdata/asia.tif\", package = \"tidyterra\")) asia #> class : SpatRaster #> dimensions : 164, 306, 1 (nrow, ncol, nlyr) #> resolution : 31836.23, 31847.57 (x, y) #> extent : 7619120, 17361007, -1304745, 3918256 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source : asia.tif #> name : file44bc291153f2 #> min value : -9558.468 #> max value : 5801.927 ggplot() + geom_spatraster(data = asia) + scale_fill_hypso_tint_c( palette = \"gmt_globe\", labels = scales::label_number(), # Further refinements breaks = c(-10000, -5000, 0, 2000, 5000, 8000), guide = guide_colorbar(reverse = TRUE) ) + labs( fill = \"elevation (m)\", title = \"Hypsometric map of Asia\" ) + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" )"},{"path":"https://dieghernan.github.io/tidyterra/articles/welcome.html","id":"spatvectors-1","dir":"Articles","previous_headings":"Plotting with ggplot2","what":"SpatVectors","title":"Welcome to tidyterra","text":"tidyterra allows plot SpatVectors ggplot2 using geom_spatvector() functions: Plotting SpatVectors underlying implementation take advantage conversion terra::vect()/sf::st_as_sf() use ggplot2::geom_sf() endpoint creating layer. tidyterra can also aggregate SpatVectors convenience: Union SpatVectors Union SpatVector keeping inner borders","code":"lux <- system.file(\"ex/lux.shp\", package = \"terra\") v_lux <- terra::vect(lux) ggplot(v_lux) + geom_spatvector(aes(fill = POP), color = \"white\") + geom_spatvector_text(aes(label = NAME_2), color = \"grey90\") + scale_fill_binned(labels = scales::number_format()) + coord_sf(crs = 3857) # Dissolving v_lux %>% # Create categories mutate(gr = cut(POP / 1000, 5)) %>% group_by(gr) %>% # Summary summarise( n = n(), tot_pop = sum(POP), mean_area = mean(AREA) ) %>% ggplot() + geom_spatvector(aes(fill = tot_pop), color = \"black\") + geom_spatvector_label(aes(label = gr)) + coord_sf(crs = 3857) # Same but keeping internal boundaries v_lux %>% # Create categories mutate(gr = cut(POP / 1000, 5)) %>% group_by(gr) %>% # Summary without dissolving summarise( n = n(), tot_pop = sum(POP), mean_area = mean(AREA), .dissolve = FALSE ) %>% ggplot() + geom_spatvector(aes(fill = tot_pop), color = \"black\") + geom_spatvector_label(aes(label = gr)) + coord_sf(crs = 3857)"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Diego Hernangómez. Author, maintainer, copyright holder. Dewey Dunnington. Contributor. ggspatial code ggplot2 authors. Copyright holder. contour code","code":""},{"path":"https://dieghernan.github.io/tidyterra/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Hernangómez D (2023). “Using tidyverse terra objects: tidyterra package.” Journal Open Source Software, 8(91), 5751. ISSN 2475-9066, doi:10.21105/joss.05751, https://doi.org/10.21105/joss.05751.","code":"@Article{R-tidyterra, title = {Using the {tidyverse} with {terra} objects: the {tidyterra} package}, doi = {10.21105/joss.05751}, author = {Diego Hernangómez}, year = {2023}, url = {https://doi.org/10.21105/joss.05751}, publisher = {The Open Journal}, volume = {8}, number = {91}, pages = {5751}, journal = {Journal of Open Source Software}, issn = {2475-9066}, }"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement diego.hernangomezherrero@gmail.com. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"fixing-typos","dir":"","previous_headings":"","what":"Fixing typos","title":"CONTRIBUTING","text":"Small typos grammatical errors documentation may edited directly using GitHub web interface, long changes made source file. YES: edit roxygen comment .R file R/. : edit .Rd file man/.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"prerequisites","dir":"","previous_headings":"","what":"Prerequisites","title":"CONTRIBUTING","text":"make substantial pull request, always file issue make sure someone team agrees ’s problem. ’ve found bug, create associated issue illustrate bug minimal reprex.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"pull-request-process","dir":"","previous_headings":"","what":"Pull request process","title":"CONTRIBUTING","text":"recommend create Git branch pull request (PR). Look R-CMD-check build status making changes. recommend tidyverse style guide. can use styler package apply styles, please don’t restyle code nothing PR. use roxygen2. use testthat. Contributions test cases included easier accept. user-facing changes, add bullet top NEWS.md current development version header describing changes made followed GitHub username, links relevant issue(s)/PR(s).","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"prefer-to-email","dir":"","previous_headings":"","what":"Prefer to Email?","title":"CONTRIBUTING","text":"Email person listed maintainer DESCRIPTION file repo. Though note private discussions email don’t help others - course email totally warranted ’s sensitive problem kind.","code":""},{"path":"https://dieghernan.github.io/tidyterra/CONTRIBUTING.html","id":"thanks-for-contributing","dir":"","previous_headings":"","what":"Thanks for contributing!","title":"CONTRIBUTING","text":"contributing guide adapted tidyverse contributing guide available https://raw.githubusercontent.com/r-lib/usethis/master/inst/templates/tidy-contributing.md","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"tidyterra-","dir":"","previous_headings":"","what":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"goal tidyterra provide common methods tidyverse packages objects created terra package: SpatRaster SpatVector. also provides geoms plotting objects ggplot2. Please cite tidyterra : Hernangómez, D., (2023). Using tidyverse terra objects: tidyterra package. Journal Open Source Software, 8(91), 5751, https://doi.org/10.21105/joss.05751. BibTeX entry LaTeX users :","code":"@article{Hernangómez2023, doi = {10.21105/joss.05751}, url = {https://doi.org/10.21105/joss.05751}, year = {2023}, publisher = {The Open Journal}, volume = {8}, number = {91}, pages = {5751}, author = {Diego Hernangómez}, title = {Using the {tidyverse} with {terra} objects: the {tidyterra} package}, journal = {Journal of Open Source Software} }"},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Full manual recent release tidyterra CRAN online: https://dieghernan.github.io/tidyterra/ tidyverse methods implemented tidyterra works differently depending type Spat* object: SpatVector: methods implemented using terra::.data.frame() coercion. Rows correspond geometries columns correspond attributes geometry. SpatRaster: implementation SpatRaster objects differs, since methods applied layers cells. tidyterra overall approach treat layers columns tibble cells rows (.e. select(SpatRaster, 1) select first layer SpatRaster). methods implemented return type object used input, unless expected behavior method return another type object, (example, as_tibble() return tibble). Current methods functions provided tidyterra :","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"exclamation-a-note-on-performance","dir":"","previous_headings":"","what":"❗ A note on performance","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"tidyterra conceived user-friendly wrapper terra using tidyverse methods verbs. approach therefore cost terms performance. heavy user terra need work big raster files, terra much focused terms performance. possible, function tidyterra references equivalent terra. rule thumb raster less 10.000.000 data slots counting cells layers (.e. terra::ncell(your_rast)*terra::nlyr(your_rast) < 10e6) good go tidyterra. plotting rasters, resampling performed automatically (terra::plot() , see help page). can adjust maxcell parameter.","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Install tidyterra CRAN: can install development version tidyterra like : Alternatively, can install tidyterra using r-universe:","code":"install.packages(\"tidyterra\") remotes::install_github(\"dieghernan/tidyterra\") # Enable this universe install.packages(\"tidyterra\", repos = c( \"https://dieghernan.r-universe.dev\", \"https://cloud.r-project.org\" ))"},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"spatrasters","dir":"","previous_headings":"Example","what":"SpatRasters","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"basic example shows manipulate plot SpatRaster objects: tidyterra also provide geom plotting RGB SpatRaster tiles ggplot2 tidyterra provides specific scales plotting hypsometric maps ggplot2:","code":"library(tidyterra) library(terra) # Temperatures rastertemp <- rast(system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\")) rastertemp #> class : SpatRaster #> dimensions : 87, 118, 3 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source : cyl_temp.tif #> names : tavg_04, tavg_05, tavg_06 #> min values : 1.885463, 5.817587, 10.46338 #> max values : 13.283829, 16.740898, 21.11378 # Rename rastertemp <- rastertemp %>% rename(April = tavg_04, May = tavg_05, June = tavg_06) # Facet all layers library(ggplot2) ggplot() + geom_spatraster(data = rastertemp) + facet_wrap(~lyr, ncol = 2) + scale_fill_whitebox_c( palette = \"muted\", labels = scales::label_number(suffix = \"º\"), n.breaks = 12, guide = guide_legend(reverse = TRUE) ) + labs( fill = \"\", title = \"Average temperature in Castille and Leon (Spain)\", subtitle = \"Months of April, May and June\" ) # Create maximum differences of two months variation <- rastertemp %>% mutate(diff = June - May) %>% select(variation = diff) # Add also a overlay of a SpatVector prov <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) ggplot(prov) + geom_spatraster(data = variation) + geom_spatvector(fill = NA) + scale_fill_whitebox_c( palette = \"deep\", direction = -1, labels = scales::label_number(suffix = \"º\"), n.breaks = 5 ) + theme_minimal() + coord_sf(crs = 25830) + labs( fill = \"variation\", title = \"Variation of temperature in Castille and Leon (Spain)\", subtitle = \"Average temperatures in June vs. May\" ) rgb_tile <- rast(system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\")) plot <- ggplot(prov) + geom_spatraster_rgb(data = rgb_tile) + geom_spatvector(fill = NA) + theme_light() plot # Recognizes coord_sf() plot + # Change crs and datum (for relabeling graticules) coord_sf(crs = 3857, datum = 3857) asia <- rast(system.file(\"extdata/asia.tif\", package = \"tidyterra\")) terra::plot(asia) ggplot() + geom_spatraster(data = asia) + scale_fill_hypso_tint_c( palette = \"gmt_globe\", labels = scales::label_number(), # Further refinements breaks = c(-10000, -5000, 0, 2000, 5000, 8000), guide = guide_colorbar(reverse = TRUE) ) + labs( fill = \"elevation (m)\", title = \"Hypsometric map of Asia\" ) + theme( legend.position = \"bottom\", legend.title.position = \"top\", legend.key.width = rel(3), legend.ticks = element_line(colour = \"black\", linewidth = 0.3), legend.direction = \"horizontal\" )"},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"spatvectors","dir":"","previous_headings":"Example","what":"SpatVectors","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"basic example shows manipulate plot SpatVector objects:","code":"vect(system.file(\"ex/lux.shp\", package = \"terra\")) %>% mutate(pop_dens = POP / AREA) %>% glimpse() %>% autoplot(aes(fill = pop_dens)) + scale_fill_whitebox_c(palette = \"pi_y_g\") + labs( fill = \"population per km2\", title = \"Population density of Luxembourg\", subtitle = \"By canton\" ) #> # A SpatVector 12 x 7 #> # Geometry type: Polygons #> # Geodetic CRS: lon/lat WGS 84 (EPSG:4326) #> # Extent (x / y) : ([5° 44' 38.9\" E / 6° 31' 41.71\" E] , [49° 26' 52.11\" N / 50° 10' 53.84\" N]) #> #> $ ID_1 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3 #> $ NAME_1 \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Diekirch\", \"Diekirch\", \"… #> $ ID_2 1, 2, 3, 4, 5, 6, 7, 12, 8, 9, 10, 11 #> $ NAME_2 \"Clervaux\", \"Diekirch\", \"Redange\", \"Vianden\", \"Wiltz\", \"Echte… #> $ AREA 312, 218, 259, 76, 263, 188, 129, 210, 185, 251, 237, 233 #> $ POP 18081, 32543, 18664, 5163, 16735, 18899, 22366, 29828, 48187,… #> $ pop_dens 57.95192, 149.27982, 72.06178, 67.93421, 63.63118, 100.52660,…"},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"i-need-your-feedback","dir":"","previous_headings":"","what":"I need your feedback","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Please leave feedback open issue https://github.com/dieghernan/tidyterra/issues.","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"need-help","dir":"","previous_headings":"","what":"Need help?","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"Check FAQs open new issue! can also ask Stack Overflow using tag [tidyterra].","code":""},{"path":"https://dieghernan.github.io/tidyterra/index.html","id":"acknowledgement","dir":"","previous_headings":"","what":"Acknowledgement","title":"tidyterra | tidyverse methods and ggplot2 functions for terra objects\n","text":"tidyterra ggplot2 geoms based ggspatial implementation, Dewey Dunnington ggspatial contributors.","code":""},{"path":"https://dieghernan.github.io/tidyterra/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2022 tidyterra authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Order a SpatVector using column values — arrange.SpatVector","title":"Order a SpatVector using column values — arrange.SpatVector","text":"arrange.SpatVector() orders geometries SpatVector values selected columns.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Order a SpatVector using column values — arrange.SpatVector","text":"","code":"# S3 method for class 'SpatVector' arrange(.data, ..., .by_group = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Order a SpatVector using column values — arrange.SpatVector","text":".data SpatVector created terra::vect(). ... Variables, functions variables. Use desc() sort variable descending order. .by_group TRUE, sort first grouping variable. Applies grouped SpatVector (see group_by.SpatVector()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Order a SpatVector using column values — arrange.SpatVector","text":"SpatVector object.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Order a SpatVector using column values — arrange.SpatVector","text":"terra::sort()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Order a SpatVector using column values — arrange.SpatVector","text":"Implementation generic dplyr::arrange() function SpatVector class.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/arrange.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Order a SpatVector using column values — arrange.SpatVector","text":"","code":"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 : #> 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 : #> 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 : #> values : ES-SG 40 Segovia 6.921e+09 #> ES-P 34 Palencia 8.042e+09 #> ES-AV 05 Avila 8.053e+09"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":null,"dir":"Reference","previous_headings":"","what":"Get cell number, row and column from a SpatRaster — as_coordinates","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"as_coordinates() can used obtain position cell SpatRaster matrix.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"","code":"as_coordinates(x, as.raster = FALSE)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"x SpatRaster object. .raster TRUE, result SpatRaster object three layers indicating position cell (cell number, row column).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"tibble SpatRaster (.raster = TRUE) number rows (cells) number cells x. .raster = TRUE resulting SpatRaster crs, extension resolution x","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_coordinates.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get cell number, row and column from a SpatRaster — as_coordinates","text":"","code":"library(terra) f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) as_coordinates(r) #> # A tibble: 10,266 × 3 #> cellindex rowindex colindex #> #> 1 1 1 1 #> 2 2 1 2 #> 3 3 1 3 #> 4 4 1 4 #> 5 5 1 5 #> 6 6 1 6 #> 7 7 1 7 #> 8 8 1 8 #> 9 9 1 9 #> 10 10 1 10 #> # ℹ 10,256 more rows as_coordinates(r, as.raster = TRUE) #> class : SpatRaster #> dimensions : 87, 118, 3 (nrow, ncol, nlyr) #> resolution : 3881.255, 3881.255 (x, y) #> extent : -612335.4, -154347.3, 4283018, 4620687 (xmin, xmax, ymin, ymax) #> coord. ref. : World_Robinson #> source(s) : memory #> names : cellindex, rowindex, colindex #> min values : 1, 1, 1 #> max values : 10266, 87, 118 as_coordinates(r, as.raster = TRUE) %>% plot()"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce a SpatVector to a sf object — as_sf","title":"Coerce a SpatVector to a sf object — as_sf","text":"as_sf() turns SpatVector sf object. wrapper sf::st_as_sf() particularity groups created group_by.SpatVector() preserved.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce a SpatVector to a sf object — as_sf","text":"","code":"as_sf(x, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce a SpatVector to a sf object — as_sf","text":"x SpatVector. ... additional arguments passed sf::st_as_sf().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerce a SpatVector to a sf object — as_sf","text":"sf object object additional tbl_df class, pretty printing method.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_sf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce a SpatVector to a sf object — as_sf","text":"","code":"library(terra) f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- terra::vect(f) # This is ungrouped v #> class : SpatVector #> geometry : polygons #> dimensions : 9, 3 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name #> type : #> values : ES-AV 05 Avila #> ES-BU 09 Burgos #> ES-LE 24 Leon is_grouped_spatvector(v) #> [1] FALSE # Get an ungrouped data a_sf <- as_sf(v) dplyr::is_grouped_df(a_sf) #> [1] FALSE # Grouped v$gr <- c(\"C\", \"A\", \"A\", \"B\", \"A\", \"B\", \"B\") v$gr2 <- rep(c(\"F\", \"G\", \"F\"), 3) gr_v <- group_by(v, gr, gr2) gr_v #> class : SpatVector #> geometry : polygons #> dimensions : 9, 5 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name gr gr2 #> type : #> values : ES-AV 05 Avila C F #> ES-BU 09 Burgos A G #> ES-LE 24 Leon A F is_grouped_spatvector(gr_v) #> [1] TRUE group_data(gr_v) #> # A tibble: 5 × 3 #> gr gr2 .rows #> - > #> 1 A F [2] #> 2 A G [2] #> 3 B F [3] #> 4 C F [1] #> 5 C G [1] # A sf a_gr_sf <- as_sf(gr_v) dplyr::is_grouped_df(a_gr_sf) #> [1] TRUE group_data(a_gr_sf) #> # A tibble: 5 × 3 #> gr gr2 .rows #>
- > #> 1 A F [2] #> 2 A G [2] #> 3 B F [3] #> 4 C F [1] #> 5 C G [1]"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce a data frame to SpatRaster — as_spatraster","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"as_spatraster() turns existing data frame tibble SpatRaster. wrapper terra::rast() S4 method signature data.frame.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"","code":"as_spatraster(x, ..., xycols = 1:2, crs = \"\", digits = 6)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"x tibble data frame. ... additional arguments passed terra::rast(). xycols vector integers length 2 determining position columns hold x y coordinates. crs crs several formats (PROJ.4, WKT, EPSG code, ..) spatial object sf terra. includes target coordinate reference system. See pull_crs() Details. digits integer set precision detecting whether points regular grid (low number digits low precision).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"SpatRaster.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"crs provided tibble created method as_tibble.SpatRaster(), crs inferred attr(x, \"crs\").","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"terra::rast() (see S4 method signature data.frame).","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatraster.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce a data frame to SpatRaster — as_spatraster","text":"","code":"library(terra) r <- rast(matrix(1:90, ncol = 3), crs = \"EPSG:3857\") r #> class : SpatRaster #> dimensions : 30, 3, 1 (nrow, ncol, nlyr) #> resolution : 1, 1 (x, y) #> extent : 0, 3, 0, 30 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> name : lyr.1 #> min value : 1 #> max value : 90 # Create tibble as_tbl <- as_tibble(r, xy = TRUE) as_tbl #> # A tibble: 90 × 3 #> x y lyr.1 #>
#> 1 0.5 29.5 1 #> 2 1.5 29.5 31 #> 3 2.5 29.5 61 #> 4 0.5 28.5 2 #> 5 1.5 28.5 32 #> 6 2.5 28.5 62 #> 7 0.5 27.5 3 #> 8 1.5 27.5 33 #> 9 2.5 27.5 63 #> 10 0.5 26.5 4 #> # ℹ 80 more rows # From tibble newrast <- as_spatraster(as_tbl, crs = \"EPSG:3857\") newrast #> class : SpatRaster #> dimensions : 30, 3, 1 (nrow, ncol, nlyr) #> resolution : 1, 1 (x, y) #> extent : 0, 3, 0, 30 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> source(s) : memory #> name : lyr.1 #> min value : 1 #> max value : 90"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":null,"dir":"Reference","previous_headings":"","what":"Method for coercing objects to SpatVector — as_spatvector","title":"Method for coercing objects to SpatVector — as_spatvector","text":"as_spatvector() turns existing object SpatVector. wrapper terra::vect() S4 method signature data.frame.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Method for coercing objects to SpatVector — as_spatvector","text":"","code":"as_spatvector(x, ...) # S3 method for class 'data.frame' as_spatvector(x, ..., geom = c(\"lon\", \"lat\"), crs = \"\") # S3 method for class 'sf' as_spatvector(x, ...) # S3 method for class 'sfc' as_spatvector(x, ...) # S3 method for class 'SpatVector' as_spatvector(x, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Method for coercing objects to SpatVector — as_spatvector","text":"x tibble, data frame sf object class sf sfc. ... additional arguments passed terra::vect(). geom character. field name(s) geometry data. Either two names x y coordinates points, single name single column WKT geometries. crs crs several formats (PROJ.4, WKT, EPSG code, ..) spatial object sf terra includes target coordinate reference system. See pull_crs() Details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Method for coercing objects to SpatVector — as_spatvector","text":"SpatVector.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Method for coercing objects to SpatVector — as_spatvector","text":"function differs terra::vect() following: geometries NA \"\" values removed prior conversion x grouped data frame (see dplyr::group_by()) grouping vars transferred \"grouped\" SpatVector created (see group_by.SpatVector()). crs provided tibble created method as_tibble.SpatVector(), crs inferred attr(x, \"crs\"). Handles correctly conversion EMPTY geometries sf terra.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Method for coercing objects to SpatVector — as_spatvector","text":"terra::vect()","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_spatvector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Method for coercing objects to SpatVector — as_spatvector","text":"","code":"library(terra) v <- vect(matrix(1:80, ncol = 2), crs = \"EPSG:3857\") v$cat <- sample(LETTERS[1:4], size = nrow(v), replace = TRUE) v #> class : SpatVector #> geometry : points #> dimensions : 40, 1 (geometries, attributes) #> extent : 1, 40, 41, 80 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> names : cat #> type : #> values : A #> C #> D # Create tibble as_tbl <- as_tibble(v, geom = \"WKT\") as_tbl #> # A tibble: 40 × 2 #> cat geometry #> #> 1 A POINT (1 41) #> 2 C POINT (2 42) #> 3 D POINT (3 43) #> 4 C POINT (4 44) #> 5 A POINT (5 45) #> 6 B POINT (6 46) #> 7 C POINT (7 47) #> 8 C POINT (8 48) #> 9 C POINT (9 49) #> 10 D POINT (10 50) #> # ℹ 30 more rows # From tibble newvect <- as_spatvector(as_tbl, geom = \"geometry\", crs = \"EPSG:3857\") newvect #> class : SpatVector #> geometry : points #> dimensions : 40, 1 (geometries, attributes) #> extent : 1, 40, 41, 80 (xmin, xmax, ymin, ymax) #> coord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) #> names : cat #> type : #> values : A #> C #> D"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"as_tibble() methods SpatRaster SpatVector objects.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"","code":"# S3 method for class 'SpatRaster' as_tibble(x, ..., xy = FALSE, na.rm = FALSE, .name_repair = \"unique\") # S3 method for class 'SpatVector' as_tibble(x, ..., geom = NULL, .name_repair = \"unique\")"},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"x SpatRaster created terra::rast() SpatVector created terra::vect(). ... Arguments passed terra::.data.frame(). xy logical. TRUE, coordinates raster cell included na.rm logical. TRUE, cells NA value least one layer removed. argument set NA cells NA values layers removed .name_repair Treatment problematic column names: \"minimal\": name repair checks, beyond basic existence. \"unique\": Make sure names unique empty. \"check_unique\": (default value), name repair, check unique. \"universal\": Make names unique syntactic. function: apply custom name repair (e.g., .name_repair = make.names names style base R). purrr-style anonymous function, see rlang::as_function(). geom character NULL. NULL, either \"WKT\" \"HEX\", get geometry included Well-Known-Text hexadecimal notation. x point geometry, can also \"XY\" add coordinates point","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"tibble.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"terra::.data.frame()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"Implementation generic tibble::as_tibble() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"spatraster-and-spatvector","dir":"Reference","previous_headings":"","what":"SpatRaster and SpatVector","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"tibble returned attribute including crs initial object WKT format (see pull_crs()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"about-layer-column-names","dir":"Reference","previous_headings":"","what":"About layer/column names","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"coercing SpatRaster objects data frames, x y names reserved geographic coordinates cell SpatRaster also noted terra allows layers duplicated names. process coercing SpatRaster tibble, tidyterra may rename layers SpatRaster overcoming issue. Specifically, layers may renamed following cases: Layers duplicated names. coercing tibble, xy = TRUE, layers named x y renamed. working tidyverse methods (.e. filter.SpatRaster()), latter happen well. tidyterra display message informing changes names layer. issue happens SpatVector names geometry (geom = c(\"WKT\", \"HEX\")) x, y (geom = \"XY\"). reserved names representing geometry SpatVector (see terra::.data.frame()). geom NULL logic described SpatRaster apply well columns SpatVector.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/as_tibble.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerce a SpatVector or SpatRaster object to data frames — as_tibble.Spat","text":"","code":"library(terra) # SpatRaster f <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") r <- rast(f) as_tibble(r, na.rm = TRUE) #> # A tibble: 6,522 × 3 #> tavg_04 tavg_05 tavg_06 #> #> 1 3.18 6.79 11.1 #> 2 5.30 8.73 12.7 #> 3 4.59 8.05 12.1 #> 4 6.38 9.72 13.6 #> 5 4.05 7.58 11.8 #> 6 2.90 6.54 10.9 #> 7 5.05 8.49 12.5 #> 8 2.58 6.17 10.5 #> 9 9.30 12.5 15.4 #> 10 9.84 13.0 15.9 #> # ℹ 6,512 more rows as_tibble(r, xy = TRUE) #> # A tibble: 10,266 × 5 #> x y tavg_04 tavg_05 tavg_06 #> #> 1 -610395. 4618746. NA NA NA #> 2 -606513. 4618746. NA NA NA #> 3 -602632. 4618746. NA NA NA #> 4 -598751. 4618746. NA NA NA #> 5 -594870. 4618746. NA NA NA #> 6 -590988. 4618746. NA NA NA #> 7 -587107. 4618746. NA NA NA #> 8 -583226. 4618746. NA NA NA #> 9 -579345. 4618746. NA NA NA #> 10 -575463. 4618746. NA NA NA #> # ℹ 10,256 more rows # SpatVector f <- system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\") v <- vect(f) as_tibble(v) #> # A tibble: 9 × 3 #> iso2 cpro name #> #> 1 ES-AV 05 Avila #> 2 ES-BU 09 Burgos #> 3 ES-LE 24 Leon #> 4 ES-P 34 Palencia #> 5 ES-SA 37 Salamanca #> 6 ES-SG 40 Segovia #> 7 ES-SO 42 Soria #> 8 ES-VA 47 Valladolid #> 9 ES-ZA 49 Zamora"},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a complete ggplot for Spat* objects — autoplot.Spat","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"autoplot() uses ggplot2 draw plots ones produced terra::plot()/terra::plotRGB() single command.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"","code":"# S3 method for class 'SpatRaster' autoplot( object, ..., rgb = NULL, use_coltab = NULL, facets = NULL, nrow = NULL, ncol = 2 ) # S3 method for class 'SpatVector' autoplot(object, ...)"},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"object SpatRaster created terra::rast() SpatVector created terra::vect(). ... arguments passed geom_spatraster(), geom_spatraster_rgb() geom_spatvector(). rgb Logical. plotted RGB image? NULL (default) autoplot.SpatRaster() try guess. use_coltab Logical. plotted corresponding terra::coltab()? NULL (default) autoplot.SpatRaster() try guess. See also scale_fill_coltab(). facets Logical. facets displayed? NULL (default) autoplot.SpatRaster() try guess. nrow, ncol Number rows columns facet.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"ggplot2 layer","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Implementation ggplot2::autoplot() method.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Implementation generic ggplot2::autoplot() function.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"spatraster","dir":"Reference","previous_headings":"","what":"SpatRaster","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Uses geom_spatraster() geom_spatraster_rgb().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"spatvector","dir":"Reference","previous_headings":"","what":"SpatVector","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"Uses geom_spatvector(). Labels can placed geom_spatvector_text() geom_spatvector_label().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/autoplot.Spat.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a complete ggplot for Spat* objects — autoplot.Spat","text":"","code":"# \\donttest{ file_path <- system.file(\"extdata/cyl_temp.tif\", package = \"tidyterra\") library(terra) temp <- rast(file_path) library(ggplot2) autoplot(temp) # With a tile tile <- system.file(\"extdata/cyl_tile.tif\", package = \"tidyterra\") %>% rast() autoplot(tile) # With coltabs ctab <- system.file(\"extdata/cyl_era.tif\", package = \"tidyterra\") %>% rast() autoplot(ctab) # With vectors v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) autoplot(v) v %>% autoplot(aes(fill = cpro)) + geom_spatvector_text(aes(label = iso2)) + coord_sf(crs = 25829) # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"Bind number SpatVector, data frames sf object column, making wider result. similar .call(cbind, dfs). possible prefer using join combine SpatVector data frames objects. bind_spat_cols() binds rows order appear easy create meaningless results without realizing .","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"","code":"bind_spat_cols( ..., .name_repair = c(\"unique\", \"universal\", \"check_unique\", \"minimal\") )"},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"... Objects combine. first argument SpatVector subsequent arguments can either SpatVector, sf object data frame. Inputs recycled length, matched position. .name_repair One \"unique\", \"universal\", \"check_unique\". See dplyr::bind_cols() Details.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"SpatVector corresponding columns. geometry CRS correspond first SpatVector ....","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"cbind() method","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"Implementation dplyr::bind_rows() function SpatVector objects. Note second subsequent arguments ... geometry cbinded, data frame (-ish) columns kept.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_cols.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Bind multiple SpatVector sf and data frames objects by column — bind_cols.SpatVector","text":"","code":"library(terra) sv <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) df2 <- data.frame(letters = letters[seq_len(nrow(sv))]) # Data frame bind_spat_cols(sv, df2) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 4 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name letters #> type : #> values : ES-AV 05 Avila a #> ES-BU 09 Burgos b #> ES-LE 24 Leon c # Another SpatVector bind_spat_cols(sv[1:2, ], sv[3:4, ]) #> New names: #> • `iso2` -> `iso2...1` #> • `cpro` -> `cpro...2` #> • `name` -> `name...3` #> • `iso2` -> `iso2...4` #> • `cpro` -> `cpro...5` #> • `name` -> `name...6` #> class : SpatVector #> geometry : polygons #> dimensions : 2, 6 (geometries, attributes) #> extent : 2987054, 3296229, 2017622, 2331004 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2...1 cpro...2 name...3 iso2...4 cpro...5 name...6 #> type : #> values : ES-AV 05 Avila ES-LE 24 Leon #> ES-BU 09 Burgos ES-P 34 Palencia # sf objects sfobj <- sf::read_sf(system.file(\"shape/nc.shp\", package = \"sf\")) bind_spat_cols(sv[1:9, ], sfobj[1:9, ]) #> class : SpatVector #> geometry : polygons #> dimensions : 9, 17 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name AREA PERIMETER CNTY_ CNTY_ID NAME FIPS #> type : #> values : ES-AV 05 Avila 0.114 1.442 1825 1825 Ashe 37009 #> ES-BU 09 Burgos 0.061 1.231 1827 1827 Alleghany 37005 #> ES-LE 24 Leon 0.143 1.63 1828 1828 Surry 37171 #> FIPSNO (and 7 more) #> #> 3.701e+04 #> 3.7e+04 #> 3.717e+04 # Mixed end <- bind_spat_cols(sv, sfobj[seq_len(nrow(sv)), 1:2], df2) end #> class : SpatVector #> geometry : polygons #> dimensions : 9, 6 (geometries, attributes) #> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> source : cyl.gpkg #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : iso2 cpro name AREA PERIMETER letters #> type : #> values : ES-AV 05 Avila 0.114 1.442 a #> ES-BU 09 Burgos 0.061 1.231 b #> ES-LE 24 Leon 0.143 1.63 c glimpse(end) #> # A SpatVector 9 x 6 #> # Geometry type: Polygons #> # Projected CRS: ETRS89-extended / LAEA Europe (EPSG:3035) #> # CRS projection units: meter #> # Extent (x / y) : ([2,892,687 / 3,341,372] , [2,017,622 / 2,361,600]) #> #> $ iso2 \"ES-AV\", \"ES-BU\", \"ES-LE\", \"ES-P\", \"ES-SA\", \"ES-SG\", \"ES-SO\"… #> $ cpro \"05\", \"09\", \"24\", \"34\", \"37\", \"40\", \"42\", \"47\", \"49\" #> $ name \"Avila\", \"Burgos\", \"Leon\", \"Palencia\", \"Salamanca\", \"Segovia… #> $ AREA 0.114, 0.061, 0.143, 0.070, 0.153, 0.097, 0.062, 0.091, 0.118 #> $ PERIMETER 1.442, 1.231, 1.630, 2.968, 2.206, 1.670, 1.547, 1.284, 1.421 #> $ letters \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\" # Row sizes must be compatible when column-binding try(bind_spat_cols(sv, sfobj)) #> Error in dplyr::bind_cols(alltibbs, .name_repair = .name_repair) : #> Can't recycle `..1` (size 9) to match `..2` (size 100)."},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"Bind number SpatVector, data frames sf/sfc objects row, making longer result. similar .call(rbind, dfs), output contain columns appear inputs.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"","code":"bind_spat_rows(..., .id = NULL)"},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"... Objects combine. first argument SpatVector subsequent arguments can either SpatVector, sf/sfc object data frame. Columns matched name, missing columns filled NA. .id name optional identifier column. Provide string create output column identifies input. column use names available, otherwise use positions.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"SpatVector type first element ....","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"rbind() method","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"Implementation dplyr::bind_rows() function SpatVector objects. first element ... SpatVector. Subsequent elements may SpatVector, sf/sfc objects data frames: subsequent SpatVector/sf/sfc objects present different CRS first element, elements reprojected CRS first element message. element ... tibble/data frame rows cbinded empty geometries message.","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/bind_rows.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Bind multiple SpatVector, sf/sfc and data frames objects by row — bind_rows.SpatVector","text":"","code":"library(terra) v <- vect(system.file(\"extdata/cyl.gpkg\", package = \"tidyterra\")) v1 <- v[1, \"cpro\"] v2 <- v[3:5, c(\"name\", \"iso2\")] # You can supply individual SpatVector as arguments: bind_spat_rows(v1, v2) #> class : SpatVector #> geometry : polygons #> dimensions : 4, 3 (geometries, attributes) #> extent : 2892687, 3180130, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE #> NA Palencia ES-P # When you supply a column name with the `.id` argument, a new # column is created to link each row to its original data frame bind_spat_rows(v1, v2, .id = \"id\") #> class : SpatVector #> geometry : polygons #> dimensions : 4, 4 (geometries, attributes) #> extent : 2892687, 3180130, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : id cpro name iso2 #> type : #> values : 1 05 NA NA #> 2 NA Leon ES-LE #> 2 NA Palencia ES-P # \\donttest{ # Use with sf sfobj <- sf::st_as_sf(v2[1, ]) sfobj #> Simple feature collection with 1 feature and 2 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 2926589 ymin: 2233673 xmax: 3125372 ymax: 2361600 #> Projected CRS: ETRS89-extended / LAEA Europe #> name iso2 geometry #> 1 Leon ES-LE POLYGON ((3049427 2233673, ... bind_spat_rows(v1, sfobj) #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2926589, 3126360, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE # Would reproject with a message on different CRS sfobj_3857 <- as_spatvector(sfobj) %>% project(\"EPSG:3857\") bind_spat_rows(v1, sfobj_3857) #> ! Reprojecting object 2 in `...` since it doesn't have the same CRS than object 1 #> class : SpatVector #> geometry : polygons #> dimensions : 2, 3 (geometries, attributes) #> extent : 2926589, 3126360, 2017622, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE # And with data frames with a message data(\"mtcars\") bind_spat_rows(v1, sfobj, mtcars, .id = \"id2\") #> ! Object 3 in `...` is #> The result would present empty geoms #> class : SpatVector #> geometry : polygons #> dimensions : 34, 15 (geometries, attributes) #> extent : -180, 3126360, -90, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : id2 cpro name iso2 mpg cyl disp hp drat wt #> type : #> values : 1 05 NA NA NA NA NA NA NA NA #> 2 NA Leon ES-LE NA NA NA NA NA NA #> 3 NA NA NA 21 6 160 110 3.9 2.62 #> (and 5 more) #> #> #> #> # Use lists bind_spat_rows(list(v1[1, ], sfobj[1:2, ])) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 3 (geometries, attributes) #> extent : -180, 3126360, -90, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : cpro name iso2 #> type : #> values : 05 NA NA #> NA Leon ES-LE #> NA NA NA # Or named list combined with .id bind_spat_rows(list( SpatVector = v1[1, ], sf = sfobj[1, ], mtcars = mtcars[1, ] ), .id = \"source\") #> ! Object 3 in `...` is #> The result would present empty geoms #> class : SpatVector #> geometry : polygons #> dimensions : 3, 15 (geometries, attributes) #> extent : -180, 3126360, -90, 2361600 (xmin, xmax, ymin, ymax) #> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035) #> names : source cpro name iso2 mpg cyl disp hp drat wt #> type : #> values : SpatVector 05 NA NA NA NA NA NA NA NA #> sf NA Leon ES-LE NA NA NA NA NA NA #> mtcars NA NA NA 21 6 160 110 3.9 2.62 #> (and 5 more) #> #> #> #> # }"},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":null,"dir":"Reference","previous_headings":"","what":"Compare attributes of two SpatRaster objects — compare_spatrasters","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"Two SpatRaster objects compatible (terms combining layers) crs, extent resolution similar. cases can combine objects simply c(x, y). function compares attributes informing results. See Solving issues section minimal guidance.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"","code":"compare_spatrasters(x, y, digits = 6)"},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"x, y SpatRaster objects digits Integer set precision comparing extent resolution.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"invisible logical TRUE/FALSE indicating SpatRaster objects compatible, plus informative message flagging issues found ().","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"terra::identical()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"solving-issues","dir":"Reference","previous_headings":"","what":"Solving issues","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"non-equal crs, try terra::project(). non-equal extent try terra::resample(). non-equal resolution can try terra::resample(), terra::aggregate() terra::disagg().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/compare_spatrasters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Compare attributes of two SpatRaster objects — compare_spatrasters","text":"","code":"library(terra) x <- rast(matrix(1:90, ncol = 3), crs = \"EPSG:3857\") # Nothing compare_spatrasters(x, x) # Different crs y_nocrs <- x crs(y_nocrs) <- NA compare_spatrasters(x, y_nocrs) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • crs # Different extent compare_spatrasters(x, x[1:10, , drop = FALSE]) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • extent # Different resolution y_newres <- x res(y_newres) <- res(x) / 2 compare_spatrasters(x, y_newres) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • resolution # Everything compare_spatrasters(x, project(x, \"epsg:3035\")) #> ! Results of `tidyterra::compare_spatrasters()`: #> The following attributes are not equal: #> • crs #> • extent #> • resolution"},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":null,"dir":"Reference","previous_headings":"","what":"Count the observations in each SpatVector group — count.SpatVector","title":"Count the observations in each SpatVector group — count.SpatVector","text":"count() lets quickly count unique values one variables: df %>% count(, b) roughly equivalent df %>% group_by(, b) %>% summarise(n = n()). count() paired tally(), lower-level helper equivalent df %>% summarise(n = n()).","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Count the observations in each SpatVector group — count.SpatVector","text":"","code":"# S3 method for class 'SpatVector' count( x, ..., wt = NULL, sort = FALSE, name = NULL, .drop = group_by_drop_default(x), .dissolve = TRUE ) # S3 method for class 'SpatVector' tally(x, wt = NULL, sort = FALSE, name = NULL)"},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Count the observations in each SpatVector group — count.SpatVector","text":"x SpatVector. ... Variables group . wt implemented method sort TRUE, show largest groups top. name name new column output. omitted, default n. already column called n, use nn. column called n nn, 'll use nnn, , adding ns gets new name. .drop Handling factor levels appear data, passed group_by(). count(): FALSE include counts empty groups (.e. levels factors exist data). add_count(): deprecated since actually affect output. .dissolve logical. borders aggregated geometries dissolved?","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Count the observations in each SpatVector group — count.SpatVector","text":"SpatVector object additional attribute.","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"terra-equivalent","dir":"Reference","previous_headings":"","what":"terra equivalent","title":"Count the observations in each SpatVector group — count.SpatVector","text":"terra::aggregate()","code":""},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Count the observations in each SpatVector group — count.SpatVector","text":"Implementation generic dplyr::count() family functions SpatVector objects. tally() always return disaggregated geometry count() can handle . See also summarise.SpatVector().","code":""},{"path":[]},{"path":"https://dieghernan.github.io/tidyterra/reference/count.SpatVector.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Count the observations in each SpatVector group — count.SpatVector","text":"","code":"# \\donttest{ library(terra) f <- system.file(\"ex/lux.shp\", package = \"terra\") p <- vect(f) p %>% count(NAME_1, sort = TRUE) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_1 n #> type : #> values : Diekirch 5 #> Luxembourg 4 #> Grevenmacher 3 p %>% count(NAME_1, sort = TRUE) #> class : SpatVector #> geometry : polygons #> dimensions : 3, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : NAME_1 n #> type : #> values : Diekirch 5 #> Luxembourg 4 #> Grevenmacher 3 p %>% count(pop = ifelse(POP < 20000, \"A\", \"B\")) #> class : SpatVector #> geometry : polygons #> dimensions : 2, 2 (geometries, attributes) #> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax) #> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : pop n #> type :