createCopy()
copies a raster dataset, optionally changing the format.
The extent, cell size, number of bands, data type, projection, and
geotransform are all copied from the source raster.
Usage
createCopy(
format,
dst_filename,
src_filename,
strict = FALSE,
options = NULL,
quiet = FALSE
)
Arguments
- format
Format short name for the output raster (e.g., "GTiff" or "HFA").
- dst_filename
Filename to create.
- src_filename
Filename of source raster.
- strict
Logical. TRUE if the copy must be strictly equivalent, or more normally FALSE indicating that the copy may adapt as needed for the output format.
- options
Optional list of format-specific creation options in a vector of
"NAME=VALUE"
pairs (e.g.,options = c("COMPRESS=LZW")
to setLZW
compression during creation of a GTiff file). The APPEND_SUBDATASET=YES option can be specified to avoid prior destruction of existing dataset.- quiet
Logical scalar. If
TRUE
, a progress bar will be not be displayed. Defaults toFALSE
.
Examples
lcp_file <- system.file("extdata/storm_lake.lcp", package="gdalraster")
tif_file <- paste0(tempdir(), "/", "storml_lndscp.tif")
opt <- c("COMPRESS=LZW")
createCopy(format="GTiff", dst_filename=tif_file, src_filename=lcp_file,
options=opt)
#> 0...10...20...30...40...50...60...70...80...90...100 - done.
file.size(lcp_file)
#> [1] 252132
file.size(tif_file)
#> [1] 108510
ds <- new(GDALRaster, tif_file, read_only=FALSE)
ds$getMetadata(band=0, domain="IMAGE_STRUCTURE")
#> [1] "COMPRESSION=LZW" "INTERLEAVE=PIXEL"
for (band in 1:ds$getRasterCount())
ds$setNoDataValue(band, -9999)
ds$getStatistics(band=1, approx_ok=FALSE, force=TRUE)
#> 0...10...20...30...40...50...60...70...80...90...100 - done.
#> [1] 2438.0000 3046.0000 2675.9713 133.0185
ds$close()
deleteDataset(tif_file)
#> [1] TRUE