-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_data_train_test_splitting.R
66 lines (44 loc) · 1.68 KB
/
01_data_train_test_splitting.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
pacman::p_load(sf)
# todos los puntos en WGS 84 / UTM zone 19S
list_files <- list.files(path = "./data/sampling_points/",
recursive = TRUE,
full.name = TRUE, # directorio relativo raster
pattern = "\\.gpkg$")
list_gpkg <- lapply(list_files, FUN = sf::read_sf)
#SPLIT TRAIN- TEST
# # filter train points
list_gpkg_train <- list()
for (i in seq_along(list_gpkg)) {
list_gpkg_train[[i]] <- list_gpkg[[i]] %>%
dplyr::filter(train_test=="train") %>%
dplyr::select(!c("cell","CLASS.1", "train_test")) %>%
na.omit()
}
# #test data
list_gpkg_test <- list()
for (i in seq_along(list_gpkg)) {
list_gpkg_test[[i]] <- list_gpkg[[i]] %>%
dplyr::filter(train_test=="test") %>%
dplyr::select(!c("cell","CLASS.1", "train_test")) %>%
na.omit()
}
# #SPATIAL TASK
#
cordilleras <- c("Blanca","Central","Huallanca",
"Huayhuasha","Huaytapallana","LaRaya",
"LaViuda","Raura","Urubamba",
"Vilcabamba","Vilcanota")
#WRITE GPKG
for (i in 1:length(list_gpkg_train)) {
# Creating a filename using the corresponding name from the vector
filename <- paste0("./data/sampling_points_split/", cordilleras[i], "_train", ".gpkg")
# Saving the SF object to the file
st_write(list_gpkg_train[[i]], filename)
}
#save test
for (i in 1:length(list_gpkg_test)) {
# Creating a filename using the corresponding name from the vector
filename <- paste0("./data/sampling_points_split/" ,cordilleras[i], "_test", ".gpkg")
# Saving the SF object to the file
st_write(list_gpkg_test[[i]], filename)
}