Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new methods for SpatVectors #82

Merged
merged 38 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b259623
Add new features for SpatVectors
dieghernan Feb 24, 2023
c55b09c
Update docs with pkgdev
github-actions[bot] Feb 24, 2023
8b8b454
Fix tests
dieghernan Feb 24, 2023
d9a2e1d
Add mutate joins
dieghernan Feb 25, 2023
6677f5f
Fix docs
dieghernan Feb 25, 2023
791def0
Update docs with pkgdev
github-actions[bot] Feb 25, 2023
d92ed1e
Fix rest of docs
dieghernan Feb 25, 2023
eaa78a5
Update docs with pkgdev
github-actions[bot] Feb 25, 2023
f619262
Add filter joins
dieghernan Feb 26, 2023
306fb71
Start profiling groups
dieghernan Feb 26, 2023
d305c95
Add group support
dieghernan Feb 27, 2023
090def0
Update docs with pkgdev
github-actions[bot] Feb 27, 2023
a62fa76
Add internal coercion system for SpatVectors
dieghernan Feb 27, 2023
d3e01a0
Update docs with pkgdev
github-actions[bot] Feb 27, 2023
e70e96b
Fix tests
dieghernan Feb 27, 2023
1fed7f3
Add as_spatvector as Method
dieghernan Feb 27, 2023
c5ded6f
New coercing method
dieghernan Feb 28, 2023
546e5f2
Export functions
dieghernan Feb 28, 2023
dcd3abb
Update docs
dieghernan Feb 28, 2023
6dc1f4c
Fix pkgdown index
dieghernan Feb 28, 2023
3303b85
Fix issues
dieghernan Feb 28, 2023
743fe42
Improve tests
dieghernan Feb 28, 2023
a509f8d
Change approach for group_by.SpatVector()
dieghernan Feb 28, 2023
9012c50
Add summarise support
dieghernan Feb 28, 2023
c337330
Fix error on groups
dieghernan Feb 28, 2023
1f6fb39
Fix example
dieghernan Feb 28, 2023
fa4ae3c
Minor internal improvements
dieghernan Mar 1, 2023
1569250
Add example for groups
dieghernan Mar 1, 2023
571daa7
Count tally
dieghernan Mar 1, 2023
971e00e
Work on distinct
dieghernan Mar 2, 2023
b00bf5a
Add tests for summarise
dieghernan Mar 2, 2023
1e907ac
Add tests for groups
dieghernan Mar 2, 2023
adebe49
Improve tests
dieghernan Mar 2, 2023
d2231fc
Potential error on tests...
dieghernan Mar 2, 2023
5258780
End with internals
dieghernan Mar 2, 2023
b58f2fc
Add tests for count tally
dieghernan Mar 2, 2023
594cc21
Start joins
dieghernan Mar 2, 2023
32c50b2
Finish SpatVector
dieghernan Mar 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Finish SpatVector
  • Loading branch information
dieghernan committed Mar 2, 2023
commit 32c50b254205022fde6791e2fd1979e9ddf8c694
14 changes: 12 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
- `arrange.SpatVector()`
- `distinct.SpatVector()`
- `inner_join.SpatVector()`, `left_join.SpatVector()`,
`right_join.SpatVector()` and `full_join.SpatVector()`.
`right_join.SpatVector()` and `full_join.SpatVector()`
- `semi_join.SpatVector()` and `anti_join.SpatVector()`
- `summarise.SpatVector()`
- `group_by.SpatVector()`,`ungroup.SpatVector()`
- `count.SpatVector()`, `tally.SpatVector()`

- New `glimpse()` method for SpatRaster.
- New `glimpse().SpatRaster` method for SpatRaster.

- New coercing and helper functions:

- `as_spatvector()`
- `as_sf()`
- `is_grouped_spatvector()`

# tidyterra 0.3.2

Expand Down
12 changes: 0 additions & 12 deletions R/as_spatvector.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,6 @@ as_spatvect_attr <- function(x) {
return(x)
}


if (!isTRUE((attr(x, "source")) == "SpatVector")) {
cli::cli_alert_danger(
paste(
"Spatial attributes may have been removed.",
"Check the result carefully."
)
)
return(as_spatvector(x, geom = "geometry"))
}


# Get attributes
attrs <- attributes(x)

Expand Down
2 changes: 2 additions & 0 deletions R/group-data-SpatVector.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ dplyr::group_keys
#' @rdname group_data.SpatVector
#' @importFrom dplyr group_rows
group_rows.SpatVector <- function(.data) {
# nocov start
group_data(.data)[[".rows"]]
# nocov end
}

#' @export
Expand Down
71 changes: 52 additions & 19 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ SpatVector. It also provides geoms for plotting these objects with

## Overview

```{r echo=FALSE, results='asis'}
tterra_v <- packageVersion("tidyterra")

l <- unlist(strsplit(as.character(tterra_v), ".", fixed = TRUE))

if (length(l) == 4) {
cat(
"You can have a look to the documentation of",
"the dev version in <https://dieghernan.github.io/tidyterra/dev/>"
)
}
```

