Description Usage Arguments Note Author(s) Examples
The function applies gdal_translate or gdalwarp to clip, reproject and/or warp raster files. The choice of the algorythm is based on the comparison between input and output projections (gdal_translate if they are equal, gdalwarp elsewhere). If not specified, the output format of each file is the same of the corresponding source file.
1 2 3 |
srcfiles |
A vector of input file paths (managed by GDAL). |
dstfiles |
A vector of corresponding output file paths. |
of |
The output format (use the short format name). Default is the format of every input filename. |
ref |
Path of the raster taken as reference: if provided,
parameters regarding the output grid (alignment, resolution and
extent) are taken from this raster. To set differently some of
these values, specify also other values of |
mask |
Spatial path or object from which to take the extent
of output files. If it is a polygon, this is used as masking layer;
otherwise, only the bounding box is considered;. If both |
tr |
Numeric. ( |
t_srs |
Target spatial reference set (character). The coordinate systems that can be passed are anything supported by the OGRSpatialReference.SetFromUserInput() call, which includes EPSG PCS and GCSes (ie. EPSG:4296), PROJ.4 declarations (as above), or the name of a .prf file containing well known text. |
r |
Resampling_method ("near"|"bilinear"|"cubic"|"cubicspline"| "lanczos"|"average"|"mode"|"max"|"min"|"med"|"q1"|"q3"). |
dstnodata |
Set nodata values for output bands (different values
can be supplied for each band). If more than one value is supplied
all values should be quoted to keep them together as a single
operating system argument. New files will be initialized to this
value and if possible the nodata value will be recorded in the output
file. Use a value of NA to ensure that nodata is not defined.
A vector with the same length of |
overwrite |
Logical value: should existing output files be overwritten? (default: FALSE) |
tmpdir |
(optional) Path where intermediate files (maskfile) will be created. Default is a temporary directory. |
rmtmp |
(optional) Logical: should temporary files be removed? (Default: TRUE) |
... |
Additional parameters of gdalwarp or gdal_translate
(different from |
License: GPL 3.0
Luigi Ranghetti, phD (2017) ranghetti.l@irea.cnr.it
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | ## Not run:
srcfiles <- c("/path/of/a/s2/file.tif",
"/path/of/another/s2/file.tif")
crop_poly <- c("/path/of/a/polygon/vector.shp")
# Simple clip
gdal_warp(srcfiles[1],
test0_clip <- file.path(tempdir(),"test0_clip.tif"),
mask = get_extent(crop_poly))
# Clip and mask
gdal_warp(srcfiles,
test0_mask <- c(file.path(tempdir(),"test0_mask.tif"),
tempfile()),
mask = crop_poly)
# Warp on a reference raster
gdal_warp(srcfiles[1],
test1 <- file.path(tempdir(),"test1.tif"),
ref = test0_mask[1])
# Reproject all the input file
gdal_warp(srcfiles[1],
test2 <- file.path(tempdir(),"test2.tif"),
t_srs = "+init=epsg:32631")
# Reproject and clip on a bounding box
gdal_warp(srcfiles[1],
test3a <- file.path(tempdir(),"test3a.tif"),
mask = get_extent(crop_poly),
t_srs = "+init=epsg:32631")
# Reproject and clip on polygon (masking outside)
gdal_warp(srcfiles[1],
test3b <- file.path(tempdir(),"test3b.tif"),
mask = crop_poly,
t_srs = "+init=epsg:32631")
# Workaround to clip on a bounding box without
# enlarging it too much (cause of the reprojection)
gdal_warp(srcfiles[1],
test3c <- file.path(tempdir(),"test3c.tif"),
mask = st_cast(crop_poly,"LINESTRING"),
t_srs = "+init=epsg:32631")
# Use a reference raster with a different projection
gdal_warp(srcfiles[1],
test4a <- file.path(tempdir(),"test4a.tif"),
ref = test3b)
# Use a reference raster with a different projection
# and specify a different bounding box
gdal_warp(srcfiles[1],
test4b <- file.path(tempdir(),"test4b.tif"),
mask = test0_clip,
ref = test3b)
# Use a reference raster with a different projection and a mask
gdal_warp(srcfiles[1],
test4c <- file.path(tempdir(),"test4c.tif"),
mask = crop_poly,
ref = test3b)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.