From 6fe2822a7fd5f983dd7213c0c659817af3a84b29 Mon Sep 17 00:00:00 2001 From: Ward Langeraert Date: Mon, 14 Apr 2025 14:02:14 +0200 Subject: [PATCH 1/3] utm as geopackage --- README.Rmd | 4 ++-- README.md | 2 +- data/b3data_package/datapackage.json | 12 ++++++------ source/add_spatial_resources.Rmd | 17 ++++++++++------- source/create_b3data_package.Rmd | 10 +++++----- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/README.Rmd b/README.Rmd index 3e764ea..f1116fe 100644 --- a/README.Rmd +++ b/README.Rmd @@ -88,7 +88,7 @@ library(frictionless) The content of the data package can be consulted using `read_package()`. ```{r} -b3data_package <- read_package("https://zenodo.org/records/15181098/files/datapackage.json") +b3data_package <- read_package("https://zenodo.org/records/15211029/files/datapackage.json") b3data_package ``` @@ -105,7 +105,7 @@ For non-tabular resources (e.g. spatial or raster data), use packages like `sf` ```{r} mgrs10_belgium <- sf::st_read( - "https://zenodo.org/records/15181098/files/mgrs10_refgrid_belgium.geojson", + "https://zenodo.org/records/15211029/files/mgrs10_refgrid_belgium.gpkg", quiet = TRUE) head(mgrs10_belgium) ``` diff --git a/README.md b/README.md index 369da2c..f066d38 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ like `sf` or `terra` directly. ``` r mgrs10_belgium <- sf::st_read( - "https://zenodo.org/records/15181098/files/mgrs10_refgrid_belgium.geojson", + "https://zenodo.org/records/15181098/files/mgrs10_refgrid_belgium.gpkg", quiet = TRUE) head(mgrs10_belgium) #> Simple feature collection with 6 features and 1 field diff --git a/data/b3data_package/datapackage.json b/data/b3data_package/datapackage.json index fc8f5b9..c23677c 100644 --- a/data/b3data_package/datapackage.json +++ b/data/b3data_package/datapackage.json @@ -1,7 +1,7 @@ { "name": "b3data", - "id": "https://doi.org/10.5281/zenodo.15181098", - "version": "0.1.0", + "id": "https://doi.org/10.5281/zenodo.15211029", + "version": "0.1.2", "resources": [ { "name": "bird_cube_belgium_mgrs10", @@ -11,7 +11,7 @@ "mediatype": "text/csv", "encoding": "utf-8", "title": "Occurrence cube for birds in Belgium (MGRS 10 km)", - "description": "Occurrence cube for birds in Belgium between 2000 en 2024. The taxonomical resolution is 'species' and the temporal resolution is 'year' Spatial aggregation is done using the MGRS grid at 10 km scale. Only grid cells that fall within the 10 km MGRS reference grid for mainland Belgium (see b3data: `mgrs10_refgrid_belgium.geojson`) are included.", + "description": "Occurrence cube for birds in Belgium between 2000 en 2024. The taxonomical resolution is 'species' and the temporal resolution is 'year' Spatial aggregation is done using the MGRS grid at 10 km scale. Only grid cells that fall within the 10 km MGRS reference grid for mainland Belgium (see b3data: `mgrs10_refgrid_belgium.gpkg`) are included.", "sources": [ { "title": "GBIF Occurrence Download", @@ -64,10 +64,10 @@ }, { "name": "mgrs10_refgrid_belgium", - "path": "mgrs10_refgrid_belgium.geojson", - "format": "geojson", + "path": "mgrs10_refgrid_belgium.gpkg", + "format": "gpkg", "title": "MGRS 10 km reference grid Belgium", - "description": "MGRS 10 km reference grid for the mainland of Belgium.", + "description": "MGRS 10 km reference grid for the mainland of Belgium. EPSG:32631 (WGS 84 / UTM zone 31N).", "licenses": [ { "name": "CC0-1.0", diff --git a/source/add_spatial_resources.Rmd b/source/add_spatial_resources.Rmd index 459896e..5f5bfd0 100644 --- a/source/add_spatial_resources.Rmd +++ b/source/add_spatial_resources.Rmd @@ -39,7 +39,7 @@ Add spatial data resources to b3data frictionless data package. # Methods -This report focuses on adding spatial resources (e.g. GeoJSON, raster) to the **b3data** frictionless data package. +This report focuses on adding spatial resources (e.g. GeoPackage, raster) to the **b3data** frictionless data package. ## Source Data @@ -57,7 +57,7 @@ Example: Each dataset includes the following metadata (see: [Frictionless resource spec](https://docs.ropensci.org/frictionless/articles/data-resource.html#properties-implementation)): -- **format**: e.g. `geojson` +- **format**: e.g. `gpkg` - **title**: e.g. `"MGRS 10 km reference grid for Belgium"` - **description**: concise explanation of content - **sources**: source if applicable @@ -77,20 +77,22 @@ ggplot() + geom_sf(data = utm10_bel) ``` Clean data and transform cell codes to MGRS. +Convert to EPSG:32631 (WGS 84 / UTM zone 31N). ```{r} mgrs10_refgrid_belgium <- utm10_bel %>% select(utm_tag = TAG, geometry) %>% mutate(mgrscode = ifelse(grepl("^[A-G]", utm_tag), paste0("31U", utm_tag), paste0("32U", utm_tag))) %>% - select(mgrscode, geometry) + select(mgrscode, geometry) %>% + st_transform(32631) ``` Write to data package and add metadata. ```{r} st_write(mgrs10_refgrid_belgium, - file.path(package_path, "mgrs10_refgrid_belgium.geojson"), + file.path(package_path, "mgrs10_refgrid_belgium.gpkg"), delete_dsn = TRUE) ``` @@ -101,10 +103,11 @@ b3data_package <- read_package(file.path(package_path, "datapackage.json")) # Add resource to data package mgrs10_resource <- list( name = "mgrs10_refgrid_belgium", - path = "mgrs10_refgrid_belgium.geojson", - format = "geojson", + path = "mgrs10_refgrid_belgium.gpkg", + format = "gpkg", title = "MGRS 10 km reference grid Belgium", - description = "MGRS 10 km reference grid for the mainland of Belgium.", + description = paste("MGRS 10 km reference grid for the mainland of Belgium.", + "EPSG:32631 (WGS 84 / UTM zone 31N)."), licenses = list(list( name = "CC0-1.0", path = "https://creativecommons.org/publicdomain/zero/1.0/", diff --git a/source/create_b3data_package.Rmd b/source/create_b3data_package.Rmd index 2e34a16..08899d7 100644 --- a/source/create_b3data_package.Rmd +++ b/source/create_b3data_package.Rmd @@ -38,7 +38,7 @@ Create [frictionless](https://docs.ropensci.org/frictionless/) data package with # Methods This report focuses on creating the **b3data** frictionless data package for tabular datasets. -A separate report adds spatial resources (e.g. GeoJSON, raster) to the same data package. +A separate report adds spatial resources (e.g. GeoPackage, raster) to the same data package. ## Data Package Overview @@ -134,7 +134,7 @@ bird_cube_belgium_mgrs10_full <- download_occ_cube( ) ``` -We only select the grid cells that belong to the MGRS 10 km reference grid for the mainland of Belgium (see b3data `mgrs10_refgrid_belgium.geojson`). +We only select the grid cells that belong to the MGRS 10 km reference grid for the mainland of Belgium (see b3data `mgrs10_refgrid_belgium.gpkg`). ```{r} # Read reference grid @@ -166,7 +166,7 @@ b3data_package <- create_package() %>% "the temporal resolution is 'year'", "Spatial aggregation is done using the MGRS grid at 10 km scale.", "Only grid cells that fall within the 10 km MGRS reference grid for", - "mainland Belgium (see b3data: `mgrs10_refgrid_belgium.geojson`) are", + "mainland Belgium (see b3data: `mgrs10_refgrid_belgium.gpkg`) are", "included."), sources = list(list( title = "GBIF Occurrence Download", @@ -193,10 +193,10 @@ b3data_package <- append(b3data_package, c(name = "b3data"), after = 0) b3data_package <- append(b3data_package, - c(id = "https://doi.org/10.5281/zenodo.15181098"), + c(id = "https://doi.org/10.5281/zenodo.15211029"), after = 1) b3data_package <- append(b3data_package, - c(version = "0.1.0"), + c(version = "0.1.2"), after = 2) # Warning: append() drops the custom datapackage class. From d597eb1b7676597646b5ed70021eb9b9b04acf27 Mon Sep 17 00:00:00 2001 From: Ward Langeraert Date: Mon, 14 Apr 2025 14:03:30 +0200 Subject: [PATCH 2/3] add dict --- inst/en_gb.dic | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inst/en_gb.dic b/inst/en_gb.dic index 7da38ca..95d0065 100644 --- a/inst/en_gb.dic +++ b/inst/en_gb.dic @@ -1,12 +1,14 @@ Daele EEA GeoJSON +GeoPackage Havenlaan Langeraert MGRS NC Rproj Teirlinckgebouw +WGS cff dic gb From 5c514b0181dd7cc95cff223feaedeeb90f7d23e3 Mon Sep 17 00:00:00 2001 From: Ward Langeraert Date: Mon, 14 Apr 2025 14:05:29 +0200 Subject: [PATCH 3/3] fix lintrs --- source/R/download_occ_cube.R | 9 ++++++--- source/add_spatial_resources.Rmd | 10 ++++++---- source/create_b3data_package.Rmd | 8 +++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/source/R/download_occ_cube.R b/source/R/download_occ_cube.R index cc9469b..749377d 100644 --- a/source/R/download_occ_cube.R +++ b/source/R/download_occ_cube.R @@ -6,8 +6,10 @@ download_occ_cube <- function(sql_query, file, path, overwrite = FALSE) { # Stop if overwrite = FALSE and file does not exist file_path <- file.path(path, file) if (file.exists(file_path) && !overwrite) { - message(paste("File already exists. Reading existing file.", - "Set `overwrite = TRUE` to overwrite file.", sep = "\n")) + message( + paste("File already exists. Reading existing file.", + "Set `overwrite = TRUE` to overwrite file.", sep = "\n") + ) occ_cube <- readr::read_csv(file = file_path, show_col_types = FALSE) @@ -34,7 +36,8 @@ download_occ_cube <- function(sql_query, file, path, overwrite = FALSE) { readr::write_csv( x = occ_cube, file = file_path, - append = FALSE) + append = FALSE + ) # Return tibble return(occ_cube) diff --git a/source/add_spatial_resources.Rmd b/source/add_spatial_resources.Rmd index 5f5bfd0..097c36a 100644 --- a/source/add_spatial_resources.Rmd +++ b/source/add_spatial_resources.Rmd @@ -112,17 +112,19 @@ mgrs10_resource <- list( name = "CC0-1.0", path = "https://creativecommons.org/publicdomain/zero/1.0/", title = "Creative Commons Zero v1.0 Universal" - )) - ) + )) +) b3data_package <- add_manual_resource( - b3data_package, mgrs10_resource, replace = TRUE) + b3data_package, mgrs10_resource, replace = TRUE +) # Write package to directory write_package( package = b3data_package, directory = package_path, - compress = TRUE) + compress = TRUE +) ``` ## EEA 100 km reference grid Europe diff --git a/source/create_b3data_package.Rmd b/source/create_b3data_package.Rmd index 08899d7..4cbeb53 100644 --- a/source/create_b3data_package.Rmd +++ b/source/create_b3data_package.Rmd @@ -167,7 +167,8 @@ b3data_package <- create_package() %>% "Spatial aggregation is done using the MGRS grid at 10 km scale.", "Only grid cells that fall within the 10 km MGRS reference grid for", "mainland Belgium (see b3data: `mgrs10_refgrid_belgium.gpkg`) are", - "included."), + "included." + ), sources = list(list( title = "GBIF Occurrence Download", path = "https://doi.org/10.15468/dl.y3wpwk" @@ -176,7 +177,7 @@ b3data_package <- create_package() %>% name = "CC0-1.0", path = "https://creativecommons.org/publicdomain/zero/1.0/", title = "Creative Commons Zero v1.0 Universal" - )) + )) ) ``` @@ -215,5 +216,6 @@ dir.create(package_path, showWarnings = FALSE, recursive = TRUE) write_package( package = b3data_package, directory = package_path, - compress = TRUE) + compress = TRUE +) ```