|
9 | 9 | #' @param start_date Start date for the data set.
|
10 | 10 | #' @param end_date End date for the data set.
|
11 | 11 | #' @param n_sam_pol Number of samples per polygon to be read.
|
12 |
| -#' @param pol_id ID attribute for polygons shapefile. |
| 12 | +#' @param pol_id ID attribute which contains label |
13 | 13 | #' (for POLYGON or MULTIPOLYGON shapefile).
|
| 14 | +#' @param sampling_type Spatial sampling type: random, hexagonal, |
| 15 | +#' regular, or Fibonacci. |
14 | 16 | #' @return A tibble with information the samples to be retrieved.
|
15 | 17 | #'
|
16 | 18 | .sf_get_samples <- function(sf_object,
|
|
19 | 21 | start_date,
|
20 | 22 | end_date,
|
21 | 23 | n_sam_pol,
|
22 |
| - pol_id) { |
| 24 | + pol_id, |
| 25 | + sampling_type) { |
23 | 26 | # Pre-condition - is the sf object has geometries?
|
24 | 27 | .check_that(
|
25 | 28 | x = nrow(sf_object) > 0,
|
|
44 | 47 | label = label,
|
45 | 48 | n_sam_pol = n_sam_pol,
|
46 | 49 | pol_id = pol_id,
|
| 50 | + sampling_type = sampling_type, |
47 | 51 | start_date = start_date,
|
48 | 52 | end_date = end_date
|
49 | 53 | )
|
|
60 | 64 | #' @description reads a shapefile and retrieves a sits tibble
|
61 | 65 | #' containing a set of lat/long points for data retrieval
|
62 | 66 | #'
|
63 |
| -#' @param sf_object sf object . |
64 |
| -#' @param label_attr Attribute in sf object used as a polygon label. |
65 |
| -#' @param label Label to be assigned to points. |
66 |
| -#' @param n_sam_pol Number of samples per polygon to be read |
67 |
| -#' (for POLYGON or MULTIPOLYGON shapes). |
68 |
| -#' @param pol_id ID attribute for polygons. |
69 |
| -#' @param start_date Start of the interval for the time series |
70 |
| -#' in "YYYY-MM-DD" format (optional). |
71 |
| -#' @param end_date End of the interval for the time series in |
72 |
| -#' "YYYY-MM-DD" format (optional). |
| 67 | +#' @param sf_object sf object. |
| 68 | +#' @param label_attr Attribute in sf object used as a polygon label. |
| 69 | +#' @param label Label to be assigned to points. |
| 70 | +#' @param n_sam_pol Number of samples per polygon to be read |
| 71 | +#' (for POLYGON or MULTIPOLYGON shapes). |
| 72 | +#' @param pol_id ID attribute for polygons which contains the label |
| 73 | +#' @param sampling_type Spatial sampling type: random, hexagonal, |
| 74 | +#' regular, or Fibonacci. |
| 75 | +#' @param start_date Start of the interval for the time series |
| 76 | +#' in "YYYY-MM-DD" format (optional). |
| 77 | +#' @param end_date End of the interval for the time series in |
| 78 | +#' "YYYY-MM-DD" format (optional). |
73 | 79 | #' @return A sits tibble with points to to be read.
|
74 | 80 | .sf_to_tibble <- function(sf_object,
|
75 | 81 | label_attr,
|
76 | 82 | label,
|
77 | 83 | n_sam_pol,
|
78 | 84 | pol_id,
|
| 85 | + sampling_type, |
79 | 86 | start_date,
|
80 | 87 | end_date) {
|
81 | 88 |
|
|
110 | 117 | label_attr = label_attr,
|
111 | 118 | label = label,
|
112 | 119 | n_sam_pol = n_sam_pol,
|
113 |
| - pol_id = pol_id |
| 120 | + pol_id = pol_id, |
| 121 | + sampling_type = sampling_type |
114 | 122 | )
|
115 | 123 | )
|
116 | 124 |
|
|
170 | 178 | #' @param label_attr Attribute in the shapefile used as a polygon label
|
171 | 179 | #' @param label Label to be assigned to points
|
172 | 180 | #' @param n_sam_pol Number of samples per polygon to be read
|
173 |
| -#' @param pol_id ID attribute for polygons shapefile. |
| 181 | +#' @param pol_id ID attribute for polygons containing the label |
| 182 | +#' @param sampling_type Spatial sampling type: random, hexagonal, |
| 183 | +#' regular, or Fibonacci. |
174 | 184 | #' @return A tibble with latitude/longitude points from POLYGON geometry
|
175 | 185 | #'
|
176 | 186 | .sf_polygon_to_tibble <- function(sf_object,
|
177 | 187 | label_attr,
|
178 | 188 | label,
|
179 | 189 | n_sam_pol,
|
180 |
| - pol_id) { |
| 190 | + pol_id, |
| 191 | + sampling_type) { |
181 | 192 | # get the db file
|
182 | 193 | sf_df <- sf::st_drop_geometry(sf_object)
|
183 | 194 |
|
|
213 | 224 | polygon_id <- unname(as.character(sf_df[i, pol_id]))
|
214 | 225 | }
|
215 | 226 | # obtain a set of samples based on polygons
|
216 |
| - points <- list(sf::st_sample(sf_object[i, ], size = n_sam_pol)) |
| 227 | + points <- list(sf::st_sample(sf_object[i, ], |
| 228 | + type = sampling_type, |
| 229 | + size = n_sam_pol)) |
217 | 230 | # get one time series per sample
|
218 | 231 | pts_tab <- points |>
|
219 | 232 | purrr::pmap_dfr(function(p) {
|
|
0 commit comments