Skip to content

Commit 3cf55f4

Browse files
committed
0.95 pre-release
1 parent 07fa594 commit 3cf55f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2475
-678
lines changed

.Rbuildignore

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
^rAHNextract\.Rproj$
22
^\.Rproj\.user$
33
^data-raw$
4-
^scratch$
5-
^AHN_sheets$
6-
^AHN_output$
7-
ahn_hoogtes.R
84
^LICENSE\.md$
9-
rAHNextract_test.qgz
105
^tests$
116
^README\.Rmd$
12-
^my_output$
13-
Rcode
14-
^Nederwaard1$
7+
^ahn_hoogtes\.R$
8+
^Rcode$
9+
^rAHNextract_test\.qgz$
10+
^AHN_sheets$
11+
^AHN_output$
12+
^Routput - Shortcut\.lnk$
13+
^README_cache$
14+
^README\.HTML$
15+
^_pkgdown\.yml$
16+
^docs$
17+
^pkgdown$

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ Rcode
1212
rAHNextract_test.qgz
1313
my_output/
1414
Nederwaard1/
15+
docs/
16+
Routput - Shortcut.lnk
17+
README_cache

DESCRIPTION

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
Type: Package
22
Package: rAHNextract
33
Title: Extract elevation points or areas in the Netherlands from the AHN
4-
Version: 0.98
5-
Date: 23-02-2020
4+
Version: 0.95
5+
Date: 22-04-2020
66
Author: Jelle Stuurman
77
Maintainer: Jelle Stuurman <[email protected]>
8-
Description: Extract elevation points or areas in the Netherlands from the Actueel Hoogtebestand Nederland (AHN). Raster or point clouds extraction is possible of a custom area for the AHN1, AHN2 or AHN3.
8+
Description: Extract elevation points or raster areas or point clouds areas in the Netherlands from the Actueel Hoogtebestand Nederland (AHN). Raster or point clouds extraction is possible of a custom area for the AHN1, AHN2 or AHN3.
99
URL: https://github.com/Jellest/rAHNextract
1010
BugReports: https://github.com/Jellest/rAHNextract/issues
11-
License: GPL-3
11+
License: GPL-3 LICENSE.md
1212
Encoding: UTF-8
1313
LazyData: true
14-
RoxygenNote: 7.0.2
14+
RoxygenNote: 7.1.0
1515
Imports:
1616
rgdal,
1717
sf,

LICENSE.md

+595
Large diffs are not rendered by default.

R/ahn_area.R

