Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
483a5a7
Do not use rgdal::readOGR(), remove arg "use_sf"
hsonne Apr 15, 2024
8016218
Get rid of dependency on rgdal, sp
hsonne Apr 15, 2024
b1e61d9
Do not use additional repository any more
hsonne Apr 16, 2024
47a8914
Do not evaluate chunks, set start and end date
hsonne Apr 16, 2024
60d8762
Add test for provide_projection_file()
hsonne Apr 16, 2024
eb23ec9
Add a test
hsonne Apr 16, 2024
ef7878e
Merge branch 'dev' into get-rid-of-rgdal
hsonne Apr 18, 2024
6344edc
Make VignetteIndexEntry consistent with title
hsonne Apr 18, 2024
9ffadf6
Let list_grids_germany() be silent
hsonne Apr 18, 2024
e41e891
Use helper variable "file"
hsonne Apr 18, 2024
e52b5b8
Add tests, change defaults to last month only
hsonne Apr 18, 2024
484a183
Implement test for read_asc_file()
hsonne Apr 18, 2024
a9840dc
Return the path to the projection file
hsonne Apr 18, 2024
7a4a9a1
Use/import capture.output() where necessary
hsonne Apr 19, 2024
6338cce
Fix test, not that path to file is returned
hsonne Apr 19, 2024
425a07e
Update dataset "dwd_files"
hsonne Apr 19, 2024
5c8c5f5
Add argument "radolan"
hsonne Apr 19, 2024
b15ba1e
Update documentation of dataset "dwd_files"
hsonne Apr 19, 2024
bfbbcd4
Move R-scripts to "extdata/scripts"
hsonne Apr 19, 2024
0bbad62
Provide RADOLAN projection files
hsonne Apr 19, 2024
61ac3e6
Provide .prj files in "extdata/projections"
hsonne Apr 19, 2024
cbb12b1
Let default_projection_file() point to local file
hsonne Apr 19, 2024
bc8837c
Determine EPSG codes and provide dataset
hsonne Apr 19, 2024
29ae694
Resolve "base_url" in documentation
hsonne Apr 19, 2024
d51b57c
Try to fix the test
hsonne Apr 19, 2024
170fdfb
Add function to guess EPSG code based on URL
hsonne Apr 19, 2024
36665be
Add tests for get_epsg_from_url()
hsonne Apr 19, 2024
fcc1fb9
Fix, document, export, test get_epsg_from_url()
hsonne Apr 20, 2024
15277a4
Add argument "crs" to read_asc_[gz_]file()
hsonne Apr 20, 2024
e3c8c03
Fix example in get_epsg_from_url.R
hsonne Apr 20, 2024
f550178
Document the "crs" argument
hsonne Apr 20, 2024
7537dc1
Fix example for get_epsg_from_url()
hsonne Apr 20, 2024
44b12b4
Resolve conflict, update Rd file
hsonne Apr 20, 2024
2512924
Do not run example that gives an error message
hsonne Apr 20, 2024
79eff59
Implement raster_stats() for "SpatRaster" objects
hsonne Apr 21, 2024
618619d
Read ASC file with terra instead of raster package
hsonne Apr 21, 2024
74d7bfa
Improve interface to high level function
hsonne Apr 21, 2024
203ac18
Make the test run silently
hsonne Apr 21, 2024
b058afa
Update NAMESPACE
hsonne Apr 21, 2024
e6d16e0
Add "terra" to "Imports:"
hsonne Apr 21, 2024
c143503
Improve output of read_asc_file()
hsonne Apr 21, 2024
7edddda
Cleanup test script, add plots for crs validation
hsonne Apr 21, 2024
74a64cb
Drop z dimensions first in read_shape_file()
hsonne Apr 21, 2024
7666f2c
Use terra::names() to get grid name
hsonne Apr 21, 2024
a3cd895
Unify wrappers, pass args to read_data_over_shape()
hsonne Apr 21, 2024
86d3a94
Let read_shape_file() tranform coordinates
hsonne Apr 21, 2024
5608bd9
Set arguments by name, reindent
hsonne Apr 21, 2024
73f0d6d
Set the coordinate reference system
hsonne Apr 21, 2024
7720013
Adapt test scripts
hsonne Apr 21, 2024
ae250db
Use terra::mask and terra::crop
mrustl Apr 22, 2024
6f11ea6
Only use working GH actions routine
mrustl Apr 22, 2024
a137b72
Improvements for release
mrustl Apr 22, 2024
117e216
terra::names() is not exported, use names()
hsonne May 24, 2024
20c814d
Add argument "from_prj_file"
hsonne May 24, 2024
898a585
Add test scripts
hsonne May 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 0 additions & 92 deletions .github/workflows/R-CMD-check.yaml

This file was deleted.

