@@ -95,3 +95,55 @@ test_that('gdal_utils work', {
9595# gdalwarp -t_srs '+proj=utm +zone=11 +datum=WGS84' -overwrite NETCDF:avhrr-only-v2.19810901.nc:anom utm11.tif
9696# becomes:
9797# st_gdalwarp("NETCDF:avhrr-only-v2.19810901.nc:anom", "utm11.tif", c("-t_srs", "+proj=utm +zone=11 +datum=WGS84"))
98+
99+ test_that(' gdal_addo works' , {
100+
101+ skip_on_cran()
102+
103+ has_overviews = function (x ){
104+ info = gdal_utils(source = x , quiet = TRUE )
105+ grepl(" overview" , info , ignore.case = TRUE )
106+ }
107+
108+ has_compressed_overviews = function (x ){
109+ # Check if sidecar overview file has compression, x is tif path
110+ path = paste0(x , " .ovr" ) # overview file
111+ info = gdal_utils(source = path , quiet = TRUE )
112+ if (! file.exists(path ))
113+ return (NA )
114+ grepl(" compression" , info , ignore.case = TRUE )
115+ }
116+
117+ # setup
118+ dir = file.path(tempdir(), " gdal_addo" )
119+ dir.create(dir )
120+ on.exit(unlink(dir , recursive = TRUE )) # cleanup when done
121+ tif = file.path(dir , " geomatrix.tif" )
122+ file.copy(system.file(" tif/geomatrix.tif" , package = " sf" ),
123+ tif , overwrite = TRUE )
124+
125+ expect_false(has_overviews(tif ))
126+
127+ # Default arguments
128+ expect_no_error(gdal_addo(tif )) # internal overview
129+ expect_true(has_overviews(tif ))
130+ expect_true(is.na(has_compressed_overviews(tif ))) # no overview file
131+
132+ # Clean overviews
133+ expect_no_error(gdal_addo(tif , clean = TRUE ))
134+ expect_false(has_overviews(tif ))
135+
136+ # Overviews in separate file
137+ expect_no_error(gdal_addo(tif , read_only = TRUE ))
138+ expect_false(has_compressed_overviews(tif )) # uncompressed overview file
139+
140+ # Clean overviews
141+ expect_no_error(gdal_addo(tif , clean = TRUE ))
142+ expect_false(has_overviews(tif ))
143+
144+ # Compression via config_options works
145+ expect_no_error(gdal_addo(tif , read_only = TRUE ,
146+ config_options = c(COMPRESS_OVERVIEW = " LZW" )))
147+ expect_true(has_compressed_overviews(tif ))
148+
149+ })
0 commit comments