Skip to content

Commit

Permalink
Merge pull request #37 from dieghernan/master
Browse files Browse the repository at this point in the history
Lintr
  • Loading branch information
dieghernan authored Aug 4, 2023
2 parents b523bae + 91bf9a4 commit 6b6f65e
Show file tree
Hide file tree
Showing 30 changed files with 192 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
needs: coverage

- name: Test coverage
run: |
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE
Expand Down
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Type: Package
Package: CatastRo
Title: Interface to the API 'Sede Electronica Del Catastro'
Version: 0.2.3
Expand Down
20 changes: 10 additions & 10 deletions R/atom_ad.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#' municipality using the INSPIRE ATOM service.
#'
#' @references
#' [API Documentation](https://www.catastro.minhap.es/webinspire/documentos/inspire-ATOM.pdf)
#' [API
#' Documentation](https://www.catastro.minhap.es/webinspire/documentos/inspire-ATOM.pdf)
#'
#' [INSPIRE Services for Cadastral Cartography](https://www.catastro.minhap.es/webinspire/index.html)
#' [INSPIRE Services for Cadastral
#' Cartography](https://www.catastro.minhap.es/webinspire/index.html)
#'
#'
#' @family INSPIRE
Expand Down Expand Up @@ -59,10 +61,7 @@ catr_atom_get_address <- function(munic,
all <- all[linesto, ]
} else {
if (verbose) {
message(
"Ignoring 'to' parameter. No results for ",
to
)
message("Ignoring 'to' parameter. No results for ", to)
}
}
}
Expand All @@ -85,7 +84,8 @@ catr_atom_get_address <- function(munic,
)
}

