Skip to content
Merged
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
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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)
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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
Expand Down
12 changes: 6 additions & 6 deletions data/b3data_package/datapackage.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions inst/en_gb.dic
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
Daele
EEA
GeoJSON
GeoPackage
Havenlaan
Langeraert
MGRS
NC
Rproj
Teirlinckgebouw
WGS
cff
dic
gb
Expand Down
9 changes: 6 additions & 3 deletions source/R/download_occ_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
27 changes: 16 additions & 11 deletions source/add_spatial_resources.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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)
```

Expand All @@ -101,25 +103,28 @@ 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/",
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
Expand Down
18 changes: 10 additions & 8 deletions source/create_b3data_package.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -166,8 +166,9 @@ 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",
"included."),
"mainland Belgium (see b3data: `mgrs10_refgrid_belgium.gpkg`) are",
"included."
),
sources = list(list(
title = "GBIF Occurrence Download",
path = "https://doi.org/10.15468/dl.y3wpwk"
Expand All @@ -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"
))
))
)
```

Expand All @@ -193,10 +194,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.
Expand All @@ -215,5 +216,6 @@ dir.create(package_path, showWarnings = FALSE, recursive = TRUE)
write_package(
package = b3data_package,
directory = package_path,
compress = TRUE)
compress = TRUE
)
```