@@ -117,7 +117,7 @@ sits_labels.default <- function(data) {
117117 UseMethod(" sits_labels<-" , data )
118118}
119119# ' @title Change the labels of a set of time series
120- # ' @param data Data cube or time series.
120+ # ' @param data Time series.
121121# ' @param value A character vector used to convert labels. Labels will
122122# ' be renamed to the respective value positioned at the
123123# ' labels order returned by \code{\link{sits_labels}}.
@@ -139,8 +139,8 @@ sits_labels.default <- function(data) {
139139 data [[" label" ]] <- value [data [[" label" ]]]
140140 data
141141}
142- # ' @title Change the labels of a set of time series
143- # ' @param data Data cube or time series .
142+ # ' @title Change the labels of a probs raster cube
143+ # ' @param data Raster cube with probability values .
144144# ' @param value A character vector used to convert labels. Labels will
145145# ' be renamed to the respective value positioned at the
146146# ' labels order returned by \code{\link{sits_labels}}.
@@ -156,8 +156,8 @@ sits_labels.default <- function(data) {
156156 data [[" labels" ]] <- list (value )
157157 data
158158}
159- # ' @title Change the labels of a set of time series
160- # ' @param data Data cube or time series .
159+ # ' @title Change the labels of a classified raster cube
160+ # ' @param data Classified raster data cube .
161161# ' @param value A character vector used to convert labels. Labels will
162162# ' be renamed to the respective value positioned at the
163163# ' labels order returned by \code{\link{sits_labels}}.
@@ -178,7 +178,109 @@ sits_labels.default <- function(data) {
178178 row
179179 })
180180}
181- # ' @title Change the labels of a set of time series
181+ # ' @title Change the labels of a probs vector data cube
182+ # ' @author Gilberto Camara, \email{gilberto.camara@@inpe.br}
183+ # ' @param data Probs vector data cube.
184+ # ' @param value A character vector used to convert labels.
185+ # '
186+ # ' @description
187+ # ' A "probs_vector_cube" is a data cube with a set of segments that
188+ # ' contain the probability values of each class for each polygon.
189+ # ' When a user changes the labels of the class, this function
190+ # ' modifies the labels associated to the cube's metadata and
191+ # ' also changes the names in the segments file. The GPKG file
192+ # ' containing the segments and the probability values is replace
193+ # ' with a new file with the desired labels.
194+ # '
195+ # ' @export
196+ `sits_labels<-.probs_vector_cube` <- function (data , value ) {
197+
198+ # get the labels for the vector cube
199+ labels_orig <- .cube_labels(data )
200+ # check if value and labels match
201+ .check_chr_parameter(value ,
202+ len_max = length(labels_orig ),
203+ len_min = length(labels_orig )
204+ )
205+ # check if there are no NA
206+ .check_that(! anyNA(value ))
207+ # check if there are empty strings
208+ .check_that(any(trimws(value ) != " " ))
209+ # name the conversion vector with the original labels
210+ names(labels_orig ) <- value
211+
212+ # run for each tile of the cube
213+ slider :: slide_dfr(data , function (row ){
214+ # change the labels in the tile
215+ row [[" labels" ]] <- list (value )
216+ # read the segments for the tile
217+ .segments <- .segments_read_vec(row )
218+ # rename column names
219+ .segments <- dplyr :: rename(.segments , dplyr :: all_of(labels_orig ))
220+ # Prepare and save results as vector
221+ .vector_write_vec(
222+ v_obj = .segments ,
223+ file_path = .segments_path(row ),
224+ append = FALSE
225+ )
226+ row
227+ })
228+ }
229+ # ' @title Change the labels of a class vector data cube
230+ # ' @author Gilberto Camara, \email{gilberto.camara@@inpe.br}
231+ # ' @param data Class vector data cube.
232+ # ' @param value A character vector used to convert labels.
233+ # '
234+ # ' @description
235+ # ' A "class_vector_cube" is a data cube with a set of segments that
236+ # ' contain the probability values of each class for each polygon
237+ # ' and also list the most probable class.
238+ # ' When a user changes the labels of the class, this function
239+ # ' modifies the labels associated to the cube's metadata and
240+ # ' also changes the names in the segments file. The GPKG file
241+ # ' containing the segments and the probability values is replace
242+ # ' with a new file with the desired labels.
243+ # '
244+ # ' @export
245+ `sits_labels<-.class_vector_cube` <- function (data , value ) {
246+
247+ # get the labels for the vector cube
248+ labels_orig <- .cube_labels(data )
249+ # check if value and labels match
250+ .check_chr_parameter(value ,
251+ len_max = length(labels_orig ),
252+ len_min = length(labels_orig )
253+ )
254+ # check if there are no NA
255+ .check_that(! anyNA(value ))
256+ # check if there are empty strings
257+ .check_that(any(trimws(value ) != " " ))
258+ # name the conversion vector with the original labels
259+ names(labels_orig ) <- value
260+ # create a named vector to map the class values
261+ names(value ) <- unname(labels_orig )
262+
263+ # run for each tile of the cube
264+ slider :: slide_dfr(data , function (row ){
265+ # change the labels in the tile
266+ row [[" labels" ]] <- list (value )
267+ # read the segments for the tile
268+ # rename column names
269+ # rename values in "class" column
270+ .segments <- .segments_read_vec(row ) | >
271+ dplyr :: rename(dplyr :: all_of(labels_orig )) | >
272+ dplyr :: mutate(class = value [.data [[" class" ]]] )
273+
274+ # Save results in the segments file
275+ .vector_write_vec(
276+ v_obj = .segments ,
277+ file_path = .segments_path(row ),
278+ append = FALSE
279+ )
280+ row
281+ })
282+ }
283+ # ' @title Change the labels of other data structures
182284# ' @param data Data cube or time series.
183285# ' @param value A character vector used to convert labels. Labels will
184286# ' be renamed to the respective value positioned at the
0 commit comments