9 changes: 3 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ Imports:
lubridate (>= 1.7.4),
magrittr (>= 1.5),
raster (>= 2.8),
rgdal (>= 1.5-31),
RCurl (>= 1.95.4.11),
sf (>= 0.7.4),
sp (>= 1.3.1),
stringr (>= 1.4.0)
stringr (>= 1.4.0),
terra (>= 1.7)
Suggests:
covr (>= 3.2.1),
knitr (>= 1.22),
Expand All @@ -55,11 +54,9 @@ VignetteBuilder:
knitr
Remotes:
github::kwb-r/kwb.utils
Additional_repositories:
https://packagemanager.posit.co/cran/2023-09-20/
Encoding: UTF-8
LazyData: true
LazyDataCompression: bzip2
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2019-2022 Kompetenzzentrum Wasser Berlin gGmbH (KWB)
Copyright (c) 2019-2024 Kompetenzzentrum Wasser Berlin gGmbH (KWB)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2019-2022 Kompetenzzentrum Wasser Berlin gGmbH (KWB)
Copyright (c) 2019-2024 Kompetenzzentrum Wasser Berlin gGmbH (KWB)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 6 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(download_shapes_germany)
export(extract_radolan_zip_files)
export(get_berlin_dwd_mask)
export(get_dwd_urls_metadata)
export(get_epsg_from_url)
export(get_example_grid_germany)
export(get_radolan_extension)
export(get_radolan_projection_string)
Expand Down Expand Up @@ -38,7 +39,6 @@ importFrom(bitops,bitAnd)
importFrom(fs,dir_create)
importFrom(kwb.utils,assertFinalSlash)
importFrom(kwb.utils,backspace)
importFrom(kwb.utils,callWith)
importFrom(kwb.utils,catAndRun)
importFrom(kwb.utils,catIf)
importFrom(kwb.utils,clearConsole)
Expand Down Expand Up @@ -66,31 +66,32 @@ importFrom(kwb.utils,setColumns)
importFrom(kwb.utils,space)
importFrom(kwb.utils,stopFormatted)
importFrom(kwb.utils,stringList)
importFrom(kwb.utils,tempSubdirectory)
importFrom(lubridate,month)
importFrom(lubridate,rollback)
importFrom(lubridate,ymd)
importFrom(magrittr,"%>%")
importFrom(raster,`crs<-`)
importFrom(raster,cellStats)
importFrom(raster,crop)
importFrom(raster,extent)
importFrom(raster,flip)
importFrom(raster,projection)
importFrom(raster,raster)
importFrom(raster,stack)
importFrom(raster,writeRaster)
importFrom(rgdal,readOGR)
importFrom(sf,as_Spatial)
importFrom(sf,st_as_sf)
importFrom(sf,st_buffer)
importFrom(sf,st_crs)
importFrom(sf,st_read)
importFrom(sf,st_transform)
importFrom(sf,st_zm)
importFrom(sp,CRS)
importFrom(stats,sd)
importFrom(stats,setNames)
importFrom(stringr,str_replace)
importFrom(terra,`crs<-`)
importFrom(terra,rast)
importFrom(utils,browseURL)
importFrom(utils,capture.output)
importFrom(utils,download.file)
importFrom(utils,head)
importFrom(utils,read.csv)
Expand Down
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# kwb.dwd 0.3.0 (2023-05-23)
# kwb.dwd 0.3.0 (2024-04-xx)

