Skip to content
Prev 20237 / 29559 Next

resampling MODIS-based raster to PRISM raster to obtain same extent

Julie:

First off, what you are attempting to do is a bit complicated, so try
to not be intimidated!

Second: it might help to understand that HDF files aren't rasters,
persay, they are scientific data "containers" that can CONTAIN raster
files.  So, often the first step is to extract the raster subcomponent
of the HDF file into something more usable.

As Robert mentioned, I have a package designed to make this quite a
bit easier.  First, install a GDAL release that supports HDF4/5 from
http://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries.  On Windows,
this is Osgeo4w.  On Mac this is the Kyngesburye GDAL Frameworks.

Next:

install.packages("gdalUtils", repos="http://R-Forge.R-project.org")
# Note that I'm suggesting the r-forge version which has some key
fixes vs. the CRAN version

Third, you now can run the utilities.  You want to figure out which
subset to extract first using:
library("gdalUtils")
?get_subdatasets
get_subdatasets("pathto/my.hdf") # Look at the examples of this function
# This will return a list of subdatasets.  Make note of the number of
the one you want.

# Now, you can extract that subdataset to any format you want via
gdal_translate:
?gdal_translate
my_hdf_to_tiff <-
gdal_translate("pathto/my.hdf","my_modis_extracted.tif",sd_index=X,output_raster=TRUE)
# Where X is the number of the subdataset you got from get_subdatasets()

# Finally, to sync all the files to the same projection, you can use
my other package "spatial.tools"
install.packages("spatial.tools")
library("spatial.tools")
# And use spatial_sync_raster
?spatial_sync_raster

This function takes two inputs, "unsynced" (the file you are going to
reproject/extend/crop) and "reference" (the file that serves as the
reference projection, resolution, and extent).  Check the parameters
to understand which resampling it will use.

This puts a bunch of steps together in one: reprojection, resampling,
cropping, and expanding the raster.  The final product will be the
unsynced file that will exactly match the projection, extent and pixel
size of the reference.

Hope this helps!

--j
On Tue, Jan 21, 2014 at 7:42 AM, Julie Lee-Yaw <julleeyaw at yahoo.ca> wrote: