3 Templates and utilities

This chapter defines template files. They define the analysis space and ensure harmonisation of georeferenced data creation, and facilitate connection with other Latvian geodata.

3.1 Vector data

Baseline template (or reference) vector grid and point files are publically available at HiQBioDiv’s Zenodo repository. Command lines and data used to create these files are documented at the HiQBioDiv main code repository’s file.

The easiest way to obtain these files is to run determined function download_vector_templates() from {egvtools}.

Code
if(!require(egvtools)) {remotes::install_github("aavotins/egvtools"); require(egvtools)}

download_vector_templates(
  url = "https://zenodo.org/api/records/14277114/files-archive",
  grid_dir = "./Templates/TemplateGrids",
  points_dir = "./Templates/TemplateGridPoints",
  gpkg_dir = "./Templates",
  overwrite = FALSE,
  quiet = FALSE
)

Once template vector data are downloaded and unarchived, they need to be tiled:

  1. Analysis grid is tiled in tks50km pages
Code
if(!require(egvtools)) {remotes::install_github("aavotins/egvtools"); require(egvtools)}

tile_vector_grid(
  grid_path = "./Templates/TemplateGrids/tikls100_sauzeme.parquet",
  out_dir = "./Templates/TemplateGrids/tiles",
  tile_field = "tks50km",
  chunk_size = 50000L,
  overwrite = FALSE,
  quiet = FALSE
)

Expect to see warning: This is an initial implementation of Parquet/Feather file support and geo metadata. This is tracking version 0.1.0 of the metadata (https://github.com/geopandas/geo-arrow-spec). This metadata specification may change and does not yet make stability promises. We do not yet recommend using this in a production setting unless you are able to rewrite your Parquet/Feather files.

  1. Point files are tiled and buffered. In workflows creating EGVs described in this document, we used “sparse” grid:

    • 500m buffers around every 100m grids center;

    • 1250m buffers around every 100m grids center;

    • 3000m buffers around every 300m grids center (to speed up neighbourhood analysis ~9 times, while loosing <0.001% of precission);

    • 10000m buffers around every 1000m grids center (to speed up neighbourhood analysis ~100 times, while loosing <0.001% of precission)

Code
if(!require(egvtools)) {remotes::install_github("aavotins/egvtools"); require(egvtools)}

tiled_buffers(
  in_dir = "./Templates/TemplateGridPoints",
  out_dir = "./Templates/TemplateGridPoints/tiles",
  buffer_mode = "sparse",
  mapping_sparse = list("pts100_sauzeme.parquet" = c(500, 1250), 
                        "pts300_sauzeme.parquet" = 3000, 
                        "pts1000_sauzeme.parquet" = 10000),
  split_field = "tks50km",
  n_workers = 4,
  future_max_mem_gb = 4,
  overwrite = FALSE,
  quiet = FALSE
)

Expect to see warning: This is an initial implementation of Parquet/Feather file support and geo metadata. This is tracking version 0.1.0 of the metadata (https://github.com/geopandas/geo-arrow-spec). This metadata specification may change and does not yet make stability promises. We do not yet recommend using this in a production setting unless you are able to rewrite your Parquet/Feather files.

Apperance of file pts300_r3000_NA.parquet, i.e. without a tile number, is expected, due to slight mismatch of 300 m grid with the 50 km one.

3.2 Raster data

Baseline template (or reference) raster grid and point files are publically available at HiQBioDiv’s Zenodo repository. Command lines and data used to create these files are documented at the HiQBioDiv main code repository’s file.

The easiest way to obtain these files is to run determined function download_raster_templates() from {egvtools}.

Code
if(!require(egvtools)) {remotes::install_github("aavotins/egvtools"); require(egvtools)}

download_raster_templates(
  url = "https://zenodo.org/api/records/14497070/files-archive",
  out_dir = "./Templates/TemplateRasters",
  overwrite = TRUE,
  quiet = FALSE
)

During EGV creation background covering to deal with missing values may be necessary. All the EGVs described in this document where such an excercise might be necessary can be considered quantities of ratio scale, therefore backgrounds with value 0 are created.

Code
if(!require(egvtools)) {remotes::install_github("aavotins/egvtools"); require(egvtools)}

create_backgrounds(in_dir="./Templates/TemplateRasters/",
                   out_dir = "./Templates/TemplateRasters/",
                   background_value = 0,
                   out_prefix = "nulls_",
                   overwrite=TRUE)