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

67 use simplify geom from db #124

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .Rprofile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (grepl("ubuntu 18.04|debian 8", tolower(utils::osVersion))) {
# repos <- c("RSPM" = "https://cran.rstudio.com",
"thinkropen" = "https://thinkr-open.r-universe.dev",
"CRAN" = "https://cran.rstudio.com")
} else if (grepl("ubuntu 20.04|debian 9", tolower(utils::osVersion))) {
} else if (grepl("ubuntu 20.04|debian 9|pop!_os 22.04 lts", tolower(utils::osVersion))) {
repos <- c("RSPM" = "https://packagemanager.rstudio.com/all/__linux__/focal/latest",
# repos <- c("RSPM" = "https://cran.rstudio.com",
"thinkropen" = "https://thinkr-open.r-universe.dev",
Expand All @@ -28,6 +28,10 @@ if (grepl("ubuntu 18.04|debian 8", tolower(utils::osVersion))) {
repos <- c("RSPM" = "https://packagemanager.rstudio.com/all/__linux__/centos7/latest",
"thinkropen" = "https://thinkr-open.r-universe.dev",
"CRAN" = "https://cran.rstudio.com")
} else if ( grepl("pop!_os 22.04 lts", tolower(utils::osVersion)) ) {
repos <- c("RSPM" = "https://packagemanager.rstudio.com/all/latest",
"thinkropen" = "https://thinkr-open.r-universe.dev",
"CRAN" = "https://cran.rstudio.com")
} else {
# Important for MacOS users in particular
repos <- c("RSPM" = "https://cran.rstudio.com",
Expand Down
3 changes: 1 addition & 2 deletions R/utils_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ generate_datasets <- function(con) {
catchment_geom <- sf::st_read(
con,
query = "SELECT * FROM diadesatlas.v_basin vb"
) %>%
rmapshaper::ms_simplify()
)

dataALL <- DBI::dbGetQuery(
con,
Expand Down
47 changes: 40 additions & 7 deletions data-raw/aa-a-exploration_data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ remotes::install_github('inrae/diades.atlas')
```

## Packages
```{r}
```{r, message=FALSE}
library(dplyr)
library(DBI)
library(ggplot2)
Expand Down Expand Up @@ -59,9 +59,9 @@ However, at some point, some of your {tidyverse} operations can not be realised
For instance.

- `dbGetQuery()` download data in R
- `filter()` is executed by R in your R session
- `filter()` is executed by R in your R session
- Note that `!!` is a specific to using {dplyr} with SQL there.
+ This is because the variable after it (e.g. `species_id`) is defined in the R session, but not in the database. Therefore, before sending the SQL query to the database, R has to transform the variable by its real value in R. Otherwise, it will send the word `"species_id"` which does not make sense for the SQL database, instead of the number you wanted to put.
+ This is because the variable after it (e.g. `species_id`) is defined in the R session, but not in the database. Therefore, before sending the SQL query to the database, R has to transform the variable by its real value in R. Otherwise, it will send the word `"species_id"` which does not make sense for the SQL database, instead of the number you wanted to put.


```{r}
Expand All @@ -75,13 +75,16 @@ get_data_dbi <- function(conn_eurodiad, species_id, scenario) {
}

# Use it
get_data_dbi(conn_eurodiad,
species_id = c(6),
scenario = 'rcp85')
get_data_dbi(
conn_eurodiad,
species_id = c(6),
scenario = 'rcp85'
) %>%
head()
```

- `tbl()` only connects to the table, only a glimpse of the data is presented
- `filter()` is run by the SQL database
- `filter()` is run by the SQL database

```{r}
get_data_tbl <- function(conn_eurodiad, species_id, scenario) {
Expand Down Expand Up @@ -139,6 +142,36 @@ get_data_tbl_query_collect(conn_eurodiad,
geom_line(aes(y = hsi))
```

## Reprex invalid ices_geom

Two polygons of ices_geom have invalid geometries.

```{r}
ices_geom <- st_read(
conn_eurodiad,
query = "SELECT * FROM diadesatlas.v_ices_geom;"
) %>%
st_transform("+proj=wintri") #%>%
# rmapshaper::ms_simplify()
```


```{r}
invalid_pols <- ices_geom %>%
filter(!st_is_valid(.))

nrow(invalid_pols)
```

This makes the interactive map fails.

```{r, error=TRUE}
map_invalid <- tm_shape(invalid_pols)+
tm_sf()

tmap_leaflet(map_invalid)
```


## Disconnect from the database

Expand Down
Loading