Is there a way to write a GDAL raster to a HDF4 or HDF5 dataset using GDAL? I have found many examples that show how to read HDF datasets, but none on how to write them.
You're right, I get ERROR 6: GDALDriver::Create() ... no create method implemented for this format
in both 32bit and 64bit GDAL for HDF4 but driver HDF4Image will create a HDF4 raster.
To test your installed drivers use GDALInfo --formats
and you should see a full list of the available formats:
Supported Formats:
HDF4 -raster- (ros): Hierarchical Data Format Release 4
HDF4Image -raster- (rw+): HDF4 Dataset
VRT -raster- (rw+v): Virtual Raster
GTiff -raster- (rw+vs): GeoTIFF
NITF -raster- (rw+vs): National Imagery Transmission Format
RPFTOC -raster- (rovs): Raster Product Format TOC format
... and more to follow
The HDF4
driver is ros which means read only, the HDF4Image
is rw+ which means read, write and create.
-
Using HDF4Image works, thank you. On a related note, do you know how to create a name subdataset for the HDF4Image file? – Forrest Williams Aug 12 '20 at 23:33
-
No I don't know how to create a subdataset, it's not a task that I've done before. The API gdal.org/python/osgeo.gdal.Dataset-class.html has GetSubDatasets() to get a reference to all the suddatasets in the raster but no SetSubDataset method. A subdataset is not a band as each can have differing extent, pixel type and cell size. Perhaps it's something simple like specifying the name in the form HDF4_SDS:subdataset_type:file_name:subdataset_index; if you have an existing HDF4 you could use GDALInfo to get the name strings and see if that works, if not please post a new question. – Michael Stimson Aug 17 '20 at 2:04
DCAP_CREATE
andDCAP_CREATECOPY
features are not enabled. Do you know if there is a way that I can install the creation-enabled version of the driver? – Forrest Williams Aug 12 '20 at 1:42import gdal
driver = gdal.GetDriverByName('HDF4')
dst_ds = driver.Create('test.hdf', xsize=512, ysize=512)
– Forrest Williams Aug 12 '20 at 2:29