-
Notifications
You must be signed in to change notification settings - Fork 77
/
api_shp.R
84 lines (77 loc) · 3.03 KB
/
api_shp.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#' @title Transform a shapefile into a samples file
#' @name .shp_get_samples
#' @author Gilberto Camara
#' @keywords internal
#' @noRd
#' @param shp_file Shapefile that describes the data to be retrieved.
#' @param label Default label for samples.
#' @param shp_attr Shapefile attribute that describes the label.
#' @param start_date Start date for the data set.
#' @param end_date End date for the data set.
#' @param n_shp_pol Number of samples per polygon to be read.
#' @param shp_id ID attribute which contains the label
#' (for POLYGON or MULTIPOLYGON shapefile).
#' @param sampling_type Spatial sampling type: random, hexagonal,
#' regular, or Fibonacci.
#' @return A sits tibble with samples to be retrieved.
#'
.shp_get_samples <- function(shp_file,
label,
shp_attr,
start_date,
end_date,
n_shp_pol,
shp_id,
sampling_type) {
# set caller to show in errors
.check_set_caller(".shp_get_samples")
# Pre-condition - check the shape file and its attribute
.check_that(.has(label) || .has(shp_attr))
sf_shape <- .shp_transform_to_sf(
shp_file = shp_file,
shp_attr = shp_attr,
label = label
)
# Get the points to be read
samples <- .sf_to_tibble(
sf_object = sf_shape,
label_attr = shp_attr,
label = label,
n_sam_pol = n_shp_pol,
pol_id = shp_id,
sampling_type = sampling_type,
start_date = start_date,
end_date = end_date
)
class(samples) <- c("sits", class(samples))
return(samples)
}
#' @title Check the validity of the shape file and return an sf object
#' @name .shp_transform_to_sf
#' @keywords internal
#' @noRd
#'
#' @param shp_file SHP file - boundaries of a region.
#' @param shp_attr attribute that contains the label
#' @param label Label to be used instead of shp_attr