{tidyverse} methods implemented on {tidyterra} works differently depending on
the type of Spat\* object:

Expand All @@ -71,25 +84,29 @@ example, `as_tibble()` would return a tibble).

Current methods and functions provided by {tidyterra} are:

| tidyverse method | SpatVector | SpatRaster |
|--------------------|--------------------|----------------------------------------|
| `tibble::as_tibble()` | ✔️ | ✔️ |
| `dplyr::select()` | ✔️ | ✔️ Select layers |
| `dplyr::mutate()` | ✔️ | ✔️ Create /modify layers |
| `dplyr::transmute()` | ✔️ | ✔️ |
| `dplyr::filter()` | ✔️ | ✔️ Modify cells values and (additionally) remove outer cells. |
| `dplyr::slice()` | ✔️ | ✔️ Additional methods for slicing by row and column. |
| `dplyr::pull()` | ✔️ | ✔️ |
| `dplyr::rename()` | ✔️ | ✔️ |
| `dplyr::relocate()` | ✔️ | ✔️ |
| `dplyr::distinct()` | ✔️ | |
| `dplyr::arrange()` | ✔️ | |
| `dplyr::glimpse()` | ✔️ | ✔️ |
| `tidyr::drop_na()` | ✔️ | ✔️ Remove cell values with `NA` on any layer. Additionally, outer cells with `NA` are removed. |
| `tidyr::replace_na()` | ✔️ | ✔️ |
| `ggplot2::autoplot()` | ✔️ | ✔️ |
| `ggplot2::fortify()` | ✔️ to sf via `sf::st_as_sf()` | To a tibble with coordinates. |
| `ggplot2::geom_*()` | ✔️ `geom_spatvector()` | ✔️ `geom_spatraster()` and `geom_spatraster_rgb()`. |
| tidyverse method | SpatVector | SpatRaster |
|---------------------|---------------------|--------------------------------------|
| `tibble::as_tibble()` | ✔️ | ✔️ |
| `dplyr::select()` | ✔️ | ✔️ Select layers |
| `dplyr::mutate()` | ✔️ | ✔️ Create /modify layers |
| `dplyr::transmute()` | ✔️ | ✔️ |
| `dplyr::filter()` | ✔️ | ✔️ Modify cells values and (additionally) remove outer cells. |
| `dplyr::slice()` | ✔️ | ✔️ Additional methods for slicing by row and column. |
| `dplyr::pull()` | ✔️ | ✔️ |
| `dplyr::rename()` | ✔️ | ✔️ |
| `dplyr::relocate()` | ✔️ | ✔️ |
| `dplyr::distinct()` | ✔️ | |
| `dplyr::arrange()` | ✔️ | |
| `dplyr::glimpse()` | ✔️ | ✔️ |
| `dplyr::inner_join()` family | ✔️ | |
| `dplyr::summarise()` | ✔️ | |
| `dplyr::group_by()` family | ✔️ | |
| `dplyr::count()`, `tally()` | ✔️ | |
| `tidyr::drop_na()` | ✔️ | ✔️ Remove cell values with `NA` on any layer. Additionally, outer cells with `NA` are removed. |
| `tidyr::replace_na()` | ✔️ | ✔️ |
| `ggplot2::autoplot()` | ✔️ | ✔️ |
| `ggplot2::fortify()` | ✔️ to sf via `sf::st_as_sf()` | To a tibble with coordinates. |
| `ggplot2::geom_*()` | ✔️ `geom_spatvector()` | ✔️ `geom_spatraster()` and `geom_spatraster_rgb()`. |

## :exclamation: A note on performance

Expand Down Expand Up @@ -137,6 +154,8 @@ install.packages("tidyterra")

## Example

### SpatRasters

This is a basic example which shows you how to manipulate and plot SpatRaster
objects:

