Learn R Programming

getSpatialData (version 0.0.4)

cropFAST: Crop file to a spatial extent (beta)

Description

cropFAST crops a raster file to a spatial extent using GDAL. It is useful when working with large-scale, memory-intensive datasets.

Usage

cropFAST(file, ext, filename, verbose = TRUE, ...)

Arguments

file

Path to raster file.

ext

Extent object or such from which an extent can be extracted.

filename

Filename of output, if it should be written to disk.

verbose

logical, whether to display details on the function's progress or output on the console.

...

additional arguments passed to writeRaster. Ignored, if filename ends with ".vrt".

Value

Raster* object.

Details

GDAL must be installed. If no GDAL installation is found, cropFAST is masking raster::crop. The input file on disk will not be changed.

See Also

getSentinel_data

Examples

Run this code
# NOT RUN {
library(raster)

## load a file
path_tiff <- "/path/to/file.tiff"
r_tiff <- stack(path_tiff)

## define an AOI
data("aoi_data")
aoi <- aoi_data[[2]] # example AOI

## if necessary, reproject AOI to file CRS
aoi <- spTransform(aoi, crs(r))

## crop (file on disk will not be changed)
r_crop <- cropFAST(path_tiff, ext = aoi)

## crop to a new file
r_crop <- cropFAST(path_tiff, ext = aoi, filename = "/path/to/file_cropped.tiff")
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab