gdalUtils (version 0.2.0)

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, scale, unscale, srcwin, projwin, epo, eco, a_srs, a_ullr,
  a_nodata, mo, co, gcp, q, sds, stats, additional_commands, sd_index,
  output_Raster = FALSE, 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 "m
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 ("aut
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 data
outsize
Numeric. (c(xsize[ size of the output file. Outsize is in pixels and lines unless ' of the input image size.
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
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.
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 acce
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.
additional_commands
Character. Additional commands to pass directly to gdal_translate.
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.
output_Raster
Logical. Return output dst_dataset as a RasterBrick?
verbose
Logical.
...
Other parameters to pass to gdal_translate.

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
# 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 DataCamp Workspace