Skip to content

Commit

Permalink
v1.12.3 - housekeeping (#100)
Browse files Browse the repository at this point in the history
* buggy documentation of katastry()

* cran comments for v1.12.2

* purge mapview from examples

* cleaner history / s2 artefacts removed

* upgrade http >> https in readme

* housekeeping - citation, readme, description, vignette updated to current best practices

* readxl purged from vignettw
  • Loading branch information
jlacko authored Nov 25, 2024
1 parent 10f6787 commit a640d2f
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 189 deletions.
255 changes: 100 additions & 155 deletions CITATION.cff

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: RCzechia
Type: Package
Title: Spatial Objects of the Czech Republic
Version: 1.12.2
Date: 2024-07-07
Version: 1.12.3
Date: 2024-11-25
Authors@R: c(
person("Jindra", "Lacko", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-0375-5156")),
Expand All @@ -26,18 +26,12 @@ Imports:
magrittr
Suggests:
terra,
readxl,
units,
ggplot2,
tidyterra,
stringr,
rvest,
xml2,
scales,
knitr,
testthat,
roxygen2,
devtools,
rmarkdown,
dplyr,
lwgeom,
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## version 1.12.3

- history objects updated to return cleaner geometry

- minor updates in README + CITATION.cff

- removed unnecessary dependencies

## version 1.12.2 (2024-07-07)

- katastry function added to serve cadastral areas / katastrální území
Expand Down
2 changes: 1 addition & 1 deletion R/historie.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ historie <- function(era) {
stop(paste(era, "is not a valid historical era!"))
}

result <- .downloader(paste0("history_", era, ".rds"))
result <- .downloader(paste0("history_", era, "v2.rds"))
result
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# RCzechia
<!-- badges: start -->
[![R-CMD-check](https://github.com/jlacko/RCzechia/workflows/R-CMD-check/badge.svg)](https://github.com/jlacko/RCzechia/actions/workflows/R-CMD-check.yaml)
[![CRAN](http://www.r-pkg.org/badges/version/RCzechia)](https://cran.r-project.org/package=RCzechia)
[![CRAN](https://www.r-pkg.org/badges/version/RCzechia)](https://cran.r-project.org/package=RCzechia)
[![CRAN-checks](https://badges.cranchecks.info/worst/RCzechia.svg)](https://cran.r-project.org/web/checks/check_results_RCzechia.html)
[![Codecov test coverage](https://codecov.io/gh/jlacko/RCzechia/branch/master/graph/badge.svg)](https://app.codecov.io/gh/jlacko/RCzechia?branch=master)
[![Downloads-weekly](http://cranlogs.r-pkg.org/badges/last-week/RCzechia?color=brightgreen)](https://cran.r-project.org/package=RCzechia)
[![Downloads-total](http://cranlogs.r-pkg.org/badges/grand-total/RCzechia?color=brightgreen)](https://cran.r-project.org/package=RCzechia)
[![Downloads-weekly](https://cranlogs.r-pkg.org/badges/last-week/RCzechia?color=brightgreen)](https://cran.r-project.org/package=RCzechia)
[![Downloads-total](https://cranlogs.r-pkg.org/badges/grand-total/RCzechia?color=brightgreen)](https://cran.r-project.org/package=RCzechia)
[![DOI](https://zenodo.org/badge/97862932.svg)](https://zenodo.org/badge/latestdoi/97862932)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.05082/status.svg)](https://doi.org/10.21105/joss.05082)
<!-- badges: end -->
Expand Down
50 changes: 50 additions & 0 deletions data-raw/digest-historie.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
library(sf)
library(arcpullr)

remote_target <- "https://services1.arcgis.com/LPm07959azIAvFRD/ArcGIS/rest/services/urrlab_historicky_gis_cesko/FeatureServer/"

objekty <- list( "3" = "okresy_1921",
"4" = "okresy_1930",
"2" = "okresy_1947",
"6" = "okresy_1950",
"7" = "okresy_1961",
"8" = "okresy_1970",
"9" = "okresy_1980",
"10" = "okresy_1991",
"11" = "okresy_2001",
"12" = "okresy_2011",
"13" = "kraje_1950",
"14" = "kraje_1961",
"15" = "kraje_1970",
"16" = "kraje_1980",
"17" = "kraje_1991",
"18" = "kraje_2001",
"19" = "kraje_2011")


for (i in seq_along(objekty)) {

wrk_objekt <- arcpullr::get_spatial_layer(paste0(remote_target, names(objekty)[i]))

info <- arcpullr::get_layer_info(paste0(remote_target, names(objekty)[i]))

clean_objekt <- wrk_objekt %>%
st_make_valid() %>%
st_transform(4326)

colnames(clean_objekt) <- c(info$fields$alias, "geometry")

st_geometry(clean_objekt) <- "geometry"

duplicity <- which(duplicated(colnames(clean_objekt))) # indexy duplictních názvů sloupců

clean_objekt <- clean_objekt[, -duplicity] # duplicitní sloupce ven!

if((st_crs(clean_objekt)$input == "EPSG:4326") & all(st_is_valid(clean_objekt))) {
saveRDS(clean_objekt, paste0("./data-backup/history_", objekty[i], "v2.rds"))
} else {
warning(paste(objekty[i], "je nevalidní, ještě jednou a pořádně!!"))
}

}

1 change: 1 addition & 0 deletions generate-vignette.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ system("rm ./vignettes/*")
knit("./vignette.Rmd.orig",
output = "./vignettes/vignette.Rmd")
system("mv ./*.png ./vignettes/")

2 changes: 1 addition & 1 deletion tests/testthat/test-1-historie.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test_that("historie platí", {
expect_true("geometry" %in% colnames(historie(doba)))

# území je pokryté
expect_equal(sum(st_area(historie(doba))), st_area(republika("high")), tolerance = 5/100)
expect_equal(sum(st_area(historie(doba))), st_area(republika("high")), tolerance = 1/1000)

}

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-1-transport.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ test_that("silnice", {


# dálnic je méně jak silnic
expect_gt(sum(st_length(subset(silnice(), stringr::str_starts(silnice()$TRIDA, "Silnice")))),
sum(st_length(subset(silnice(), stringr::str_starts(silnice()$TRIDA, "Dálnice")))))
expect_gt(sum(st_length(subset(silnice(), grepl("Silnice", silnice()$TRIDA)))),
sum(st_length(subset(silnice(), grepl("Dálnice",silnice()$TRIDA)))))

# sloupce se nerozbily...
expect_equal(colnames(silnice()), c("TRIDA", "CISLO_SILNICE", "MEZINARODNI_OZNACENI", "geometry"))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-3-integrace.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test_that("integrace", {
expect_equal(sum(st_area(obce_polygony())), st_area(republika()), tolerance = 1/1000)

# v újezdech se nevolí...
vojaci <- filter(obce_polygony(), stringr::str_starts(NAZ_POU, "Vojenský újezd"))
vojaci <- filter(obce_polygony(), grepl("Vojenský újezd", NAZ_POU))
expect_equal(sum(st_area(volebni_okrsky("high"))), st_area(republika("high")) - sum(st_area(vojaci)), tolerance = 1/1000)

expect_equal(sum(st_area(senat_obvody("high"))), st_area(republika("high")), tolerance = 1/1000)
Expand Down
5 changes: 2 additions & 3 deletions vignette.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ output:
self_contained: no
vignette: >
%\VignetteIndexEntry{Solving Real World Issues With RCzechia}
%\VignetteDepends{readxl}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down Expand Up @@ -61,8 +60,8 @@ ggplot(data = okresni_data) +
labs(title = "Czech population",
fill = "population\n(log scale)") +
theme_bw() +
theme(legend.text.align = 1,
legend.title.align = 0.5)
theme(legend.text = element_text(hjust = 1),
legend.title = element_text(hjust = 0.5))
```

## Geocoding Locations & Drawing them on a Map
Expand Down
Binary file modified vignettes/brno-center-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/census-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/ctverce-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/geocode-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/senat-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 14 additions & 15 deletions vignettes/vignette.Rmd
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
title: "Solving Real World Issues With RCzechia"
author: "Jindra Lacko"
date: "2024-03-04"
date: "2024-11-25"
output:
rmarkdown::html_vignette:
toc: true
self_contained: no
vignette: >
%\VignetteIndexEntry{Solving Real World Issues With RCzechia}
%\VignetteDepends{readxl}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand All @@ -21,7 +20,7 @@ Population of the Czech Republic from the 2011 census, per district (okres). The
As the population distributed highly unevenly a log scale is used.


```r
``` r
library(RCzechia)
library(ggplot2)
library(readxl)
Expand All @@ -32,11 +31,11 @@ tf <- tempfile(fileext = ".xls") # a temporary xls file
GET("https://raw.githubusercontent.com/jlacko/RCzechia/master/data-raw/zvcr034.xls",
write_disk(tf))
## Response [https://raw.githubusercontent.com/jlacko/RCzechia/master/data-raw/zvcr034.xls]
## Date: 2024-03-04 13:47
## Date: 2024-11-25 14:10
## Status: 200
## Content-Type: application/octet-stream
## Size: 44.5 kB
## <ON DISK> /tmp/Rtmpa239co/file9a1ec35053513.xls
## <ON DISK> /tmp/Rtmpn3okFy/file20e11aee97ca.xls
src <- read_excel(tf, range = "Data!B5:C97") # read in with original column names

colnames(src) <- c("NAZ_LAU1", "obyvatel") # meaningful names instead of the original ones
Expand All @@ -58,8 +57,8 @@ ggplot(data = okresni_data) +
labs(title = "Czech population",
fill = "population\n(log scale)") +
theme_bw() +
theme(legend.text.align = 1,
legend.title.align = 0.5)
theme(legend.text = element_text(hjust = 1),
legend.title = element_text(hjust = 0.5))
```

<div class="figure" style="text-align: center">
Expand All @@ -74,7 +73,7 @@ Drawing a map: three semi-random landmarks on map, with rivers shown for better
To get the geocoded data frame function `RCzechia::geocode()` is used.


```r
``` r
library(RCzechia)
library(ggplot2)
library(sf)
Expand Down Expand Up @@ -118,7 +117,7 @@ Calculate distance between two spatial objects; the `sf` package supports (via g
Calculating distance from Prague (#1 Czech city) to Brno (#2 Czech city).


```r
``` r
library(dplyr)
library(RCzechia)
library(sf)
Expand All @@ -135,7 +134,7 @@ vzdalenost <- sf::st_distance(praha, brno) %>%

# report results
print(vzdalenost[1])
## 152.4636 [kilometers]
## 152.4642 [kilometers]
```

## Geographical Center of the City of Brno
Expand All @@ -147,7 +146,7 @@ The center is calculated using `sf::st_centroid()` and reversely geocoded via `R
Note the use of `reky("Brno")` to provide the parts of Svitava and Svratka relevant to a map of Brno city.


```r
``` r
library(dplyr)
library(RCzechia)
library(ggplot2)
Expand Down Expand Up @@ -192,7 +191,7 @@ Since Stamen Toner basemap no longer sparkles joy I have found a new favorite -
*Note*: it is technically impossible to make html in vignette interactive (and for good reasons). As a consequence the result of code shown has been replaced by a static screenshot; the code itself is legit.


```r
``` r
library(dplyr)
library(RCzechia)
library(leaflet)
Expand Down Expand Up @@ -233,7 +232,7 @@ This example covers a frequent use case:



```r
``` r
library(RCzechia)
library(ggplot2)
library(dplyr)
Expand Down Expand Up @@ -292,7 +291,7 @@ Package RCzechia supports two versions of relief visualization:
This example covers the first option.


```r
``` r
library(RCzechia)
library(ggplot2)
library(terra)
Expand Down Expand Up @@ -333,7 +332,7 @@ This example uses [`{rvest}`](https://rvest.tidyverse.org/) to scrape the offici
Since not all districts were up for election in this cycle two thirds of the map contain NA's; that is expected behavior (the Czech senate elections are staggered, like in the US).


```r
``` r

library(RCzechia)
library(ggplot2)
Expand Down

0 comments on commit a640d2f

Please sign in to comment.