On 06/20/2012 02:55 PM, Etienne Tourigny wrote:
You could combine them as a multi-band gtiff file for example
No, in this case (MOD09GA data) you cannot, because the subdatasets have different resolutions / raster sizes, and datatypes. Imho there is no other way than to subset each subdataset separately. Things might seem a bit more logical when you consider the main hdf file as a container, like a directory or an archive. You also cannot subset a directory, but you'll need to subset each raster file in it by itself.

Best,
Vincent.


On Wed, Jun 20, 2012 at 9:50 AM, dcd <[email protected]> wrote:
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"]]
[...]
_______________________________________________

Merci beaucoup for the quick reply!

Sorry, I didn't mention in the original post that I need to spatially subset
hundreds of images.

While I know that I can declare subdatasets individually, it will still mean
that I need to combine the individual subdatasets after spatial subsetting.
Also, declaring individual subdatasets by name is a bit of pain, although
doable if need be.

It would be nice if the "-b" switch in gdal_translate could be used for
selecting specific subdatasets within an HDF4Image, either by their full
name (SUBDATASET_1_NAME=....), description (SUBDATASET_1_DESC=...), or
preferably by index ("-b 1" would be equivalent to "SUBDATASET_1", "-b 2"
would be equivalent to "SUBDATASET_2", etc). When reading the gdal_translate
documentation for the "-b" switch, it appears that this should be possible,
although the example is with a GTiff image. If it is possible with HDF
files, I'd like to know how. If not, I will put in a request using the
appropriate channels.

I could always use the MODIS Reprojection Tool to script this task, but I'd
like to have done this exclusively using GDAL.

Anyway, thanks for the tip!



--
View this message in context: 
http://osgeo-org.1560.n6.nabble.com/gdal-translate-Spatial-subset-HDF4Image-with-multiple-subdatasets-tp4982526p4982668.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev


_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to