[gdal-dev] [gdal_translate] Spatial subset HDF4Image with multiple subdatasets?

Even Rouault even.rouault at mines-paris.org
Tue Jun 19 15:02:14 PDT 2012


Le mardi 19 juin 2012 23:55:49, dcd a écrit :
> Hi,
> 
> Is it possible to spatially subset an HDF4Image that contains multiple
> subdatasets using gdal_translate (GDAL 1.9.1)? When using a spatial subset
> switch ("-a_ullr"), I get the following response:
> 
> "Input file contains subdatasets. Please, select one of them for reading."
> 
> This happens regardless of output format specified (HDF4Image, GTiff, ENVI,
> etc.), or whether the "-b" switch has been used as per the examples here:
> http://www.gdal.org/gdal_translate.html. A workaround is to use the "-sds"
> switch allows the process to complete, but (as expected) it processes each
> subdataset as a separate file. I suppose I can just merge these subdatasets
> together again, but I'd like to avoid the extra step. Is this possible?
> 
> I'm working with a MODIS imagery (MOD09GA), but I've had the issues with
> other similar HDF4 datasets.

You can use one of the subdataset names listed by gdalinfo on the HDF file as a 
pseudo-filename usable by any GDAL utility (including gdal_translate).

For example :

$ gdalinfo MOD02HKM.A2011169.1750.005.NRT.hdf
[...]
Subdatasets:
  SUBDATASET_1_NAME=HDF4_EOS:EOS_SWATH:"MOD02HKM.A2011169.1750.005.NRT.hdf":MODIS_SWATH_Type_L1B:EV_500_RefSB
  SUBDATASET_1_DESC=[5x4060x2708] EV_500_RefSB MODIS_SWATH_Type_L1B (16-bit 
unsigned integer)
  SUBDATASET_2_NAME=HDF4_EOS:EOS_SWATH:"MOD02HKM.A2011169.1750.005.NRT.hdf":MODIS_SWATH_Type_L1B:EV_500_RefSB_Uncert_Indexes
  SUBDATASET_2_DESC=[5x4060x2708] EV_500_RefSB_Uncert_Indexes 
MODIS_SWATH_Type_L1B (8-bit unsigned integer)
[...]

$ gdalinfo 
HDF4_EOS:EOS_SWATH:"MOD02HKM.A2011169.1750.005.NRT.hdf":MODIS_SWATH_Type_L1B:EV_500_RefSB

Driver: HDF4Image/HDF4 Dataset
Files: MOD02HKM.A2011169.1750.005.NRT.hdf
Size is 2708, 4060
Coordinate System is `'
GCP Projection = 
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        TOWGS84[0,0,0,0,0,0,0],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9108"]],
    AUTHORITY["EPSG","4326"]]
[...]


More information about the gdal-dev mailing list