+70-58
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,89 @@
1-
#'Get AHN raster of a certain area
2-
#'
31
#'@title AHN raster area
4-
#'@description Get AHN raster area of a certain area
5-
#'@param X Optional. X coordinate in RD New or WGS84 (LON)
6-
#'@param Y Optional. Y coordinate in RD New or WGS84 (LAT)
7-
#'@param LONLAT Optional. Default FALSE. Set to TRUE if X and Y are in Longitude and Latitude format. Output will always be in RD New format
8-
#'@param radius Optional. Set radius in meters of area around a point to create a buffer area (circle).
9-
#'@param bbox Optional. Set bbox of area. c(XMIN, YMIN, XMAX, YMAX) in RD New or WGS84 (LONLAT)
10-
#'@param polygon Optional. Use spatial object as your area. .shp, .gpkg. Output will in the shape of this polygon
11-
#'@param name Optional. Give a name of the specified area. Name will used in the folders and files
2+
#'@description Get AHN raster area of a specified area.
3+
#'
4+
#'AHN Area is retrieved through a circle (x, y and radius), BBOX (x, y and radius, OR bbox), or own geometry (polygon).
5+
#'
6+
#'AHN data is obtained from the AHN3 (default), AHN2 or AHN 1 from the available resolutions.
7+
#'
8+
#'Default resolution is always the highest resolution (smallest number). AHN3 and AHN2 DEM (Digital Elevation Model) are available for the Digital Surface Model (DSM) and Digital Terrain Model (DTM). AHN1 only has the DTM. THE DTM of the AHN2 has an interpolated and a non-interpolate version.
9+
#'
10+
#'You can download the AHN data using the WCS method (default, sheets.method = FALSE) returning a GeoTIFF float32 format. The sheets method (sheets.method = TRUE) returns a regular raster GeoTIFF output file that is extracted from the PDOK sheets. The WCS method is recommended if only a few AHN elevation points need to be extracted. The sheets method always requires more data to be downloaded to the client but may be more efficient if many elevatiomns need to be retrieved from a small area. Choosing your method depends on speed and your desired output format. See documentation for all available parameters.
11+
#'@param name Optional. Give a name of the specified area. This name will be used in the output file names.
12+
#'@param output.dir Optional but recommended. Set location of output directory. Leaving blank (default) will make all output point files be temporary files. This output directory excludes the location of the AHN sheets which is depicted with the 'sheets.location' parameter.
13+
#'@param X Required for circle or BBOX when no BBOX coordinates are provided. X coordinate in RD New or WGS84 (LON)
14+
#'@param Y Required for circle or BBOX when no BBOX coordinates are provided. Y coordinate in RD New or WGS84 (LAT)
15+
#'@param radius Required for circle or BBOX when no BBOX coordinates are provided. Set radius in meters of area around a point to create a buffer area (circle).
16+
#'@param bbox Required when using a BBOX. Create BBOX of an area. Use c(XMIN, YMIN, XMAX, YMAX) OR set to TRUE when a radius is provided. Use RD New or WGS84 (LONLAT) coordinates.
17+
#'@param polygon Required when create an area of custom geometry. Use spatial object as your area. .shp, .gpkg. Output will in the shape of this polygon
1218
#'@param AHN Default 'AHN3'. Set to 'AHN1', 'AHN2', or 'AHN3'
1319
#'@param dem Required for raster datasets. Default 'DSM'. Choose type of Digital Elevation Model. 'DSM' or 'DTM'. AHN1 only has 'DTM'.
1420
#'@param resolution Default 0.5 meters for AHN2/AHN3, 5 meters for AHN1. Choose resolution of AHN in meters. AHN3 and AHN2 both have 0.5 and 5 meters. AHN1 has 5, and 100 m.
1521
#'@param interpolate Default TRUE. Only applicable for AHN2 DTM. It decides if you want the interpolated version of the AHN2 or not.
22+
#'@param LONLAT Optional. Default FALSE. Set to TRUE if X and Y are in Longitude and Latitude format. Output will always be in RD New format
1623
#'@param decimals Default 2. Decide number of decimal places of output elevations.
17-
#'@param destfile Default "structured". When set to "structured", all the output files will be saved in an organized way in the folder 'AHN_output' created in your current working directory. This included the AHN sheets. Set to 'Structured' to save Set to any other output path to save all the output files there. The AHN sheets will be downloaded in the output folder 'AHN_sheets" in your working directory. Set to "", to have all output files be temporary files except for the AHN sheets which are downloaded in the 'AHN_sheets' folder.
18-
#'@param method.sheets Default FALSE. FALSE downloads AHN area through the faster WCS method. Output is 32float geotif file. TRUE downloads AHN area through the available .tiff AHN sheets (kaartbladen) available on PDOK.
19-
#'@param keep.sheets Default TRUE. Only applicable if method.sheets is set to TRUE. Set to FALSE if you want to delete the downloaded sheets (kaartbladen).
20-
#'@param redownload Default FALSE. Only applicable if sheets is set to TRUE. Set to TRUE if you want to redownload the sheets (kaartbladen)
24+
#'@param sheets.method Default FALSE. FALSE downloads AHN area through the faster WCS method. Output is 32float GeoTIFF file.TRUE downloads AHN area through the available GeoTIFF AHN sheets available on [PDOK](http://esrinl-content.maps.arcgis.com/apps/Embed/index.html?appid=a3dfa5a818174aa787392e461c80f781).
25+
#'@param sheets.location Optional. Default is the 'AHN_sheets' directory in the working directory. Set directory where all the AHN sheets are loaded when pre-existing sheets will be used or when new sheets will be stored. When loading existing files, always use the correct directory structure and capitalization within the selected directory. Example directory structure when this parameter is set to e.g. 'myFolder': 'myFolder/AHN_sheets/AHN3/DSM' or 'myFolder/AHN_sheets/AHN2/DTM'. Only use extracted files in their original name after download.
26+
#'@param sheets.keep Default TRUE. Only applicable if sheets.method is set to TRUE and sheets were downloaded. Set to FALSE if you want to delete the downloaded sheets (structure). It is recommended to keep the sheets if this function will be used more than once.
27+
#'@param sheets.redownload Default FALSE. Only applicable if sheets is set to TRUE. Set to TRUE if you want to redownload the sheets (structure).
2128
#'@author Jelle Stuurman
22-
#'@return .tif file of AHN area
29+
#'@return GeoTIFF file of AHN area
2330
#'@export
24-
ahn_area <- function(X, Y, radius, bbox, polygon, name, LONLAT = FALSE, AHN = "AHN3", dem = "DSM", resolution, interpolate = TRUE, decimals = 2, destfile = "structured", method.sheets = FALSE, keep.sheets = TRUE, redownload = FALSE){
25-
if(missing(X) == TRUE && missing(Y) == TRUE && (missing(polygon) == TRUE || missing(bbox) == TRUE) && missing(radius) == TRUE){
26-
#creating BBOX or shape
27-
radius <- ""
28-
}
31+
ahn_area <- function(name = "AHNarea", output.dir, X, Y, radius, bbox, polygon, AHN = "AHN3", dem = "DSM", resolution, interpolate = TRUE, LONLAT = FALSE, decimals = 2, sheets.method = FALSE, sheets.location, sheets.keep = TRUE, sheets.redownload = FALSE){
32+
#set tmp folder if applicable or create output and directory
33+
requireNamespace("raster")
2934
name_trim <- trim_name(name)
30-
#selected AHN layer
31-
ahn_lower <- tolower(AHN)
32-
if(ahn_lower != "ahn1" && ahn_lower != "ahn2" && ahn_lower != "ahn3"){
33-
stop("No correct AHN is provided. Please select 'AHN1', 'AHN2' or 'AHN3'.")
35+
36+
#set tmp folder if applicable or create output directory
37+
if(missing(output.dir) == TRUE){
38+
output.dir <- tempdir()
3439
} else {
35-
my_ahn <- toupper(AHN)
40+
if(!dir.exists(output.dir) == TRUE){
41+
dir.create(output.dir)
42+
print(paste0("'",output.dir, "' directory was not found and was created."))
43+
}
44+
#print(output.dir)
3645
}
37-
ahn_area <- create_area(X = X, Y = Y, radius = radius, bbox = bbox, polygon = polygon, LONLAT = LONLAT, type = "raster")
38-
if(ahn_area == "point"){
39-
#go to ahn_point()
40-
warning("Geometry type was detected as a point. Function 'ahn_point()' was excecuted instead with all applicable provided parameters. Please see the documentation of ahn_point() to see what output is provided.")
41-
ahn_point(X = X, Y = Y, LONLAT = LONLAT, name = name, destfile = destfile, AHN = AHN, dem = dem, resolution = resolution, interpolate = interpolate, method.sheets = method.sheets, keep.sheets = keep.sheets, redownload = redownload, decimals = decimals)
46+
47+
#selected AHN
48+
if(tolower(AHN) != "ahn1" && tolower(AHN) != "ahn2" && tolower(AHN) != "ahn3"){
49+
stop("No correct AHN is provided. Please select 'AHN1', 'AHN2' or 'AHN3'.")
4250
} else {
43-
if(destfile != "structured" && destfile != ""){
44-
print(destfile)
45-
if(!dir.exists(destfile)){
46-
dir.create(destfile)
47-
warning("Directory did not exist and was created in your working directory.")
48-
}
49-
}
51+
AHN <- toupper(AHN)
52+
}
53+
54+
#complete geometry parameters
55+
if(missing(X) == TRUE && missing(Y) == TRUE && (missing(polygon) == TRUE || missing(bbox) == TRUE) && missing(radius) == TRUE){
56+
#creating BBOX or shape
57+
radius <- ""
58+
}
5059

51-
# if(missing(dem) == TRUE){
52-
# type = "pc"
53-
# } else {
54-
# type = "raster"
55-
# }
60+
#get and create area
61+
ahn_area <- create_area(X = X, Y = Y, radius = radius, bbox = bbox, polygon = polygon, LONLAT = LONLAT, type = "raster")
5662

63+
#get AHN data
64+
if(sheets.method == TRUE){
65+
#download AHN sheets and get data (slow)
5766

58-
if(method.sheets == TRUE){
59-
#download AHN sheets and get data (slow)
60-
data <- get_ahn_sheets(name = name_trim, area = ahn_area, type = "raster", AHN = my_ahn, dem = dem, resolution = resolution, radius = radius, interpolate = interpolate, destfile = destfile, keep.sheets = keep.sheets, redownload = redownload)
61-
if(destfile == ""){
62-
unlink(data$fileDir, recursive = TRUE)
63-
}
64-
ahn_data <- data$data
67+
#set AHN sheets location
68+
if(missing(sheets.location) == TRUE){
69+
sheets.location <- getwd()
70+
print(paste0("The AHN sheets are loaded from or downloaded in: ", sheets.location, "/", default.sheets.dir, "/", AHN, "/", dem))
6571
} else {
66-
#retrieve data through WCS (fast)
67-
wcs_url <- create_wcs_url(bbox = ahn_area$bbox, type = "area", AHN = my_ahn, resolution = resolution, dem = dem, interpolate = interpolate)
68-
raster_data <- download_wcs_raster(wcsUrl = wcs_url, name = name_trim, AHN = AHN, dem = tolower(dem), radius = radius, resolution = resolution, interpolate = interpolate, destfile = destfile)
69-
raster_mask <- raster::mask(x = raster_data$data, mask = ahn_area$area, filename = raster_data$fileName, overwrite = TRUE)
70-
ahn_data <- raster_mask
71-
if(destfile == ""){
72-
unlink(raster_data$fileDir)
73-
}
72+
ahn_sheet_directory <- paste(sheets.location, AHN, dem, sep="/")
73+
sprintf("The AHN sheets are loaded from or downloaded in: %s. If no AHN sheet in the correct directory or if no correct name of AHN sheet is found, sheet will be downloaded. For first use it is recommended to use the default output directory.", ahn_sheet_directory)
7474
}
75-
return (ahn_data)
75+
76+
#get AHN data
77+
raster_data <- get_ahn_sheets(name = name_trim, area = ahn_area, type = "area", AHN = AHN, dem = dem, resolution = resolution, radius = radius, interpolate = interpolate, output.dir = output.dir, sheets.location = sheets.location, sheets.keep = sheets.keep, sheets.redownload = sheets.redownload)
78+
ahn_data <- raster_data$data
79+
} else {
80+
#retrieve data through WCS (fast)
81+
wcs_url <- create_wcs_url(bbox = ahn_area$bbox, type = "area", AHN = AHN, resolution = resolution, dem = dem, interpolate = interpolate)
82+
raster_data <- download_wcs_raster(wcsUrl = wcs_url, name = name_trim, AHN = AHN, dem = tolower(dem), radius = radius, resolution = resolution, interpolate = interpolate, output.dir = output.dir, type = "raster")
83+
ahn_data <- raster::mask(x = raster_data$data, mask = ahn_area$area, filename = raster_data$fileName, overwrite = TRUE)
84+
}
85+
if(LONLAT == TRUE){
86+
warning("The input geometry was provided using Longitude and Latitude coordinates. The output, however, is a raster using the the RD New cordinate system.")
7687
}
88+
return (ahn_data)
7789
}

0 commit comments

Comments
 (0)