* update/improve/fix GitHub actions workflow files
* depend on R >= 3.5.0 (Required by R CMD check)
Expand Down Expand Up @@ -95,7 +95,7 @@
* Install `rgdal` dependency from CRAN`s GitHub account (as it has been archived
since 2023-10-16, see [here](https://cran.r-project.org/web/packages/rgdal/index.html)).

# kwb.dwd 0.2.0 (2022-09-20)
# [kwb.dwd 0.2.0](https://github.com/KWB-R/kwb.dwd/releases/tag/v0.2.0) <small>2022-09-17</small>

* add contributors Michael Rustler, Lukas Guericke
* use GitHub actions instead of Travis and Appveyor
Expand Down
14 changes: 12 additions & 2 deletions R/datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#'
#' Information on files that are available for download at
#' <ftp://opendata.dwd.de/climate_environment/CDC/> \[base_url\]. The
#' information were last updated on 2023-04-26.
#' information were last updated on 2024-04-19.
#'
#' @format A data frame with 838345 observations of 8 variables:
#' @format A data frame with 902382 observations of 8 variables:
#' \describe{
#' \item{file}{path to the file below \[base_ur\]}
#' \item{isdir}{TRUE for a directory, FALSE for a file}
Expand Down Expand Up @@ -69,3 +69,13 @@
#' @source
#' <https://geodata.ucdavis.edu/gadm/gadm4.0/shp/gadm40_DEU_shp.zip>
"shapes_germany_2"

#' Information on EPSG codes
#'
#' @format A data frame with 902382 observations of 8 variables:
#' \describe{
#' \item{dir}{path to the file below <ftp://opendata.dwd.de/climate_environment/CDC/>}
#' \item{file}{name of the file}
#' \item{epsg}{EPSG code (integer)}
#' }
"epsg_info"
60 changes: 60 additions & 0 deletions R/get_epsg_from_url.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# get_epsg_from_url ------------------------------------------------------------

#' Get EPSG Code as Found in Description File for a Given URL
#'
#' The URL is looked up in column \code{dir} of \code{\link{epsg_info}}. If the
#' URL is found and results in a unique EPSG code (in column \code{epsg}),
#' that EPSG code is returned. If the URL is not found or if the corresponding
#' EPSG codes are not unique, an error is raised.
#'
#' @param url URL to the file below \code{kwb.dwd:::ftp_path_cdc()} for which to
#' find out the EPSC code
#' @return In the case of success, an integer number is returned. The number
#' represents the EPSG code of the projection that is to be applied for the data
#' in the given URL.
#' @importFrom kwb.utils stopFormatted
#' @export
#' @examples
#' \dontrun{
#' url <- kwb.dwd::get_radolan_urls()$daily_historical_urls[1L]
#' kwb.dwd::get_epsg_from_url(url) # error: no unique EPSG code
#' }
get_epsg_from_url <- function(url)
{
path <- gsub("^(ftp|https?)://", "", url)

find_matching <- function(path) {
data <- kwb.dwd::epsg_info
unique(data[grep(path, data$dir, fixed = TRUE), - 2L])
}

info <- find_matching(path)

while(nzchar(path) && nrow(info) == 0L) {
path <- dirname(path)
info <- find_matching(path)
}

if (nrow(info) == 0L) {
kwb.utils::stopFormatted("I cannot determine the EPSG code for %s", url)
}

epsg <- kwb.utils::selectColumns(info, "epsg")
unique_epsg <- unique(epsg)

if (length(unique_epsg) > 1L) {
print(split(info, epsg))
kwb.utils::stopFormatted(
paste(
"I cannot determine a unique EPSG code for:\n %s\nin:\n %s\n",
"See above for EPSG codes (%s) that I found for files in similar",
"directories"
),
basename(url),
dirname(url),
paste(unique_epsg, collapse = ", ")
)
}

unique_epsg
}
11 changes: 10 additions & 1 deletion R/get_example_grid_germany.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
#' * [get_shapes_of_germany].
get_example_grid_germany <- function()
{
#kwb.utils::assignPackageObjects("kwb.dwd")

path <- "evapo_p/grids_germany_monthly_evapo_p_202201.asc.gz"
read_asc_gz_file(url = ftp_path_grids_germany("monthly", path))
url <- ftp_path_grids_germany("monthly", path)

#epsg <- get_epsg_from_url(url)
epsg <- 31467L

crs <- paste("EPSG", epsg, sep = ":")

read_asc_gz_file(url = url, crs = crs)
}
38 changes: 33 additions & 5 deletions R/get_radolan_projection_string.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
#' Compose radolan projection string
#'
#' @param from_prj_file whether or not to return the string that is provided
#' in "radolanproj.prj" on FTP server of Deutscher Wetterdienst. The default
#' is \code{FALSE}, i.e. a constant string of the form \code{+proj=...}
#' is returned.
#' @param \dots further arguments passed to \code{kwb.dwd:::to_projection_string}
#' @return default radolan projection string
#' @export
#'
#' @examples
#' get_radolan_projection_string()
#'
#' @seealso
#' * [get_radolan_urls],
#' * [get_radolan_extension].
get_radolan_projection_string <- function()
get_radolan_projection_string <- function(from_prj_file = FALSE, ...)
{
string <- paste(
"PROJCS[\"Stereographic_North_Pole\"",
"GEOGCS[\"GCS_unnamed ellipse\"",
"DATUM[\"D_unknown\"",
"SPHEROID[\"Unknown\",6370040,0]]",
"PRIMEM[\"Greenwich\",0]",
"UNIT[\"Degree\",0.017453292519943295]]",
"PROJECTION[\"Stereographic_North_Pole\"]",
"PARAMETER[\"standard_parallel_1\",60]",
"PARAMETER[\"central_meridian\",10]",
"PARAMETER[\"false_easting\",0]",
"PARAMETER[\"false_northing\",0]",
"UNIT[\"Meter\",1]]",
sep = ","
)

stopifnot(identical(
string,
readLines(default_projection_file(radolan = TRUE), warn = FALSE)
))

if (from_prj_file) {
return(string)
}

# TODO: Is this the same?
# readLines(default_projection_file())

to_projection_string(
parameters = list(
Expand All @@ -25,7 +52,8 @@ get_radolan_projection_string <- function()
y_0 = 0,
a = 6370040,
b = 6370040,
to_meter = 1000
to_meter = 1000,
...
),
switches = "no_defs"
)
Expand Down
Loading