municurls <- catr_atom_get_address_db_to(as.character(m$territorial_office),
municurls <- catr_atom_get_address_db_to(
as.character(m$territorial_office),
cache = cache,
update_cache = update_cache,
cache_dir = cache_dir,
Expand All @@ -95,9 +95,9 @@ catr_atom_get_address <- function(munic,
ref <- unlist(strsplit(m$munic, "-"))[1]

# Download from url
api_entry <- municurls[grepl(ref, municurls$munic,
ignore.case = TRUE
), ]$url
api_entry <- municurls[
grepl(ref, municurls$munic, ignore.case = TRUE),
]$url

filename <- basename(api_entry)

Expand Down
28 changes: 13 additions & 15 deletions R/atom_bu.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#' using the INSPIRE ATOM service.
#'
#' @references
#' [API Documentation](https://www.catastro.minhap.es/webinspire/documentos/inspire-ATOM.pdf)
#' [API
#' Documentation](https://www.catastro.minhap.es/webinspire/documentos/inspire-ATOM.pdf)
#'
#' [INSPIRE Services for Cadastral Cartography](https://www.catastro.minhap.es/webinspire/index.html)
#' [INSPIRE Services for Cadastral
#' Cartography](https://www.catastro.minhap.es/webinspire/index.html)
#'
#' @family INSPIRE
#' @family ATOM
Expand Down Expand Up @@ -74,10 +76,7 @@ catr_atom_get_buildings <- function(munic,
all <- all[linesto, ]
} else {
if (verbose) {
message(
"Ignoring 'to' parameter. No results for ",
to
)
message("Ignoring 'to' parameter. No results for ", to)
}
}
}
Expand All @@ -87,7 +86,8 @@ catr_atom_get_buildings <- function(munic,
if (is.na(findmunic)) {
message(
"No Municipality found for ", munic, " ", to,
". Check available municipalities with catr_atom_get_buildings_db_all()"
". Check available municipalities with ",
"catr_atom_get_buildings_db_all()"
)
return(invisible(NA))
}
Expand All @@ -100,7 +100,8 @@ catr_atom_get_buildings <- function(munic,
)
}

municurls <- catr_atom_get_buildings_db_to(as.character(m$territorial_office),
municurls <- catr_atom_get_buildings_db_to(
as.character(m$territorial_office),
cache = cache,
update_cache = update_cache,
cache_dir = cache_dir,
Expand All @@ -110,9 +111,9 @@ catr_atom_get_buildings <- function(munic,
ref <- unlist(strsplit(m$munic, "-"))[1]

# Download from url
api_entry <- municurls[grepl(ref, municurls$munic,
ignore.case = TRUE
), ]$url
api_entry <- municurls[
grepl(ref, municurls$munic, ignore.case = TRUE),
]$url

filename <- basename(api_entry)

Expand All @@ -125,10 +126,7 @@ catr_atom_get_buildings <- function(munic,
# To a new directory
# Get cached dir
cache_dir <- catr_hlp_cachedir(cache_dir)
exdir <- file.path(
cache_dir,
gsub(".zip$", "", filename)
)
exdir <- file.path(cache_dir, gsub(".zip$", "", filename))

if (!dir.exists(exdir)) dir.create(exdir, recursive = TRUE)
unzip(path, exdir = exdir, junkpaths = TRUE, overwrite = TRUE)
Expand Down
15 changes: 9 additions & 6 deletions R/atom_cp.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#' municipality using the INSPIRE ATOM service.
#'
#' @references
#' [API Documentation](https://www.catastro.minhap.es/webinspire/documentos/inspire-ATOM.pdf)
#' [API
#' Documentation](https://www.catastro.minhap.es/webinspire/documentos/inspire-ATOM.pdf)
#'
#' [INSPIRE Services for Cadastral Cartography](https://www.catastro.minhap.es/webinspire/index.html)
#' [INSPIRE Services for Cadastral
#' Cartography](https://www.catastro.minhap.es/webinspire/index.html)
#'
#' @family INSPIRE
#' @family ATOM
Expand Down Expand Up @@ -94,7 +96,8 @@ catr_atom_get_parcels <- function(munic,
)
}

municurls <- catr_atom_get_parcels_db_to(as.character(m$territorial_office),
municurls <- catr_atom_get_parcels_db_to(
as.character(m$territorial_office),
cache = cache,
update_cache = update_cache,
cache_dir = cache_dir,
Expand All @@ -104,9 +107,9 @@ catr_atom_get_parcels <- function(munic,
ref <- unlist(strsplit(m$munic, "-"))[1]

# Download from url
api_entry <- municurls[grepl(ref, municurls$munic,
ignore.case = TRUE
), ]$url
api_entry <- municurls[
grepl(ref, municurls$munic, ignore.case = TRUE),
]$url

filename <- basename(api_entry)

Expand Down
7 changes: 5 additions & 2 deletions R/cache_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ catr_hlp_detect_cache_dir <- function() {
cached_path <- readLines(cache_config)

# Case on empty cached path - would default
if (is.null(cached_path) ||
is.na(cached_path) || cached_path == "") {
if (any(
is.null(cached_path),
is.na(cached_path),
cached_path == ""
)) {
cache_dir <- catr_set_cache_dir(
overwrite = TRUE,
verbose = FALSE
Expand Down
3 changes: 2 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#'
#' @references
#' * [OVCCoordenadas](https://ovc.catastro.meh.es/ovcservweb/ovcswlocalizacionrc/ovccoordenadas.asmx)
#' * [INSPIRE WFS Service](https://www.catastro.minhap.es/webinspire/index.html)
#' * [INSPIRE WFS
#' Service](https://www.catastro.minhap.es/webinspire/index.html)
#'
#' @encoding UTF-8
#'
Expand Down
3 changes: 2 additions & 1 deletion R/ovc_munic.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#' @param cmun Code of a municipality, as recorded on the Spanish Cadastre.
#' @param cmun_ine Code of a municipality, as recorded on National Statistics
#' Institute. See
#' [INE: List of municipalities](https://www.ine.es/en/daco/daco42/codmun/codmunmapa_en.htm)
#' [INE: List of
#' . municipalities](https://www.ine.es/en/daco/daco42/codmun/codmunmapa_en.htm)
#'
#' @details
#' Parameter `cpro` is mandatory. Either `cmun` or `cmun_ine` should be
Expand Down
11 changes: 7 additions & 4 deletions R/utils_atom.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
catr_read_atom <- function(file, top = TRUE, encoding = "UTF-8") {
# Encoding error sometimes, thanks @dr_xeo
feed <- try(xml2::as_list(xml2::read_xml(file,
options = "NOCDATA",
encoding = encoding
)), silent = TRUE)
feed <- try(
xml2::as_list(xml2::read_xml(file,
options = "NOCDATA",
encoding = encoding
)),
silent = TRUE
)

# On error try without encoding
if (inherits(feed, "try-error")) {
Expand Down
27 changes: 15 additions & 12 deletions R/utils_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ catr_hlp_dwnload <- function(api_entry, filename, cache_dir,
} else if (update_cache || isFALSE(localfile)) {
dwnload <- TRUE
if (verbose) {
message(
"Downloading file from ",
url
)
message("Downloading file from ", url)
}
if (verbose && update_cache) {
message("\nUpdating cache")
Expand All @@ -42,19 +39,25 @@ catr_hlp_dwnload <- function(api_entry, filename, cache_dir,

# Downloading
if (dwnload) {
err_dwnload <- try(download.file(url, filepath,
quiet = isFALSE(verbose),
mode = "wb"
), silent = TRUE)
err_dwnload <- try(
download.file(url, filepath,
quiet = isFALSE(verbose),
mode = "wb"
),
silent = TRUE
)

# nocov start
# On error retry
if (inherits(err_dwnload, "try-error")) {
if (verbose) message("Retrying query")
err_dwnload <- try(download.file(url, filepath,
quiet = isFALSE(verbose),
mode = "wb"
), silent = TRUE)
err_dwnload <- try(
download.file(url, filepath,
quiet = isFALSE(verbose),
mode = "wb"
),
silent = TRUE
)
}
# nocov end

Expand Down
20 changes: 11 additions & 9 deletions R/utils_read.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
st_read_layers_encoding <- function(path, verbose) {
# Layer management and errors
layers <- tryCatch(sf::st_layers(path),
layers <- tryCatch(
sf::st_layers(path),
warning = function(e) {
return(NULL)
},
Expand All @@ -12,9 +13,7 @@ st_read_layers_encoding <- function(path, verbose) {
# If NULL change to a new tempfile and retry
# This may be an error on encoding
if (is.null(layers)) {
newlines <- readLines(path,
encoding = "ISO-8859-1"
)
newlines <- readLines(path, encoding = "ISO-8859-1")

# Thanks @santiagomota #19
newlines <- stringi::stri_trans_general(newlines, "latin-ascii")
Expand All @@ -29,7 +28,7 @@ st_read_layers_encoding <- function(path, verbose) {
geomtype = unlist(layers$geomtype)
)

if (nrow(df_layers) == 0 || !"geomtype" %in% names(df_layers)) {
if (any(nrow(df_layers) == 0, !"geomtype" %in% names(df_layers))) {
message("No spatial layers found.")
return(invisible(NULL))
}
Expand All @@ -44,10 +43,13 @@ st_read_layers_encoding <- function(path, verbose) {
# nocov end


out <- try(sf::st_read(path,
layer = df_layers$layer[1],
quiet = !verbose
), silent = TRUE)
out <- try(
sf::st_read(path,
layer = df_layers$layer[1],
quiet = !verbose
),
silent = TRUE
)

# It may be an error, check
if (inherits(out, "try-error")) {
Expand Down
11 changes: 7 additions & 4 deletions R/utils_wfs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
catr_wfs_get_buildingsild_url <- function(host = "http://ovc.catastro.meh.es/INSPIRE/",
entry,
params) {
catr_wfs_get_buildingsild_url <- function(
host = "http://ovc.catastro.meh.es/INSPIRE/",
entry,
params) {
# Clean empty params
params <- params[lengths(params) != 0]

Expand Down Expand Up @@ -37,7 +38,9 @@ catr_wfs_check <- function(path) {
#' object and in case of error a message to display
#'
#' @noRd
wfs_api_query <- function(entry, ..., verbose = TRUE) {
wfs_api_query <- function(
entry, ...,
verbose = TRUE) {
arguments <- list(...)

# Handle SRS. Is optional but if provided check
Expand Down
10 changes: 6 additions & 4 deletions R/wfs_bu.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
#' @return A `sf` object.
#'
#' @references
#' [API Documentation](https://www.catastro.minhap.es/webinspire/documentos/inspire-bu-WFS.pdf)
#' [API
#' Documentation](https://www.catastro.minhap.es/webinspire/documentos/inspire-bu-WFS.pdf)
#'
#' [INSPIRE Services for Cadastral Cartography](https://www.catastro.minhap.es/webinspire/index.html)
#' [INSPIRE Services for Cadastral
#' Cartography](https://www.catastro.minhap.es/webinspire/index.html)
#'
#' @details
#'
Expand Down Expand Up @@ -92,8 +94,8 @@ catr_wfs_get_buildings_bbox <- function(x, what = "building", srs,
#' - By cadastral reference: Implemented on `catr_wfs_get_buildings_rc()`.
#' Extract objects of specific cadastral references.
#'
#' Check the
#' [API Docs](https://www.catastro.minhap.es/webinspire/documentos/inspire-bu-WFS.pdf).
#' Check the [API
#' Docs](https://www.catastro.minhap.es/webinspire/documentos/inspire-bu-WFS.pdf).
#'
#' @param rc The cadastral reference to be extracted.
#'
Expand Down
3 changes: 2 additions & 1 deletion R/wfs_cp.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#' @references
#' [API Documentation](https://www.catastro.minhap.es/webinspire/documentos/inspire-cp-WFS.pdf)
#'
#' [INSPIRE Services for Cadastral Cartography](https://www.catastro.minhap.es/webinspire/index.html)
#' [INSPIRE Services for Cadastral
#' Cartography](https://www.catastro.minhap.es/webinspire/index.html)
#'
#' @details
#'
Expand Down
Loading

0 comments on commit 6b6f65e

Please sign in to comment.