From 3a21cf8891b503589334a3086150f5397ae3283c Mon Sep 17 00:00:00 2001 From: Christoph Zust Date: Tue, 5 Aug 2025 13:53:12 +0000 Subject: [PATCH 1/2] incorporate projected liegenschaften --- R/download_liegenschaften_layer.R | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/R/download_liegenschaften_layer.R b/R/download_liegenschaften_layer.R index 4651853..ab236f1 100644 --- a/R/download_liegenschaften_layer.R +++ b/R/download_liegenschaften_layer.R @@ -53,13 +53,13 @@ get_geo_info <- function(df_bp, sf_liegenschaften) { #' get_liegenschaften_layer("data", "your.email@example.com", "Monday") #' } get_liegenschaften_layer <- function(file_destination, email_address, retrieval_day) { - - sf_file <- paste0( + + current_liegenschaften <- paste0( file_destination, "/AV_MOpublic-_Liegenschaften_-OGD/AVZH_LIEGENSCHAFTEN_F.shp" ) - if (weekdays(Sys.Date()) == retrieval_day | !file.exists(sf_file)) { + if (weekdays(Sys.Date()) == retrieval_day | !file.exists(current_liegenschaften)) { dir.create(file_destination) url <- get_giszh_api_download_url(404, email_address) @@ -72,10 +72,19 @@ get_liegenschaften_layer <- function(file_destination, email_address, retrieval_ unzip(zip_file, exdir = file_destination) } - sf_liegenschaf <- sf::read_sf(sf_file) |> + sf_current_liegenschaf <- sf::read_sf(current_liegenschaften) |> + dplyr::rename_with(tolower) + + sf_projected_liegenschaf <- sf::read_sf( + paste0(file_destination, + "/AV_MOpublic-_Liegenschaften_-OGD/AVZH_LIEGENSCHAFTEN_PROJ_F.shp") + ) |> dplyr::rename_with(tolower) - return(sf_liegenschaf) + sf_liegenschaften <- rbind(sf_current_liegenschaf, + sf_projected_liegenschaf) + + return(sf_current_liegenschaf) } From 4e213aeab82e26c969bb4677f8e2d3d6b197a93b Mon Sep 17 00:00:00 2001 From: Christoph Zust Date: Wed, 6 Aug 2025 14:04:16 +0000 Subject: [PATCH 2/2] feat: introduce start- and end-date for mapping --- R/create_geo_output.R | 39 ++++++++++++++++--------- man/create_map.Rd | 25 ++++++++++++---- tests/testthat/test-create_geo_output.R | 3 +- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/R/create_geo_output.R b/R/create_geo_output.R index a38b4b1..4fd3bd7 100644 --- a/R/create_geo_output.R +++ b/R/create_geo_output.R @@ -84,15 +84,18 @@ add_spatial_information <- function(df_bp, sf_liegenschaften) { #' #' Generates an interactive Leaflet map from spatial building permit data. #' Each polygon includes a popup with details such as publication number, -#' publication date, entry deadline, address, and overlapping permits. +#' publication date, entry deadline, address, and overlapping permits. The +#' default observation period is set to 20 days, as this is the timeframe during +#' which objections to the project can be submitted. #' #' @param sf_bp_geo An `sf` object containing spatial building permit data, -#' including #' attributes such as `publicationNumber`, `entryDeadline`, +#' including attributes such as `publicationNumber`, `entryDeadline`, #' `address`, and `url`. -#' @param days_of_data Integer or Character. If a numeric value is provided, it -#' specifies the number of days in the past from which to retrieve publications. -#' If set to `"all"`, all publications will be displayed starting from January 2025. -#' +#' @param start_date A character date in the format "yyyy-mm-dd" representing the +#' first day for which data should be included. +#' first day for which data should be included. +#' @param end_date A character date in the format "yyyy-mm-dd" representing the +#' the last day for which data should be included. #' @return A Leaflet map widget displaying the building permit polygons and #' associated information. #' @@ -100,19 +103,29 @@ add_spatial_information <- function(df_bp, sf_liegenschaften) { #' #' @examples #' \dontrun{ +#' # creating a map of the last 20 days #' create_map(sf_bp_geo) +#' +#' # customize period of retrieval +#' sf_bp_geo |> +#' create_map(start_date = "20205-01-01", end_date = "2025-07-15") #' } -create_map <- function(sf_bp_geo, days_of_data = 20) { - - if (days_of_data != "all"){ - start_date = as.character(Sys.Date()-days_of_data) - } else { - start_date = "2025-01-01" +create_map <- function(sf_bp_geo, + start_date = as.character(Sys.Date()-20), + end_date = as.character(Sys.Date())) { + + if (start_date < "2025-01-01") { + cli::cli_warn("There are no geo-referenced building permit applications before 2025-01-01.") } sf_bp_geo <- sf_bp_geo |> - dplyr::filter(publicationDate >= start_date) + dplyr::filter(publicationDate >= start_date & publicationDate <= end_date) + if (nrow(sf_bp_geo) == 0) { + cli::cli_abort("There are no building permit application for this period.") + } + + #### intersected_poly <- sf_bp_geo |> sf::st_intersects() diff --git a/man/create_map.Rd b/man/create_map.Rd index 2eee364..3e8d3f1 100644 --- a/man/create_map.Rd +++ b/man/create_map.Rd @@ -4,16 +4,23 @@ \alias{create_map} \title{Create an Interactive Leaflet Map of Building Permits} \usage{ -create_map(sf_bp_geo, days_of_data = 20) +create_map( + sf_bp_geo, + start_date = as.character(Sys.Date() - 20), + end_date = as.character(Sys.Date()) +) } \arguments{ \item{sf_bp_geo}{An \code{sf} object containing spatial building permit data, -including #' attributes such as \code{publicationNumber}, \code{entryDeadline}, +including attributes such as \code{publicationNumber}, \code{entryDeadline}, \code{address}, and \code{url}.} -\item{days_of_data}{Integer or Character. If a numeric value is provided, it -specifies the number of days in the past from which to retrieve publications. -If set to \code{"all"}, all publications will be displayed starting from January 2025.} +\item{start_date}{A character date in the format "yyyy-mm-dd" representing the +first day for which data should be included. +first day for which data should be included.} + +\item{end_date}{A character date in the format "yyyy-mm-dd" representing the +the last day for which data should be included.} } \value{ A Leaflet map widget displaying the building permit polygons and @@ -22,10 +29,16 @@ associated information. \description{ Generates an interactive Leaflet map from spatial building permit data. Each polygon includes a popup with details such as publication number, -publication date, entry deadline, address, and overlapping permits. +publication date, entry deadline, address, and overlapping permits. The +default observation period is set to 20 days, as this is the timeframe during +which objections to the project can be submitted. } \examples{ \dontrun{ +# creating a map of the last 20 days create_map(sf_bp_geo) + +# customize period of retrieval +create_map(start_date = "20205-01-01", end_date = "2025-07-15") } } diff --git a/tests/testthat/test-create_geo_output.R b/tests/testthat/test-create_geo_output.R index b1b8449..c5ace1d 100644 --- a/tests/testthat/test-create_geo_output.R +++ b/tests/testthat/test-create_geo_output.R @@ -37,7 +37,8 @@ testthat::test_that("a map is create", { crs = 2056 ) - map <- sf_map_test |> create_map(days_of_data = "all") + map <- sf_map_test |> create_map(start_date = "2025-01-01", + end_date = "2025-07-15") testthat::expect_equal(inherits(map, "leaflet"), TRUE) })