An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140325/3ca6dfd4/attachment.pl>
reading .hdf files
6 messages · Barry Rowlingson, Jonathan Greenberg, dododave
Dave:
We wrote a package initially inspired by this issue -- gdalUtils,
which are wrappers for the GDAL/OGR utilities. There are even some
hdf helper functions we included (e.g. ?get_subdatasets). Note that
if you are on a Windows or Mac box, it is important you install the
correct version of GDAL first.
Currently, you'll need to extract out the subdataset you want via
?gdal_translate -- there is an example using an HDF4 file in the help.
I would recommend grabbing the R-forge version, since I have a few
fixes in there that aren't on the latest CRAN:
install.packages("gdalUtils", repos="http://R-Forge.R-project.org")
Good luck!
--j
On Tue, Mar 25, 2014 at 11:54 AM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
HDF is a richer file format, and can do more than just store rasters. It can contain multiple objects of different dimension. There's a few ad-hoc standards for regular raster data in HDF though, where objects in the HDF specify the coordinates on the axes - which might be lat, lon, time, height in a 4-D data set and then the 4d hypercube of data itself. See the Binary Data Formats section here: http://cran.r-project.org/doc/manuals/r-release/R-data.html for some packages that can read HDF, but you might have to dig into the metadata to work out how to get the NDVI raster for 01/2012 from your HDF file. Without a sample, we're guessing... Barry On Tue, Mar 25, 2014 at 4:37 PM, dododave <dododave at gmail.com> wrote:
Hi all, I am trying to load an hdf raster file consisting of NDVI values so that I can calculate the mean values within a polygon. I have been able to do this with GEOtiff files, but not with .hdf, which is strange because GIS programs can readily load them. I have looked into rgdal package, but that doesn't seem to have an hdf driver Thanks for any help, Dave -- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/reading-hdf-files-tp7586038.html Sent from the R-sig-geo mailing list archive at Nabble.com.
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
Thank-you Jonathan. I have done as you suggested and installed the latest
version of GDAL and gdalUtils, and then followed the example in the
gdal_translate help.
To convert the hdf file test.hdf to .tif format, I use the following code;
hdf4_dataset <- system.file("test.hdf", package="gdalUtils")
gdal_translate(hdf4_dataset,"test.tif",sd_index=1)
#I renamed the file to test.hdf for simplicity
But this did not work. I got this error;
Error in split1[[1]] : subscript out of bounds
In addition: Warning message:
running command '"C:\Program Files\QGIS Dufour\bin\gdalinfo.exe" ""' had
status 1
The hdf file I was trying to load was;
ftp://ftp.orbit.nesdis.noaa.gov/pub/corp/scsb/wguo/GVIx/GVIx_VH_16km/NVI/GVIX_NL_G16_C07_NVI_Y2005_P26.hdf
Thanks,
Dave
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/reading-hdf-files-tp7586038p7586041.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
Hi Dave:
In all likelihood, it couldn't find your GDAL install. What OS are
you using? What GDAL install did you use? Can you restart R, and
then paste the output of:
library("gdalUtils")
gdal_setInstallation(verbose=TRUE)
And then the output of:
getOption("gdalUtils_gdalPath")
Thanks!
--j
On Tue, Mar 25, 2014 at 12:40 PM, dododave <dododave at gmail.com> wrote:
Thank-you Jonathan. I have done as you suggested and installed the latest
version of GDAL and gdalUtils, and then followed the example in the
gdal_translate help.
To convert the hdf file test.hdf to .tif format, I use the following code;
hdf4_dataset <- system.file("test.hdf", package="gdalUtils")
gdal_translate(hdf4_dataset,"test.tif",sd_index=1)
#I renamed the file to test.hdf for simplicity
But this did not work. I got this error;
Error in split1[[1]] : subscript out of bounds
In addition: Warning message:
running command '"C:\Program Files\QGIS Dufour\bin\gdalinfo.exe" ""' had
status 1
The hdf file I was trying to load was;
ftp://ftp.orbit.nesdis.noaa.gov/pub/corp/scsb/wguo/GVIx/GVIx_VH_16km/NVI/GVIX_NL_G16_C07_NVI_Y2005_P26.hdf
Thanks,
Dave
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/reading-hdf-files-tp7586038p7586041.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
Ok, I actually think you probably got it working somewhat correctly
(if it returns something in the previous step) -- I think the issue
you are having is a few things:
1) Don't use the system.file for your own file -- the system.file()
call is specifically for demo files within a package. Set the working
directory to where your HDF file is located and do:
setwd("path/to/your/hdf/files")
hdf_file <- "GVIX_NL_G16_C07_NVI_Y2005_P26.hdf"
Note you should be able to now do:
gdalinfo(hdf_file)
2) You are using an oddly formatted hdf file -- the get_subdatasets()
routine and the sd_index= parameter only work when the subdatasets are
named following a generally agreed-upon standard, the
"SUBDATASET_n_NAME" format (common to e.g. MODIS, Landsat LEDAPS, and
a lot of other products). In your case, since it doesn't follow these
conventions, you can instead use the sds=TRUE parameter which will
extract ALL subdatasets it finds. The one annoying part about this is
that GDAL won't append the correct suffix (at least, not with version
1.10.0 and earlier), so you will need to rename the output:
outfile="testout"
gdal_translate(hdf_file,outfile,sds=TRUE,verbose=TRUE)
# Notice you now have a file named "testout" with no extension. Let's
rename it:
file.rename(outfile,paste(outfile,".tif",sep="")) # Only if a tif.
Mod this if a different output format.
Hope this helps! I'll make it more clear in future documentation when
the sd_index parameter works.
--j
On Tue, Mar 25, 2014 at 1:52 PM, Jonathan Greenberg <jgrn at illinois.edu> wrote:
Hi Dave:
In all likelihood, it couldn't find your GDAL install. What OS are
you using? What GDAL install did you use? Can you restart R, and
then paste the output of:
library("gdalUtils")
gdal_setInstallation(verbose=TRUE)
And then the output of:
getOption("gdalUtils_gdalPath")
Thanks!
--j
On Tue, Mar 25, 2014 at 12:40 PM, dododave <dododave at gmail.com> wrote:
Thank-you Jonathan. I have done as you suggested and installed the latest
version of GDAL and gdalUtils, and then followed the example in the
gdal_translate help.
To convert the hdf file test.hdf to .tif format, I use the following code;
hdf4_dataset <- system.file("test.hdf", package="gdalUtils")
gdal_translate(hdf4_dataset,"test.tif",sd_index=1)
#I renamed the file to test.hdf for simplicity
But this did not work. I got this error;
Error in split1[[1]] : subscript out of bounds
In addition: Warning message:
running command '"C:\Program Files\QGIS Dufour\bin\gdalinfo.exe" ""' had
status 1
The hdf file I was trying to load was;
ftp://ftp.orbit.nesdis.noaa.gov/pub/corp/scsb/wguo/GVIx/GVIx_VH_16km/NVI/GVIX_NL_G16_C07_NVI_Y2005_P26.hdf
Thanks,
Dave
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/reading-hdf-files-tp7586038p7586041.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
-- Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
2 days later
I am now able to convert the hdf files into GeoTiffs. I have a follow-up question though. I now need to extract the mean ndvi value from within a polygon overlaid on that GeoTiff. The issue I am having is that the code is returning NULL when I do.
rast <- raster("2011_P01.tif")
mean.ndvi <- extract(rast, poly, fun=mean)
mean.ndvi
[[1]] NULL Here is the output when I call rast;
rast
class : RasterLayer dimensions : 904, 2500, 2260000 (nrow, ncol, ncell) resolution : 1, 1 (x, y) extent : 0, 2500, 0, 904 (xmin, xmax, ymin, ymax) coord. ref. : NA data source : /Volumes/GOLONDRINA/tiff/2011_P01.tif names : X2011_P01 values : -32768, 32767 (min, max) Help appreciated! Dave Jonathan Greenberg-3 wrote
Ok, I actually think you probably got it working somewhat correctly
(if it returns something in the previous step) -- I think the issue
you are having is a few things:
1) Don't use the system.file for your own file -- the system.file()
call is specifically for demo files within a package. Set the working
directory to where your HDF file is located and do:
setwd("path/to/your/hdf/files")
hdf_file <- "GVIX_NL_G16_C07_NVI_Y2005_P26.hdf"
Note you should be able to now do:
gdalinfo(hdf_file)
2) You are using an oddly formatted hdf file -- the get_subdatasets()
routine and the sd_index= parameter only work when the subdatasets are
named following a generally agreed-upon standard, the
"SUBDATASET_n_NAME" format (common to e.g. MODIS, Landsat LEDAPS, and
a lot of other products). In your case, since it doesn't follow these
conventions, you can instead use the sds=TRUE parameter which will
extract ALL subdatasets it finds. The one annoying part about this is
that GDAL won't append the correct suffix (at least, not with version
1.10.0 and earlier), so you will need to rename the output:
outfile="testout"
gdal_translate(hdf_file,outfile,sds=TRUE,verbose=TRUE)
# Notice you now have a file named "testout" with no extension. Let's
rename it:
file.rename(outfile,paste(outfile,".tif",sep="")) # Only if a tif.
Mod this if a different output format.
Hope this helps! I'll make it more clear in future documentation when
the sd_index parameter works.
--j
On Tue, Mar 25, 2014 at 1:52 PM, Jonathan Greenberg <
jgrn@
> wrote:
Hi Dave:
In all likelihood, it couldn't find your GDAL install. What OS are
you using? What GDAL install did you use? Can you restart R, and
then paste the output of:
library("gdalUtils")
gdal_setInstallation(verbose=TRUE)
And then the output of:
getOption("gdalUtils_gdalPath")
Thanks!
--j
On Tue, Mar 25, 2014 at 12:40 PM, dododave <
dododave@
> wrote:
Thank-you Jonathan. I have done as you suggested and installed the
latest
version of GDAL and gdalUtils, and then followed the example in the
gdal_translate help.
To convert the hdf file test.hdf to .tif format, I use the following
code;
hdf4_dataset <- system.file("test.hdf", package="gdalUtils")
gdal_translate(hdf4_dataset,"test.tif",sd_index=1)
#I renamed the file to test.hdf for simplicity
But this did not work. I got this error;
Error in split1[[1]] : subscript out of bounds
In addition: Warning message:
running command '"C:\Program Files\QGIS Dufour\bin\gdalinfo.exe" ""' had
status 1
The hdf file I was trying to load was;
ftp://ftp.orbit.nesdis.noaa.gov/pub/corp/scsb/wguo/GVIx/GVIx_VH_16km/NVI/GVIX_NL_G16_C07_NVI_Y2005_P26.hdf
Thanks,
Dave
--
View this message in context:
http://r-sig-geo.2731867.n2.nabble.com/reading-hdf-files-tp7586038p7586041.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
_______________________________________________ R-sig-Geo mailing list
R-sig-Geo@
-- Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN:
jgrn307@
, Gchat: jgrn307, Skype: jgrn3007 -- Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN:
jgrn307@
, Gchat: jgrn307, Skype: jgrn3007
_______________________________________________ R-sig-Geo mailing list
R-sig-Geo@
Jonathan Greenberg-3 wrote
Ok, I actually think you probably got it working somewhat correctly
(if it returns something in the previous step) -- I think the issue
you are having is a few things:
1) Don't use the system.file for your own file -- the system.file()
call is specifically for demo files within a package. Set the working
directory to where your HDF file is located and do:
setwd("path/to/your/hdf/files")
hdf_file <- "GVIX_NL_G16_C07_NVI_Y2005_P26.hdf"
Note you should be able to now do:
gdalinfo(hdf_file)
2) You are using an oddly formatted hdf file -- the get_subdatasets()
routine and the sd_index= parameter only work when the subdatasets are
named following a generally agreed-upon standard, the
"SUBDATASET_n_NAME" format (common to e.g. MODIS, Landsat LEDAPS, and
a lot of other products). In your case, since it doesn't follow these
conventions, you can instead use the sds=TRUE parameter which will
extract ALL subdatasets it finds. The one annoying part about this is
that GDAL won't append the correct suffix (at least, not with version
1.10.0 and earlier), so you will need to rename the output:
outfile="testout"
gdal_translate(hdf_file,outfile,sds=TRUE,verbose=TRUE)
# Notice you now have a file named "testout" with no extension. Let's
rename it:
file.rename(outfile,paste(outfile,".tif",sep="")) # Only if a tif.
Mod this if a different output format.
Hope this helps! I'll make it more clear in future documentation when
the sd_index parameter works.
--j
On Tue, Mar 25, 2014 at 1:52 PM, Jonathan Greenberg <
jgrn@
> wrote:
Hi Dave:
In all likelihood, it couldn't find your GDAL install. What OS are
you using? What GDAL install did you use? Can you restart R, and
then paste the output of:
library("gdalUtils")
gdal_setInstallation(verbose=TRUE)
And then the output of:
getOption("gdalUtils_gdalPath")
Thanks!
--j
On Tue, Mar 25, 2014 at 12:40 PM, dododave <
dododave@
> wrote:
Thank-you Jonathan. I have done as you suggested and installed the
latest
version of GDAL and gdalUtils, and then followed the example in the
gdal_translate help.
To convert the hdf file test.hdf to .tif format, I use the following
code;
hdf4_dataset <- system.file("test.hdf", package="gdalUtils")
gdal_translate(hdf4_dataset,"test.tif",sd_index=1)
#I renamed the file to test.hdf for simplicity
But this did not work. I got this error;
Error in split1[[1]] : subscript out of bounds
In addition: Warning message:
running command '"C:\Program Files\QGIS Dufour\bin\gdalinfo.exe" ""' had
status 1
The hdf file I was trying to load was;
ftp://ftp.orbit.nesdis.noaa.gov/pub/corp/scsb/wguo/GVIx/GVIx_VH_16km/NVI/GVIX_NL_G16_C07_NVI_Y2005_P26.hdf
Thanks,
Dave
--
View this message in context:
http://r-sig-geo.2731867.n2.nabble.com/reading-hdf-files-tp7586038p7586041.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
_______________________________________________ R-sig-Geo mailing list
R-sig-Geo@
-- Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN:
jgrn307@
, Gchat: jgrn307, Skype: jgrn3007 -- Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN:
jgrn307@
, Gchat: jgrn307, Skype: jgrn3007
_______________________________________________ R-sig-Geo mailing list
R-sig-Geo@
-- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/reading-hdf-files-tp7586038p7586072.html Sent from the R-sig-geo mailing list archive at Nabble.com.