etc/epsg/epsg_generate_db.R

# Build EPSG dataset (containing CRS' extents) ---------------------------------

# Steps done outside R ---------------------------------------------------------

# 1. Download latest dataset from EPSG group website.
#       - http://www.epsg.org/EPSGDataset/DownloadDataset.aspx.
# 2. Convert MDB database to newer format ACCDB.
# 3. Open database with Microsoft Access.
# 4. Export table Coordinate Reference System to a TXT format
#    (using UTF-8 as encoding).
# 5. Put exported table into etc/epsg. Name must be epsg_crs_VERSION.txt.
# 6. Repeat steps 1 to 5 each time a new version is released.
#    This script should be run overnight if possible.

# Packages ---------------------------------------------------------------------

library(curl)
library(data.table)
library(rvest)
library(stringr)
library(xml2)

# Source core function ---------------------------------------------------------

source(file.path("R", "get_bounds.R"))

# Import crs data --------------------------------------------------------------

crs  <- fread(file.path("etc", "epsg", "epsg_crs_v9_7.txt"))
code <- sort(crs[, COORD_REF_SYS_CODE])

# Get bounds from EPSG.io ------------------------------------------------------

# Split codes into chunks.
chnk <- split(code, ceiling(seq_along(code) / 100L))

# Loop over codes in chunk. Fetch and save in individual files.
# EPSG.io may block some transfers. Manual restarts of the chunks could be
# needed.
for(c in seq_along(chnk)[-c(1L:47)]) {
    for (x in chnk[[c]]) {
        cat("EPSG::", x, ".\n", sep = "")
        fn <- file.path("etc", "epsg", "bnds", paste0("epsg", x, ".rds"))
        saveRDS(get_bounds(x), file = fn)
    }; rm(x, fn)
}; rm(c)

# Build proper table of boundaries ---------------------------------------------

# Here.
jeanmathieupotvin/scr documentation built on Dec. 3, 2019, 8:53 p.m.