Description Usage Arguments Details Value Author(s) References Examples
View source: R/gdal_translate.R
R wrapper for gdal_translate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 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,
config,
output_Raster = FALSE,
ignore.full_scan = TRUE,
verbose = FALSE,
...
)
|
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" (or just "mask") to mean the mask band of the first band of the input dataset. |
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"), unless the mask is an alpha channel, or if it is explicitly used to be a regular band of the output dataset ("-b mask"). band can also be set to "mask,1" (or just "mask") to mean the mask band of the 1st band of the input dataset. |
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. The 'gray' value (from GDAL 1.7.0) enables to expand a dataset with a color table that only contains gray levels to a gray indexed dataset. |
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, Matrix or List. (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 data. |
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 output image. It can be repeated several times so as to specify per band parameters. It is also possible to use the "-exponent_bn" syntax where bn is a band number (e.g. "-exponent_2" for the 2nd band of the output dataset) to specify the parameters of one or several specific bands. |
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 reprojection of the dataset to the specified SRS. |
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 requests, when they were considered as an error before. |
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 |
Matrix. Add the indicated ground control point to the output dataset. This option may be provided multiple times to provide a set of GCPs. Columns represent pixel,line,easting,northing and (optionally) elevation, in that order, and rows represent each individual gcp. |
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 the SUBDATASET_n_NAME convention. |
config |
Character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information. |
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. |
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).
NULL or if(output_Raster), a RasterBrick.
Jonathan A. Greenberg (gdalUtils@estarcion.net) (wrapper) and Frank Warmerdam (GDAL lead developer).
http://www.gdal.org/gdal_translate.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # 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.
outdir <- tempdir()
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,file.path(outdir,"tahoe_highrez_tiled.tif"),of="GTiff",
co="TILED=YES",verbose=TRUE)
# Pull out a chunk and return as a raster:
gdal_translate(src_dataset,file.path(outdir,"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,file.path(outdir,"tahoe_highrez_tiled.tif"),of="GTiff",
srcwin="1 1 100 100",output_Raster=TRUE,verbose=TRUE)
}
## Not run:
# Extract the first subdataset from an HDF4 file:
hdf4_dataset <- system.file("external/test_modis.hdf", package="gdalUtils")
gdal_translate(hdf4_dataset,file.path(outdir,"test_modis_sd1.tif"),sd_index=1)
## End(Not run)
|
Warning messages:
1: In gdal_setInstallation() :
No GDAL installation found. Please install 'gdal' before continuing:
- www.gdal.org (no HDF4 support!)
- trac.osgeo.org/osgeo4w/ (with HDF4 support RECOMMENDED)
- www.fwtools.maptools.org (with HDF4 support)
2: In gdal_setInstallation() : If you think GDAL is installed, please run:
gdal_setInstallation(ignore.full_scan=FALSE)
Loading required package: raster
Loading required package: sp
Loading required package: rgdal
rgdal: version: 1.5-18, (SVN revision 1082)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
Path to GDAL shared files: /usr/share/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
Path to PROJ shared files: /usr/share/proj
Linking to sp version:1.4-4
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
NULL
Warning messages:
1: In gdal_setInstallation(ignore.full_scan = ignore.full_scan, verbose = verbose) :
No GDAL installation found. Please install 'gdal' before continuing:
- www.gdal.org (no HDF4 support!)
- trac.osgeo.org/osgeo4w/ (with HDF4 support RECOMMENDED)
- www.fwtools.maptools.org (with HDF4 support)
2: In gdal_setInstallation(ignore.full_scan = ignore.full_scan, verbose = verbose) :
If you think GDAL is installed, please run:
gdal_setInstallation(ignore.full_scan=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.