Expand Down Expand Up @@ -244,6 +263,20 @@ ggplot() +
theme(legend.position = "bottom")
```

### SpatVectors

This is a basic example which shows you how to manipulate and plot SpatVector
objects:

```{r spatvec }
vect(system.file("ex/lux.shp", package = "terra")) %>%
group_by(NAME_1) %>%
summarise(pop_dens = sum(POP) / sum(AREA)) %>%
glimpse() %>%
autoplot(aes(fill = pop_dens)) +
scale_fill_whitebox_c(palette = "pi_y_g")
```

## I need your feedback

{tidyterra} is currently on development mode. Please leave your feedback or open
Expand Down
67 changes: 48 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ objects with [{ggplot2}](https://ggplot2.tidyverse.org/).

## Overview

You can have a look to the documentation of the dev version in
<https://dieghernan.github.io/tidyterra/dev/>

{tidyverse} methods implemented on {tidyterra} works differently
depending on the type of Spat\* object:

Expand All @@ -51,25 +54,29 @@ object, (for example, `as_tibble()` would return a tibble).

Current methods and functions provided by {tidyterra} are:

| tidyverse method | SpatVector | SpatRaster |
|-----------------------|-------------------------------|------------------------------------------------------------------------------------------------|
| `tibble::as_tibble()` | ✔️ | ✔️ |
| `dplyr::select()` | ✔️ | ✔️ Select layers |
| `dplyr::mutate()` | ✔️ | ✔️ Create /modify layers |
| `dplyr::transmute()` | ✔️ | ✔️ |
| `dplyr::filter()` | ✔️ | ✔️ Modify cells values and (additionally) remove outer cells. |
| `dplyr::slice()` | ✔️ | ✔️ Additional methods for slicing by row and column. |
| `dplyr::pull()` | ✔️ | ✔️ |
| `dplyr::rename()` | ✔️ | ✔️ |
| `dplyr::relocate()` | ✔️ | ✔️ |
| `dplyr::distinct()` | ✔️ | |
| `dplyr::arrange()` | ✔️ | |
| `dplyr::glimpse()` | ✔️ | ✔️ |
| `tidyr::drop_na()` | ✔️ | ✔️ Remove cell values with `NA` on any layer. Additionally, outer cells with `NA` are removed. |
| `tidyr::replace_na()` | ✔️ | ✔️ |
| `ggplot2::autoplot()` | ✔️ | ✔️ |
| `ggplot2::fortify()` | ✔️ to sf via `sf::st_as_sf()` | To a tibble with coordinates. |
| `ggplot2::geom_*()` | ✔️ `geom_spatvector()` | ✔️ `geom_spatraster()` and `geom_spatraster_rgb()`. |
| tidyverse method | SpatVector | SpatRaster |
|------------------------------|-------------------------------|------------------------------------------------------------------------------------------------|
| `tibble::as_tibble()` | ✔️ | ✔️ |
| `dplyr::select()` | ✔️ | ✔️ Select layers |
| `dplyr::mutate()` | ✔️ | ✔️ Create /modify layers |
| `dplyr::transmute()` | ✔️ | ✔️ |
| `dplyr::filter()` | ✔️ | ✔️ Modify cells values and (additionally) remove outer cells. |
| `dplyr::slice()` | ✔️ | ✔️ Additional methods for slicing by row and column. |
| `dplyr::pull()` | ✔️ | ✔️ |
| `dplyr::rename()` | ✔️ | ✔️ |
| `dplyr::relocate()` | ✔️ | ✔️ |
| `dplyr::distinct()` | ✔️ | |
| `dplyr::arrange()` | ✔️ | |
| `dplyr::glimpse()` | ✔️ | ✔️ |
| `dplyr::inner_join()` family | ✔️ | |
| `dplyr::summarise()` | ✔️ | |
| `dplyr::group_by()` family | ✔️ | |
| `dplyr::count()`, `tally()` | ✔️ | |
| `tidyr::drop_na()` | ✔️ | ✔️ Remove cell values with `NA` on any layer. Additionally, outer cells with `NA` are removed. |
| `tidyr::replace_na()` | ✔️ | ✔️ |
| `ggplot2::autoplot()` | ✔️ | ✔️ |
| `ggplot2::fortify()` | ✔️ to sf via `sf::st_as_sf()` | To a tibble with coordinates. |
| `ggplot2::geom_*()` | ✔️ `geom_spatvector()` | ✔️ `geom_spatraster()` and `geom_spatraster_rgb()`. |

## :exclamation: A note on performance

Expand Down Expand Up @@ -120,6 +127,8 @@ install.packages("tidyterra")

## Example

### SpatRasters

This is a basic example which shows you how to manipulate and plot
SpatRaster objects:

Expand Down Expand Up @@ -249,6 +258,26 @@ ggplot() +

<img src="https://raw.githubusercontent.com/dieghernan/tidyterra/main/img/README-hypso-2.png" width="100%" />

### SpatVectors

This is a basic example which shows you how to manipulate and plot
SpatVector objects:

``` r
vect(system.file("ex/lux.shp", package = "terra")) %>%
group_by(NAME_1) %>%
summarise(pop_dens = sum(POP) / sum(AREA)) %>%
glimpse() %>%
autoplot(aes(fill = pop_dens)) +
scale_fill_whitebox_c(palette = "pi_y_g")
#> Rows: 3
#> Columns: 2
#> $ NAME_1 <chr> "Diekirch", "Grevenmacher", "Luxembourg"
#> $ pop_dens <dbl> 80.83865, 134.90133, 485.34879
```

<img src="https://raw.githubusercontent.com/dieghernan/tidyterra/main/img/README-spatvec-1.png" width="100%" />

## I need your feedback

{tidyterra} is currently on development mode. Please leave your feedback
Expand Down
4 changes: 2 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.2.2 (2022-10-31)",
"runtimePlatform": "R version 4.2.2 (2022-10-31 ucrt)",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand Down Expand Up @@ -307,7 +307,7 @@
},
"SystemRequirements": null
},
"fileSize": "3067.724KB",
"fileSize": "3105.125KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand Down
Binary file modified data/cross_blended_hypsometric_tints_db.rda
Binary file not shown.
Binary file modified img/README-example-temp-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/README-example-temp-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/README-example-tile-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/README-example-tile-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/README-hypso-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/README-hypso-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/README-spatvec-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading