Description Usage Arguments Value Author(s) Examples
Un-zip, extract the given layers of COPERNICUS h5 files to tif files. The function can also crop, project and apply gain and offset values
1 2 |
fnames |
|
extent |
A |
extend |
numeric vector of length 1 or 2 (nrow,ncol). Extend the spatial extent of the subwindows (extent argument) by a given number of (rows,cols) |
convertDN |
logical value indicating whether DN values should be converted to physical values (eg vegetation index). Default to TRUE |
outProj |
|
pixelSize |
output pixel size (c(xres,yres)). Default is 'asIn' (same as the input image). Can be set via |
resamplingType |
Resampling method in case of reprojection or change in pixel resolution. Should be one of the following: 'near','bilinear','cubic','cubicspline' |
outPath |
Path where processed files should be stored. Default set via |
job |
Path to append to |
gdalPath |
Path to the gdal binaries. Default set via |
zip |
logical value indicating whether file(s) should be un-zipped before h5 extraction |
layers |
|
allowParallel |
Logical. If a |
... |
arguments passed to |
Return invisibly the list of extracted h5 files. If files are mosaicked, tiles numbers are dropped from the names
Antoine Stevens
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | ## Not run:
# Don't forget to provide in copernicus_options() your user and password details
# for COPERNICUS data portal before running this
# e.g. : copernicus_options(user = "Smith", password = "hello")
# First, get data: NDVI_1km_V1, for JAN 2009
fn <- download_copernicus(product = 'NDVI_1km_V1', begin = '2009-01-01', end = '2009-01-31',
tileH = 19, tileV = 4)
fn # downloaded file names
# extract layers 1,2,3 of the downladed file. Store images in the 'H19V4' folder
extract_copernicus(fnames = fn,job = 'H19V4',layers = c(1:3))
# Now, crop the tile to a given extent (extent argument),
# and add 1 row and col at each side of the data (extend argument)
# This is useful to add a buffer zone, in case of spatial smoothing
# tile location is:
get_tile_copernicus(tileH = 19, tileV = 4)
# create extent object
library(raster)
# extent corresponding to the Delta of the Po
e <- extent(c(10.5,12.5,44,46)) # xmin,xmax,ymin,ymax
f <- extract_copernicus(fnames = fn,extent = e,job = 'H19V4',extend = 1, layers = 2)
f # name of the h5 file(s)
# for each layer, the function append its name to the saved file name
# so we can change the name of the file(s) accordingly
f <- sub('\\.h5','_NDVI.tif',f)
# this is the resulting raster stack
s <- stack(f);s
plot(s)
# extent argument could also be a Raster* object,
# its projection, and resolution are then used to crop/project
# first let's create a raster object using the extent object
r <- raster(e)
projection(r) <- '+init=epsg:4326' # LatLon WGS84
# project to UTM 32N
r <- projectExtent(r,CRS('+init=epsg:32632'))
res(r) <- 1000 # set resolution to 1 km
# now extract COPERNICUS data and match these topology
f <- extract_copernicus(fnames = fn,extent = r,job = 'H19V4',extend = 1, layers = 2)
s <- stack(sub('\\.h5','_NDVI.tif',f));s
plot(s)
# This works with a SpatialPolygons* object too
# resolution can be set through pixelSize (in target geometry)
sPol <- as(e,'SpatialPolygons')
proj4string(sPol) <- CRS('+init=epsg:4326')
sPol <- spTransform(sPol,CRS('+init=epsg:32632')) # project to UTM 32N
f <- extract_copernicus(fnames = fn,extent = sPol,pixelSize = c(2000,2000),
job = 'H19V4',extend = 1, layers = 2)
s <- stack(sub('\\.h5','_NDVI.tif',f));s
plot(s)
# One can also simply reproject using the outProj argument
# and change resolution with the pixelSize argument
f <- extract_copernicus(fnames = fn,outProj = '+init=epsg:32632', pixelSize = c(1000,1000),
job = 'H19V4',layers = 2)
s <- stack(sub('\\.h5','_NDVI.tif',f));s
plot(s)
# extract_copernicus allows also to mosaic files, by grouping file names within a list
# first, download data spanning neighbouring tiles
e <- extent(c(-1,1,49,51)) # the English Channel
# the groupByDate argument allows to return a list of files, grouped by date
fn <- download_copernicus(product, begin = '2009-01-01', end = '2009-01-31',
extent = e,groupByDate = TRUE)
# now extract
f <- extract_copernicus(fnames = fn,extent = e, layers = 2)
f <- sub('\\.h5','_NDVI.tif',f)
s <-stack(f);s
plot(s,1)
# Let's add the COPERNICUS tiling system, projected to Plate Carree
sPol <- spTransform(gen_tile_copernicus(poly = T),CRS("+init=epsg:32662"))
plot(sPol,add=T)
# mosaicking works also with projection
f <- extract_copernicus(fnames = fn,extent = e, outProj = '+init=epsg:32632', layers = 2,
resamplingType = "bilinear")
f <- sub('\\.h5','_NDVI.tif',f)
s <-stack(f);s
plot(s)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.