Skip to content

Commit fa63610

Browse files
authored
Merge pull request #7 from b-cubed-eu/geopackage
Geopackage
2 parents 9af1b8f + 97c829f commit fa63610

File tree

7 files changed

+43
-31
lines changed

7 files changed

+43
-31
lines changed

README.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ library(frictionless)
8888
The content of the data package can be consulted using `read_package()`.
8989

9090
```{r}
91-
b3data_package <- read_package("https://zenodo.org/records/15181098/files/datapackage.json")
91+
b3data_package <- read_package("https://zenodo.org/records/15211029/files/datapackage.json")
9292
b3data_package
9393
```
9494

@@ -105,7 +105,7 @@ For non-tabular resources (e.g. spatial or raster data), use packages like `sf`
105105

106106
```{r}
107107
mgrs10_belgium <- sf::st_read(
108-
"https://zenodo.org/records/15181098/files/mgrs10_refgrid_belgium.geojson",
108+
"https://zenodo.org/records/15211029/files/mgrs10_refgrid_belgium.gpkg",
109109
quiet = TRUE)
110110
head(mgrs10_belgium)
111111
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ like `sf` or `terra` directly.
109109

110110
``` r
111111
mgrs10_belgium <- sf::st_read(
112-
"https://zenodo.org/records/15181098/files/mgrs10_refgrid_belgium.geojson",
112+
"https://zenodo.org/records/15181098/files/mgrs10_refgrid_belgium.gpkg",
113113
quiet = TRUE)
114114
head(mgrs10_belgium)
115115
#> Simple feature collection with 6 features and 1 field

data/b3data_package/datapackage.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "b3data",
3-
"id": "https://doi.org/10.5281/zenodo.15181098",
4-
"version": "0.1.0",
3+
"id": "https://doi.org/10.5281/zenodo.15211029",
4+
"version": "0.1.2",
55
"resources": [
66
{
77
"name": "bird_cube_belgium_mgrs10",
@@ -11,7 +11,7 @@
1111
"mediatype": "text/csv",
1212
"encoding": "utf-8",
1313
"title": "Occurrence cube for birds in Belgium (MGRS 10 km)",
14-
"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.",
14+
"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.",
1515
"sources": [
1616
{
1717
"title": "GBIF Occurrence Download",
@@ -64,10 +64,10 @@
6464
},
6565
{
6666
"name": "mgrs10_refgrid_belgium",
67-
"path": "mgrs10_refgrid_belgium.geojson",
68-
"format": "geojson",
67+
"path": "mgrs10_refgrid_belgium.gpkg",
68+
"format": "gpkg",
6969
"title": "MGRS 10 km reference grid Belgium",
70-
"description": "MGRS 10 km reference grid for the mainland of Belgium.",
70+
"description": "MGRS 10 km reference grid for the mainland of Belgium. EPSG:32631 (WGS 84 / UTM zone 31N).",
7171
"licenses": [
7272
{
7373
"name": "CC0-1.0",

inst/en_gb.dic

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
Daele
22
EEA
33
GeoJSON
4+
GeoPackage
45
Havenlaan
56
Langeraert
67
MGRS
78
NC
89
Rproj
910
Teirlinckgebouw
11+
WGS
1012
cff
1113
dic
1214
gb

source/R/download_occ_cube.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ download_occ_cube <- function(sql_query, file, path, overwrite = FALSE) {
66
# Stop if overwrite = FALSE and file does not exist
77
file_path <- file.path(path, file)
88
if (file.exists(file_path) && !overwrite) {
9-
message(paste("File already exists. Reading existing file.",
10-
"Set `overwrite = TRUE` to overwrite file.", sep = "\n"))
9+
message(
10+
paste("File already exists. Reading existing file.",
11+
"Set `overwrite = TRUE` to overwrite file.", sep = "\n")
12+
)
1113

1214
occ_cube <- readr::read_csv(file = file_path, show_col_types = FALSE)
1315

@@ -34,7 +36,8 @@ download_occ_cube <- function(sql_query, file, path, overwrite = FALSE) {
3436
readr::write_csv(
3537
x = occ_cube,
3638
file = file_path,
37-
append = FALSE)
39+
append = FALSE
40+
)
3841

3942
# Return tibble
4043
return(occ_cube)

source/add_spatial_resources.Rmd

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Add spatial data resources to b3data frictionless data package.
3939

4040
# Methods
4141

42-
This report focuses on adding spatial resources (e.g. GeoJSON, raster) to the **b3data** frictionless data package.
42+
This report focuses on adding spatial resources (e.g. GeoPackage, raster) to the **b3data** frictionless data package.
4343

4444
## Source Data
4545

@@ -57,7 +57,7 @@ Example:
5757

5858
Each dataset includes the following metadata (see: [Frictionless resource spec](https://docs.ropensci.org/frictionless/articles/data-resource.html#properties-implementation)):
5959

60-
- **format**: e.g. `geojson`
60+
- **format**: e.g. `gpkg`
6161
- **title**: e.g. `"MGRS 10 km reference grid for Belgium"`
6262
- **description**: concise explanation of content
6363
- **sources**: source if applicable
@@ -77,20 +77,22 @@ ggplot() + geom_sf(data = utm10_bel)
7777
```
7878

7979
Clean data and transform cell codes to MGRS.
80+
Convert to EPSG:32631 (WGS 84 / UTM zone 31N).
8081

8182
```{r}
8283
mgrs10_refgrid_belgium <- utm10_bel %>%
8384
select(utm_tag = TAG, geometry) %>%
8485
mutate(mgrscode = ifelse(grepl("^[A-G]", utm_tag), paste0("31U", utm_tag),
8586
paste0("32U", utm_tag))) %>%
86-
select(mgrscode, geometry)
87+
select(mgrscode, geometry) %>%
88+
st_transform(32631)
8789
```
8890

8991
Write to data package and add metadata.
9092

9193
```{r}
9294
st_write(mgrs10_refgrid_belgium,
93-
file.path(package_path, "mgrs10_refgrid_belgium.geojson"),
95+
file.path(package_path, "mgrs10_refgrid_belgium.gpkg"),
9496
delete_dsn = TRUE)
9597
```
9698

@@ -101,25 +103,28 @@ b3data_package <- read_package(file.path(package_path, "datapackage.json"))
101103
# Add resource to data package
102104
mgrs10_resource <- list(
103105
name = "mgrs10_refgrid_belgium",
104-
path = "mgrs10_refgrid_belgium.geojson",
105-
format = "geojson",
106+
path = "mgrs10_refgrid_belgium.gpkg",
107+
format = "gpkg",
106108
title = "MGRS 10 km reference grid Belgium",
107-
description = "MGRS 10 km reference grid for the mainland of Belgium.",
109+
description = paste("MGRS 10 km reference grid for the mainland of Belgium.",
110+
"EPSG:32631 (WGS 84 / UTM zone 31N)."),
108111
licenses = list(list(
109112
name = "CC0-1.0",
110113
path = "https://creativecommons.org/publicdomain/zero/1.0/",
111114
title = "Creative Commons Zero v1.0 Universal"
112-
))
113-
)
115+
))
116+
)
114117
115118
b3data_package <- add_manual_resource(
116-
b3data_package, mgrs10_resource, replace = TRUE)
119+
b3data_package, mgrs10_resource, replace = TRUE
120+
)
117121
118122
# Write package to directory
119123
write_package(
120124
package = b3data_package,
121125
directory = package_path,
122-
compress = TRUE)
126+
compress = TRUE
127+
)
123128
```
124129

125130
## EEA 100 km reference grid Europe

source/create_b3data_package.Rmd

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Create [frictionless](https://docs.ropensci.org/frictionless/) data package with
3838
# Methods
3939

4040
This report focuses on creating the **b3data** frictionless data package for tabular datasets.
41-
A separate report adds spatial resources (e.g. GeoJSON, raster) to the same data package.
41+
A separate report adds spatial resources (e.g. GeoPackage, raster) to the same data package.
4242

4343
## Data Package Overview
4444

@@ -134,7 +134,7 @@ bird_cube_belgium_mgrs10_full <- download_occ_cube(
134134
)
135135
```
136136

137-
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`).
137+
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`).
138138

139139
```{r}
140140
# Read reference grid
@@ -166,8 +166,9 @@ b3data_package <- create_package() %>%
166166
"the temporal resolution is 'year'",
167167
"Spatial aggregation is done using the MGRS grid at 10 km scale.",
168168
"Only grid cells that fall within the 10 km MGRS reference grid for",
169-
"mainland Belgium (see b3data: `mgrs10_refgrid_belgium.geojson`) are",
170-
"included."),
169+
"mainland Belgium (see b3data: `mgrs10_refgrid_belgium.gpkg`) are",
170+
"included."
171+
),
171172
sources = list(list(
172173
title = "GBIF Occurrence Download",
173174
path = "https://doi.org/10.15468/dl.y3wpwk"
@@ -176,7 +177,7 @@ b3data_package <- create_package() %>%
176177
name = "CC0-1.0",
177178
path = "https://creativecommons.org/publicdomain/zero/1.0/",
178179
title = "Creative Commons Zero v1.0 Universal"
179-
))
180+
))
180181
)
181182
```
182183

@@ -193,10 +194,10 @@ b3data_package <- append(b3data_package,
193194
c(name = "b3data"),
194195
after = 0)
195196
b3data_package <- append(b3data_package,
196-
c(id = "https://doi.org/10.5281/zenodo.15181098"),
197+
c(id = "https://doi.org/10.5281/zenodo.15211029"),
197198
after = 1)
198199
b3data_package <- append(b3data_package,
199-
c(version = "0.1.0"),
200+
c(version = "0.1.2"),
200201
after = 2)
201202
202203
# Warning: append() drops the custom datapackage class.
@@ -215,5 +216,6 @@ dir.create(package_path, showWarnings = FALSE, recursive = TRUE)
215216
write_package(
216217
package = b3data_package,
217218
directory = package_path,
218-
compress = TRUE)
219+
compress = TRUE
220+
)
219221
```

0 commit comments

Comments
 (0)