4
4
# # 1.1. Load data ---------------
5
5
6
6
# # LC for coords
7
- copernicus_coords <- fd_landcover_copernicus(
8
- lon = - 7 ,
9
- lat = 43
10
- )
7
+ test_that(" download LCC with coords work" , {
8
+ skip_on_cran()
9
+ # # load data
10
+ copernicus_coords <- fd_landcover_copernicus(lon = - 7 ,lat = 43 )
11
+ # # check spatraster
12
+ expect_s4_class(copernicus_coords , " SpatRaster" )
13
+ # # check source names
14
+ expect_equal(
15
+ copernicus_coords | > terra :: sources() | > basename(),
16
+ " W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Forest-Type-layer_EPSG-4326.tif"
17
+ )
18
+ })
19
+
20
+ # # LC coords several layers
21
+ test_that(" download LCC with coords work" , {
22
+ skip_on_cran()
23
+ # # load data
24
+ copernicus_coords_2_layers <- fd_landcover_copernicus(
25
+ lon = - 7 ,
26
+ lat = 43 ,
27
+ layer = c(" crops" , " tree" )
28
+ )
29
+ # # check spatraster
30
+ expect_s4_class(copernicus_coords_2_layers , " SpatRaster" )
31
+ # # check source names
32
+ expect_equal(
33
+ copernicus_coords_2_layers | > terra :: sources() | > basename(),
34
+ c(
35
+ " W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Crops-CoverFraction-layer_EPSG-4326.tif" ,
36
+ " W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Tree-CoverFraction-layer_EPSG-4326.tif"
37
+ )
38
+ )
39
+ })
11
40
12
- # ## LC coords several layers
13
- # copernicus_coords_2_layers <- fd_landcover_copernicus(
14
- # lon = -7,
15
- # lat = 43,
16
- # layer = c("crops", "tree")
17
- # )
18
41
#
19
42
# ## LC coords several layers and years
20
43
# copernicus_years <- fd_landcover_copernicus(
@@ -36,10 +59,19 @@ polygon_2tiles_sf <- sf::st_sfc(sf::st_point(c(-7, 44)), crs = 4326) |>
36
59
sf :: st_as_sf()
37
60
38
61
# # LC polygon one layer (merging 2 tiles)
39
- copernicus_polygon <- fd_landcover_copernicus(
40
- x = polygon_2tiles_sf ,
41
- layer = " builtup"
42
- )
62
+ test_that(" download for one polygon, merging 2 tiles" , {
63
+ skip_on_cran()
64
+ # # get data
65
+ copernicus_polygon <- fd_landcover_copernicus(
66
+ x = polygon_2tiles_sf ,
67
+ layer = " builtup"
68
+ )
69
+ # # check spatraster
70
+ expect_s4_class(copernicus_polygon , " SpatRaster" )
71
+ # # check layer names
72
+ expect_equal(copernicus_polygon | > names(), " builtup_2019" )
73
+ })
74
+
43
75
44
76
# # LC polygon 2 layers (merging 2 tiles)
45
77
# copernicus_polygon_2_layers <- fd_landcover_copernicus(
@@ -48,65 +80,49 @@ copernicus_polygon <- fd_landcover_copernicus(
48
80
# )
49
81
50
82
# # Crop
51
- copernicus_crop <- fd_landcover_copernicus(
52
- x = polygon_1tile_vect ,
53
- layer = " grass" ,
54
- year = 2016 ,
55
- crop = TRUE
56
- )
57
-
58
-
59
- # # 1.2. Unit tests --------------
60
-
61
- # # Check that data is properly downloaded (tiles are merged)
62
- test_that(" Data is properly downloaded" , {
63
- expect_s4_class(copernicus_coords , " SpatRaster" )
64
- # expect_s4_class(copernicus_coords_2_layers, "SpatRaster")
65
- # expect_s4_class(copernicus_years, "SpatRaster")
66
- expect_s4_class(copernicus_polygon , " SpatRaster" )
67
- # expect_s4_class(copernicus_polygon_2_layers, "SpatRaster")
83
+ test_that(" download polygon, crop" , {
84
+ skip_on_cran()
85
+ # # get data
86
+ copernicus_crop <- fd_landcover_copernicus(
87
+ x = polygon_1tile_vect ,
88
+ layer = " grass" ,
89
+ year = 2016 ,
90
+ crop = TRUE
91
+ )
92
+ # # check spatraster
68
93
expect_s4_class(copernicus_crop , " SpatRaster" )
69
- })
70
-
71
- # # Check that layers are correctly downloaded
72
- test_that(" Layers are correctly downloaded and named" , {
94
+ # # check layer names
95
+ expect_equal(copernicus_crop | > names(), " grass_2016" )
96
+ # # check crop worked well
97
+ expect_equal(terra :: ext(copernicus_crop )[1 ], terra :: ext(polygon_1tile_vect )[1 ], tolerance = 1e-1 )
98
+ expect_equal(terra :: ext(copernicus_crop )[2 ], terra :: ext(polygon_1tile_vect )[2 ], tolerance = 1e-1 )
99
+ expect_equal(terra :: ext(copernicus_crop )[3 ], terra :: ext(polygon_1tile_vect )[3 ], tolerance = 1e-1 )
100
+ expect_equal(terra :: ext(copernicus_crop )[4 ], terra :: ext(polygon_1tile_vect )[4 ], tolerance = 1e-1 )
73
101
74
- expect_equal(
75
- copernicus_coords | > terra :: sources() | > basename(),
76
- " W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Forest-Type-layer_EPSG-4326.tif"
77
- )
102
+ })
78
103
79
- # expect_equal(
80
- # copernicus_coords_2_layers |> terra::sources() |> basename(),
81
- # c(
82
- # "W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Crops-CoverFraction-layer_EPSG-4326.tif",
83
- # "W020N60_PROBAV_LC100_global_v3.0.1_2019-nrt_Tree-CoverFraction-layer_EPSG-4326.tif"
84
- # )
85
- # )
86
-
87
- # expect_equal(
88
- # copernicus_years |> names(),
89
- # c(
90
- # paste0("crops_", 2015:2019),
91
- # paste0("tree_", 2015:2019)
92
- # )
93
- # )
94
104
95
- expect_equal(copernicus_polygon | > names(), " builtup_2019" )
96
- # expect_equal(copernicus_polygon_2_layers |> names(), c("bare_2019", "snow_2019"))
97
- expect_equal(copernicus_crop | > names(), " grass_2016" )
98
105
99
106
100
- })
107
+ # # Check that data is properly downloaded (tiles are merged)
108
+ # test_that("Data is properly downloaded", {
109
+ # # expect_s4_class(copernicus_years, "SpatRaster")
110
+ # # expect_s4_class(copernicus_polygon_2_layers, "SpatRaster")
111
+ # })
112
+ #
113
+ # ## Check that layers are correctly downloaded
114
+ # test_that("Layers are correctly downloaded and named", {
115
+ # # expect_equal(
116
+ # # copernicus_years |> names(),
117
+ # # c(
118
+ # # paste0("crops_", 2015:2019),
119
+ # # paste0("tree_", 2015:2019)
120
+ # # )
121
+ # # )
122
+ # # expect_equal(copernicus_polygon_2_layers |> names(), c("bare_2019", "snow_2019"))
123
+ # })
101
124
102
125
103
- # # Check extent when cropping
104
- test_that(" Crop works" , {
105
- expect_equal(terra :: ext(copernicus_crop )[1 ], terra :: ext(polygon_1tile_vect )[1 ], tolerance = 1e-1 )
106
- expect_equal(terra :: ext(copernicus_crop )[2 ], terra :: ext(polygon_1tile_vect )[2 ], tolerance = 1e-1 )
107
- expect_equal(terra :: ext(copernicus_crop )[3 ], terra :: ext(polygon_1tile_vect )[3 ], tolerance = 1e-1 )
108
- expect_equal(terra :: ext(copernicus_crop )[4 ], terra :: ext(polygon_1tile_vect )[4 ], tolerance = 1e-1 )
109
- })
110
126
111
127
112
128
# 2. Esri LCE -------------------------------------------------------------
0 commit comments