gdalUtils (version 2.0.1.5)

gdal_translate: gdal_translate

Description

R wrapper for gdal_translate

Usage

gdal_translate(src_dataset, dst_dataset, ot, strict, of = "GTiff", b, mask,
  expand, outsize, tr, r, scale, exponent, unscale, srcwin, projwin,
  projwin_srs, epo, eco, a_srs, a_ullr, a_nodata, mo, co, gcp, q, sds, stats,
  norat, oo, sd_index, output_Raster = FALSE, ignore.full_scan = TRUE,
  verbose = FALSE, ...)

Arguments

src_dataset
Character. The source dataset name. It can be either file name, URL of data source or subdataset name for multi-dataset files.
dst_dataset
Character. The destination file name.
ot
Character. ("Byte"/"Int16"/"UInt16"/"UInt32"/"Int32"/"Float32"/"Float64"/"CInt16"/"CInt32"/"CFloat32"/"CFloat64"). For the output bands to be of the indicated data type.
strict
Logical. Don't be forgiving of mismatches and lost data when translating to the output format.
of
Character. Select the output format. The default is GeoTIFF (GTiff). Use the short format name.
b
Numeric or Character. Select an input band band for output. Bands are numbered from 1. Multiple bands may be used to select a set of input bands to write to the output file, or to reorder bands. Starting with GDAL 1.8.0, band can also be set to "mask,1" (
mask
Numeric. (GDAL >= 1.8.0) Select an input band band to create output dataset mask band. Bands are numbered from 1. band can be set to "none" to avoid copying the global mask of the input dataset if it exists. Otherwise it is copied by default ("auto"), unl
expand
Character. ("gray"|"rgb"|"rgba"). (From GDAL 1.6.0) To expose a dataset with 1 band with a color table as a dataset with 3 (RGB) or 4 (RGBA) bands. Useful for output drivers such as JPEG, JPEG2000, MrSID, ECW that don't support color indexed datasets. Th
outsize
Numeric. (c(xsize[percentage],ysize[percentage])). Set the size of the output file. Outsize is in pixels and lines unless '%' is attached in which case it is as a fraction of the input image size.
tr
Numeric. c(xres,yres). (starting with GDAL 2.0) set target resolution. The values must be expressed in georeferenced units. Both must be positive values. This is exclusive with -outsize and -a_ullr.
r
Character. resampling_method. ("nearest"|"bilinear"|"cubic"|"cubicspline"|"lanczos"|"average"|"mode") (GDAL >= 2.0) Select a resampling algorithm.
scale
Numeric. (c(src_min,src_max,dst_min,dst_max)). Rescale the input pixels values from the range src_min to src_max to the range dst_min to dst_max. If omitted the output range is 0 to 255. If omitted the input range is automatically computed from the source
exponent
Numeric. (From GDAL 1.11) To apply non-linear scaling with a power function. exp_val is the exponent of the power function (must be postive). This option must be used with the -scale option. If specified only once, -exponent applies to all bands of the ou
unscale
Logical. Apply the scale/offset metadata for the bands to convert scaled values to unscaled values. It is also often necessary to reset the output datatype with the -ot switch.
srcwin
Numeric. (c(xoff,yoff,xsize,ysize)). Selects a subwindow from the source image for copying based on pixel/line location.
projwin
Numeric. (c(ulx,uly,lrx,lry)). Selects a subwindow from the source image for copying (like -srcwin) but with the corners given in georeferenced coordinates.
projwin_srs
Character. srs_def. (GDAL >= 2.0) Specifies the SRS in which to interpret the coordinates given with -projwin. The srs_def may be any of the usual GDAL/OGR forms, complete WKT, PROJ.4, EPSG:n or a file containing the WKT. Note that this does not cause rep
epo
Logical. (Error when Partially Outside) (GDAL >= 1.10) If this option is set, -srcwin or -projwin values that falls partially outside the source raster extent will be considered as an error. The default behaviour starting with GDAL 1.10 is to accept such
eco
Logical. (Error when Completely Outside) (GDAL >= 1.10) Same as -epo, except that the criterion for erroring out is when the request falls completely outside the source raster extent.
a_srs
Character. Override the projection for the output file. The srs_def may be any of the usual GDAL/OGR forms, complete WKT, PROJ.4, EPSG:n or a file containing the WKT.
a_ullr
Numeric. (c(ulx,uly,lrx,lry)). Assign/override the georeferenced bounds of the output file. This assigns georeferenced bounds to the output file, ignoring what would have been derived from the source file.
a_nodata
Numeric. Assign a specified nodata value to output bands. Starting with GDAL 1.8.0, can be set to none to avoid setting a nodata value to the output file if one exists for the source file
mo
Character. ("META-TAG=VALUE"). Passes a metadata key and value to set on the output dataset if possible.
co
Character. ("NAME=VALUE"). Passes a creation option to the output format driver. Multiple -co options may be listed. See format specific documentation for legal creation options for each format.
gcp
Numeric. (c(pixel,line,easting,northing(,elevation))). Add the indicated ground control point to the output dataset. This option may be provided multiple times to provide a set of GCPs.
q
Logical. Suppress progress monitor and other non-error output.
sds
Logical. Copy all subdatasets of this file to individual output files. Use with formats like HDF or OGDI that have subdatasets.
stats
Logical. (GDAL >= 1.8.0) Force (re)computation of statistics.
norat
Logical. (GDAL >= 1.11) Do not copy source RAT into destination dataset.
oo
Character. NAME=VALUE. (starting with GDAL 2.0) Dataset open option (format specific)
sd_index
Numeric. If the file is an HDF4 or HDF5 file, which subdataset should be returned (1 to the number of subdatasets)? If this flag is used, src_dataset should be the filename of the multipart file. This parameter only works if the subdataset names follow
output_Raster
Logical. Return output dst_dataset as a RasterBrick?
ignore.full_scan
Logical. If FALSE, perform a brute-force scan if other installs are not found. Default is TRUE.
verbose
Logical. Enable verbose execution? Default is FALSE.
...
Additional arguments.

Value

  • NULL or if(output_Raster), a RasterBrick.

Details

This is an R wrapper for the 'gdal_translate' function that is part of the Geospatial Data Abstraction Library (GDAL). It follows the parameter naming conventions of the original function, with some modifications to allow for more R-like parameters. For all parameters, the user can use a single character string following, precisely, the gdal_translate format (http://www.gdal.org/gdal_translate.html), or, in some cases, can use R vectors to achieve the same end.

This function assumes the user has a working GDAL on their system. If the "gdalUtils_gdalPath" option has been set (usually by gdal_setInstallation), the GDAL found in that path will be used. If nothing is found, gdal_setInstallation will be executed to attempt to find a working GDAL that has the right drivers as specified with the "of" (output format) parameter.

The user can choose to (optionally) return a RasterBrick of the output file (assuming raster/rgdal supports the particular output format).

References

http://www.gdal.org/gdal_translate.html

Examples

Run this code
# We'll pre-check to make sure there is a valid GDAL install
# and that raster and rgdal are also installed.
# Note this isn't strictly neccessary, as executing the function will
# force a search for a valid GDAL install.
gdal_setInstallation()
valid_install <- !is.null(getOption("gdalUtils_gdalPath"))
if(require(raster) && require(rgdal) && valid_install)
{
# Example from the original gdal_translate documentation:
src_dataset <- system.file("external/tahoe_highrez.tif", package="gdalUtils")
# Original gdal_translate call:
# gdal_translate -of GTiff -co "TILED=YES" tahoe_highrez.tif tahoe_highrez_tiled.tif
gdal_translate(src_dataset,"tahoe_highrez_tiled.tif",of="GTiff",co="TILED=YES",verbose=TRUE)
# Pull out a chunk and return as a raster:
gdal_translate(src_dataset,"tahoe_highrez_tiled.tif",of="GTiff",
srcwin=c(1,1,100,100),output_Raster=TRUE,verbose=TRUE)
# Notice this is the equivalent, but follows gdal_translate's parameter format:
gdal_translate(src_dataset,"tahoe_highrez_tiled.tif",of="GTiff",
srcwin="1 1 100 100",output_Raster=TRUE,verbose=TRUE)
}
# Extract the first subdataset from an HDF4 file:
hdf4_dataset <- system.file("external/test_modis.hdf", package="gdalUtils")
gdal_translate(hdf4_dataset,"test_modis_sd1.tif",sd_index=1)

Run the code above in your browser using DataLab