[R-sig-Geo] problem reading hdf image

Matteo Mattiuzzi matteo.mattiuzzi at boku.ac.at
Tue Oct 8 14:09:47 CEST 2013


Section 'Subdatasets'ie:
SUBDATASET_1_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_b01


# this should work if R is in the HDF directory! if not redo gdalinfo with the file absolute path:  gdalinfo /path/to/MOD09A1.A2011289.h11v11.005.2011298101214.hdf
r <- raster("HDF4_EOS:EOS_GRID:MOD09A1.A2011289.h11v11.005.2011298101214.hdf:MOD_Grid_500m_Surface_Reflectance:sur_refl_b01")


Take care about the quotation marks! You can do:
r <- raster("HDF4_EOS:EOS_GRID:MOD09A1.A2011289.h11v11.005.2011298101214.hdf:MOD_Grid_500m_Surface_Reflectance:sur_refl_b01") # removed

# or 
r <- raster('HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_b01') # not removed



# The MODIS Package contains the function 'getSds' that extracts the SDS name, may you find something usable in there.


I hope this works as I am writing without testing!
Matteo


>>> Agustin Lobo <alobolistas at gmail.com> 10/08/13 1:45 PM >>>
Here it goes, thaks a lot for your help:

$ gdalinfo MOD09A1.A2011289.h11v11.005.2011298101214.hdf
Driver: HDF4/Hierarchical Data Format Release 4
Files: MOD09A1.A2011289.h11v11.005.2011298101214.hdf
Size is 512, 512
Coordinate System is `'
Metadata:
  ASSOCIATEDINSTRUMENTSHORTNAME=MODIS
  ASSOCIATEDPLATFORMSHORTNAME=Terra
  ASSOCIATEDSENSORSHORTNAME=MODIS
  AUTOMATICQUALITYFLAG=Passed
  AUTOMATICQUALITYFLAGEXPLANATION=Always Passed
  CHARACTERISTICBINANGULARSIZE250M=7.5
  CHARACTERISTICBINANGULARSIZE500M=15.0
  CHARACTERISTICBINSIZE250M=231.656358263889
  CHARACTERISTICBINSIZE500M=463.312716527778
  DATACOLUMNS250M=4800
  DATACOLUMNS500M=2400
  DATAROWS250M=4800
  DATAROWS500M=2400
  DAYNIGHTFLAG=Day
  DESCRREVISION=5.1
  EASTBOUNDINGCOORDINATE=-63.8417981939892
  EQUATORCROSSINGDATE=2011-10-16
  EQUATORCROSSINGDATE=2011-10-16
  EQUATORCROSSINGDATE=2011-10-17
  EQUATORCROSSINGDATE=2011-10-17
  EQUATORCROSSINGDATE=2011-10-18
  EQUATORCROSSINGDATE=2011-10-19
  EQUATORCROSSINGDATE=2011-10-19
  EQUATORCROSSINGDATE=2011-10-20
  EQUATORCROSSINGDATE=2011-10-21
  EQUATORCROSSINGDATE=2011-10-21
  EQUATORCROSSINGDATE=2011-10-22
  EQUATORCROSSINGDATE=2011-10-23
  EQUATORCROSSINGDATE=2011-10-23
  EQUATORCROSSINGLONGITUDE=-50.6540495500062
  EQUATORCROSSINGLONGITUDE=-52.2073110490786
  EQUATORCROSSINGLONGITUDE=-55.295882063234
  EQUATORCROSSINGLONGITUDE=-58.3832333779475
  EQUATORCROSSINGLONGITUDE=-61.4709999916156
  EQUATORCROSSINGLONGITUDE=-66.1122213699271
  EQUATORCROSSINGLONGITUDE=-69.2001737045505
  EQUATORCROSSINGLONGITUDE=-72.2878369750113
  EQUATORCROSSINGLONGITUDE=-75.3752441195227
  EQUATORCROSSINGLONGITUDE=-76.9284675895243
  EQUATORCROSSINGLONGITUDE=-80.0171825878646
  EQUATORCROSSINGLONGITUDE=-83.1045607322162
  EQUATORCROSSINGLONGITUDE=-86.1925733248845
  EQUATORCROSSINGTIME=13:52:00.296015
  EQUATORCROSSINGTIME=13:58:11.783455
  EQUATORCROSSINGTIME=14:10:33.050881
  EQUATORCROSSINGTIME=14:22:54.072603
  EQUATORCROSSINGTIME=14:35:15.964468
  EQUATORCROSSINGTIME=14:53:48.976317
  EQUATORCROSSINGTIME=15:06:10.109374
  EQUATORCROSSINGTIME=15:18:31.590110
  EQUATORCROSSINGTIME=15:30:53.380135
  EQUATORCROSSINGTIME=15:37:04.883419
  EQUATORCROSSINGTIME=15:49:26.174422
  EQUATORCROSSINGTIME=16:01:47.186363
  EQUATORCROSSINGTIME=16:14:09.091656
  EXCLUSIONGRINGFLAG=N
  GEOANYABNORMAL=False
  GEOESTMAXRMSERROR=50.0
  GLOBALGRIDCOLUMNS250M=172800
  GLOBALGRIDCOLUMNS500M=86400
  GLOBALGRIDROWS250M=86400
  GLOBALGRIDROWS500M=43200
  GRANULEBEGINNINGDATETIME=2011-10-16T13:55:00.000000Z,
2011-10-17T14:40:00.000000Z, 2011-10-18T15:20:00.000000Z,
2011-10-19T14:25:00.000000Z, 2011-10-20T15:10:00.000000Z,
2011-10-21T14:15:00.000000Z, 2011-10-22T14:55:00.000000Z,
2011-10-23T14:00:00.000000Z
  GRANULEDAYNIGHTFLAG=Day, Day, Day, Day, Day, Day, Day, Day
  GRANULEDAYOFYEAR=289, 290, 291, 292, 293, 294, 295, 296
  GRANULEENDINGDATETIME=2011-10-16T15:40:00.000000Z,
2011-10-17T16:25:00.000000Z, 2011-10-18T15:30:00.000000Z,
2011-10-19T16:10:00.000000Z, 2011-10-20T15:15:00.000000Z,
2011-10-21T16:00:00.000000Z, 2011-10-22T15:05:00.000000Z,
2011-10-23T15:50:00.000000Z
  GRINGPOINTLATITUDE=-29.9999999973059, -19.900618521232,
-19.931832012974, -30.0325512403038
  GRINGPOINTLONGITUDE=-80.8290376770946, -74.4810824411033,
-63.597163215181, -69.0095124954365
  GRINGPOINTSEQUENCENO=1, 2, 3, 4
  HDFEOSVersion=HDFEOS_V2.9
  HORIZONTALTILENUMBER=11
  INPUTPOINTER=MOD09GQ.A2011289.h11v11.005.2011291223308.hdf,
MOD09GQ.A2011290.h11v11.005.2011292054307.hdf,
MOD09GQ.A2011291.h11v11.005.2011293071509.hdf,
MOD09GQ.A2011292.h11v11.005.2011294224418.hdf,
MOD09GQ.A2011293.h11v11.005.2011295051850.hdf,
MOD09GQ.A2011294.h11v11.005.2011296053736.hdf,
MOD09GQ.A2011295.h11v11.005.2011297053810.hdf,
MOD09GQ.A2011296.h11v11.005.2011298095713.hdf,
MOD09GA.A2011289.h11v11.005.2011291223308.hdf,
MOD09GA.A2011290.h11v11.005.2011292054307.hdf,
MOD09GA.A2011291.h11v11.005.2011293071509.hdf,
MOD09GA.A2011292.h11v11.005.2011294224418.hdf,
MOD09GA.A2011293.h11v11.005.2011295051850.hdf,
MOD09GA.A2011294.h11v11.005.2011296053736.hdf,
MOD09GA.A2011295.h11v11.005.2011297053810.hdf,
MOD09GA.A2011296.h11v11.005.2011298095713.hdf
  LOCALGRANULEID=MOD09A1.A2011289.h11v11.005.2011298101214.hdf
  LOCALVERSIONID=5.0.11
  LONGNAME=MODIS/Terra Surface Reflectance 8-Day L3 Global 500m SIN Grid
  NADIRDATARESOLUTION250M=250m
  NADIRDATARESOLUTION500M=500m
  NORTHBOUNDINGCOORDINATE=-19.9999999982039
  NUMBEROFGRANULES=8
  NUMBEROFORBITS=13
  ORBITNUMBER=62913
  ORBITNUMBER=62914
  ORBITNUMBER=62928
  ORBITNUMBER=62929
  ORBITNUMBER=62943
  ORBITNUMBER=62957
  ORBITNUMBER=62958
  ORBITNUMBER=62972
  ORBITNUMBER=62986
  ORBITNUMBER=62987
  ORBITNUMBER=63001
  ORBITNUMBER=63015
  ORBITNUMBER=63016
  PARAMETERNAME=MOD09A1
  PERCENTCLOUDY=15
  PERCENTLAND=39
  PERCENTLANDSEAMASKCLASS=1, 39, 0, 0, 0, 0, 0, 59
  PERCENTLOWSUN=0
  PERCENTPROCESSED=100
  PERCENTSHADOW=4
  PGEVERSION=5.0.11
  PROCESSINGCENTER=MODAPS
  PROCESSINGENVIRONMENT=Linux minion5550 2.6.18-274.3.1.el5PAE #1 SMP
Tue Sep 6 20:56:05 EDT 2011 i686 i686 i386 GNU/Linux
  PROCESSVERSION=5.0.11
  PRODUCTIONDATETIME=2011-10-25T10:12:15.000Z
  QAPERCENTGOODQUALITY=95
  QAPERCENTINTERPOLATEDDATA=0
  QAPERCENTMISSINGDATA=0
  QAPERCENTNOTPRODUCEDCLOUD=0
  QAPERCENTNOTPRODUCEDOTHER=0
  QAPERCENTOTHERQUALITY=4
  QAPERCENTOUTOFBOUNDSDATA=0
  QAPERCENTPOOROUTPUT500MBAND1=7
  QAPERCENTPOOROUTPUT500MBAND2=20
  QAPERCENTPOOROUTPUT500MBAND3=0
  QAPERCENTPOOROUTPUT500MBAND4=0
  QAPERCENTPOOROUTPUT500MBAND5=0
  QAPERCENTPOOROUTPUT500MBAND6=0
  QAPERCENTPOOROUTPUT500MBAND7=2
  QUALITYCLASSPERCENTAGE500MBAND1=93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 7, 0, 0
  QUALITYCLASSPERCENTAGE500MBAND2=80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 20, 0, 0
  QUALITYCLASSPERCENTAGE500MBAND3=100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
  QUALITYCLASSPERCENTAGE500MBAND4=100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
  QUALITYCLASSPERCENTAGE500MBAND5=95, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0,
0, 0, 0, 0
  QUALITYCLASSPERCENTAGE500MBAND6=100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
  QUALITYCLASSPERCENTAGE500MBAND7=96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 2, 2, 0
  RANGEBEGINNINGDATE=2011-10-16
  RANGEBEGINNINGTIME=00:00:00.000000
  RANGEENDINGDATE=2011-10-23
  RANGEENDINGTIME=23:59:59.000000
  REPROCESSINGACTUAL=reprocessed
  REPROCESSINGPLANNED=further update is anticipated
  RESOLUTIONBANDS1AND2=500
  SCIENCEQUALITYFLAG=Not Investigated
  SCIENCEQUALITYFLAGEXPLANATION=See
http://landweb.nascom.nasa.gov/cgi-bin/QA_WWW/qaFlagPage.cgi?sat=terra
for the product Science Quality status.
  SHORTNAME=MOD09A1
  SOUTHBOUNDINGCOORDINATE=-29.9999999973059
  SPSOPARAMETERS=2015
  SYSTEMFILENAME=MOD09GQ.A2011289.h11v11.005.2011291223308.hdf,
MOD09GQ.A2011290.h11v11.005.2011292054307.hdf,
MOD09GQ.A2011291.h11v11.005.2011293071509.hdf,
MOD09GQ.A2011292.h11v11.005.2011294224418.hdf,
MOD09GQ.A2011293.h11v11.005.2011295051850.hdf,
MOD09GQ.A2011294.h11v11.005.2011296053736.hdf,
MOD09GQ.A2011295.h11v11.005.2011297053810.hdf,
MOD09GQ.A2011296.h11v11.005.2011298095713.hdf,
MOD09GA.A2011289.h11v11.005.2011291223308.hdf,
MOD09GA.A2011290.h11v11.005.2011292054307.hdf,
MOD09GA.A2011291.h11v11.005.2011293071509.hdf,
MOD09GA.A2011292.h11v11.005.2011294224418.hdf,
MOD09GA.A2011293.h11v11.005.2011295051850.hdf,
MOD09GA.A2011294.h11v11.005.2011296053736.hdf,
MOD09GA.A2011295.h11v11.005.2011297053810.hdf,
MOD09GA.A2011296.h11v11.005.2011298095713.hdf
  TileID=51011011
  VERSIONID=5
  VERTICALTILENUMBER=11
  WESTBOUNDINGCOORDINATE=-80.8290376770946
Subdatasets:
  SUBDATASET_1_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_b01
  SUBDATASET_1_DESC=[2400x2400] sur_refl_b01
MOD_Grid_500m_Surface_Reflectance (16-bit integer)
  SUBDATASET_2_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_b02
  SUBDATASET_2_DESC=[2400x2400] sur_refl_b02
MOD_Grid_500m_Surface_Reflectance (16-bit integer)
  SUBDATASET_3_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_b03
  SUBDATASET_3_DESC=[2400x2400] sur_refl_b03
MOD_Grid_500m_Surface_Reflectance (16-bit integer)
  SUBDATASET_4_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_b04
  SUBDATASET_4_DESC=[2400x2400] sur_refl_b04
MOD_Grid_500m_Surface_Reflectance (16-bit integer)
  SUBDATASET_5_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_b05
  SUBDATASET_5_DESC=[2400x2400] sur_refl_b05
MOD_Grid_500m_Surface_Reflectance (16-bit integer)
  SUBDATASET_6_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_b06
  SUBDATASET_6_DESC=[2400x2400] sur_refl_b06
MOD_Grid_500m_Surface_Reflectance (16-bit integer)
  SUBDATASET_7_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_b07
  SUBDATASET_7_DESC=[2400x2400] sur_refl_b07
MOD_Grid_500m_Surface_Reflectance (16-bit integer)
  SUBDATASET_8_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_qc_500m
  SUBDATASET_8_DESC=[2400x2400] sur_refl_qc_500m
MOD_Grid_500m_Surface_Reflectance (32-bit unsigned integer)
  SUBDATASET_9_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_szen
  SUBDATASET_9_DESC=[2400x2400] sur_refl_szen
MOD_Grid_500m_Surface_Reflectance (16-bit integer)
  SUBDATASET_10_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_vzen
  SUBDATASET_10_DESC=[2400x2400] sur_refl_vzen
MOD_Grid_500m_Surface_Reflectance (16-bit integer)
  SUBDATASET_11_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_raz
  SUBDATASET_11_DESC=[2400x2400] sur_refl_raz
MOD_Grid_500m_Surface_Reflectance (16-bit integer)
  SUBDATASET_12_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_state_500m
  SUBDATASET_12_DESC=[2400x2400] sur_refl_state_500m
MOD_Grid_500m_Surface_Reflectance (16-bit unsigned integer)
  SUBDATASET_13_NAME=HDF4_EOS:EOS_GRID:"MOD09A1.A2011289.h11v11.005.2011298101214.hdf":MOD_Grid_500m_Surface_Reflectance:sur_refl_day_of_year
  SUBDATASET_13_DESC=[2400x2400] sur_refl_day_of_year
MOD_Grid_500m_Surface_Reflectance (16-bit unsigned integer)
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  512.0)
Upper Right (  512.0,    0.0)
Lower Right (  512.0,  512.0)
Center      (  256.0,  256.0)


On Tue, Oct 8, 2013 at 1:34 PM, Matteo Mattiuzzi
<matteo.mattiuzzi at boku.ac.at> wrote:
> Dear Agus,
>
> yes please send the output of gdalinfo (close to the end is the string you have to use).
>
>
> Matteo
>
>
>
>
>
>>>> Agustin Lobo <alobolistas at gmail.com> 10/07/13 5:42 PM >>>
> Hi!
>
> I get the following error when try to read an hdf image (release 4):
>
>> modisima <- stack(file.path(modisdir,"MOD09A1.A2011289.h11v11.005.2011298101214.hdf"))
> rgdal: version: 0.8-11, (SVN revision 479M)
> Geospatial Data Abstraction Library extensions to R successfully loaded
> Loaded GDAL runtime: GDAL 1.10.0, released 2013/04/24
> Path to GDAL shared files: /usr/share/gdal/1.10
> Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
> Path to PROJ.4 shared files: (autodetected)
> Error in GDALinfo(filename, silent = silent, returnRAT = RAT,
> returnCategoryNames = RAT) :
>   object 'RATlist' not found
> Error in .rasterObjectFromFile(x, objecttype = "RasterBrick", ...) :
>   Cannot create a RasterLayer object from this file.
> In addition: Warning message:
> In dim(x) : no bands in dataset
>
> Also:
>
>> GDALinfo(file.path(modisdir,"MOD09A1.A2011289.h11v11.005.2011298101214.hdf"))
> Error in GDALinfo(file.path(modisdir,
> "MOD09A1.A2011289.h11v11.005.2011298101214.hdf")) :
>   object 'scaleOffset' not found
> In addition: Warning messages:
> 1: In dim(x) : no bands in dataset
> 2: In GDALinfo(file.path(modisdir,
> "MOD09A1.A2011289.h11v11.005.2011298101214.hdf")) :
>   GeoTransform values not available
>
> Nevertheless, hdf4 and 5 are listed by gdalDrivers() and, on the linux
> terminal, I do get
> output from gdalinfo (quite long, let me know if I should send it).
> Also, I can display the
> image in Qgis with no problem.
>
> Any idea on where the problem could be?
> Thanks,
> Agus
>
>> sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
> LC_TIME=es_ES.UTF-8        LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=es_ES.UTF-8    LC_MESSAGES=en_US.UTF-8
> LC_PAPER=es_ES.UTF-8       LC_NAME=C
>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
> LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] rgdal_0.8-11  MODIS_0.10-8  raster_2.1-49 sp_1.0-13
>
> loaded via a namespace (and not attached):
> [1] grid_3.0.2      lattice_0.20-23 tools_3.0.2
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>



More information about the R-sig-Geo mailing list