Skip to content

Problem merging rasters after conversion and reprojection of .hdf file

3 messages · Justin Michell, Albin Blaschka, Loïc Dutrieux

#
Hello!

is the function resample() from the raster package what you need?

HTH,
Albin


Am 30.04.2014 01:10, schrieb Justin Michell:

  
    
#
Dear Justin,

gdalwarp is able to reproject/resample and mosaic all at once, and that 
is probably the preferred option in that case (since there are no 
overlapping areas).
See the simplified example below:


###
library(raster)
library(gdalUtils)

dir <- file.path(rasterOptions()$tmpdir, 'MODIS')
dir.create(dir, recursive=TRUE)

# Download two neighboring modis tiles
download.file('http://e4ftl01.cr.usgs.gov/MOLT/MOD13A2.005/2000.04.22/MOD13A2.A2000113.h20v08.005.2006275210548.hdf', 
destfile=file.path(dir, 'NDVI.h20v08.hdf'))
download.file('http://e4ftl01.cr.usgs.gov/MOLT/MOD13A2.005/2000.04.22/MOD13A2.A2000113.h21v08.005.2006275210549.hdf', 
destfile=file.path(dir, 'NDVI.h20v09.hdf'))

# Get list of files downloaded
list <- list.files(dir, full.names=TRUE)
# Get list of sds1
sdsList <- sapply(X=list, FUN=function(x){get_subdatasets(x)[1]})
# Warp
gdalwarp(srcfile=sdsList, t_srs="+proj=longlat +datum=WGS84 +no_defs", 
dstfile=file.path(dir, 'mosaic_latlong.tif'))

r <- raster(file.path(dir, 'mosaic_latlong.tif'))
plot(r)

Hope this helps
Best regards,

--
Lo?c Dutrieux
Laboratory of Geo-Information Science and Remote Sensing
Wageningen University
The Netherlands
On 14-04-30 01:10 AM, Justin Michell wrote: