[gdal-dev] To to create HDF4 files for GDAL

Etienne Tourigny etourigny.dev at gmail.com
Thu Jan 5 09:32:41 EST 2012


Andreas,

Why don't you simply use the netcdf api to create a GMT file (which
uses the netcdf file format)̣?

Have a look at the gdal hdf4 driver documentation :
http://www.gdal.org/frmt_hdf4.html , section Georeference . It seems
that you custom way of representing georeferencing is not one of the
formats supported by gdal's HDF4 driver.

Etienne

On Thu, Jan 5, 2012 at 11:15 AM, Andreas H. <lists at hilboll.de> wrote:
> Hi there,
>
> when creating HDF4 files outside of GDAL, which metadata do I have to
> write to
> the file such that GDAL can subsequently correctly read the data? In the docs
> I read that only HDF4 files created with GDAL or certain other HDF4 types are
> recognized. However, the files are created "by hand" using the HDF4 API from
> Delphi. I would like to modify this creation in a way such that GDAL can read
> the data.
>
> The HDF files follow the "Scientific DataSet (SDS)" standard. When reading
> the files with GDAL, it looks like this:
>
>   $ gdalinfo datafile.hdf
>   Driver: HDF4Image/HDF4 Dataset
>   Files: datafile.hdf
>   Size is 2880, 1440
>   Coordinate System is `'
>   Metadata:
>     _FillValue=-nan
>     long_name=VCDstrat NO2
>   Geolocation:
>     SRS=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"]]
>     X_DATASET=HDF4_SDS:UNKNOWN:"datafile.hdf":2
>     X_BAND=1
>     Y_DATASET=HDF4_SDS:UNKNOWN:"datafile.hdf":1
>     Y_BAND=1
>     PIXEL_OFFSET=0
>     PIXEL_STEP=1
>     LINE_OFFSET=0
>     LINE_STEP=1
>   Corner Coordinates:
>   Upper Left  (    0.0,    0.0)
>   Lower Left  (    0.0, 1440.0)
>   Upper Right ( 2880.0,    0.0)
>   Lower Right ( 2880.0, 1440.0)
>   Center      ( 1440.0,  720.0)
>   Band 1 Block=2880x347 Type=Float32, ColorInterp=Gray
>
> Obviously, georeferencing is not working. What do I need to do to the HDF4
> file to fix this?
>
> Thanks for your insight,
>
> Andreas.
>
>
> PS: In case anyone is interested, here's the reason why I want to do this:
>
> I have a whole lot of HDF4-SDS files which I want to plot using GMT. So I
> thought using gdal_translate to convert the HDF4 to GRD would be the easiest
> solution. I'm using GDAL 1.8.1 .
>
> However, I'm running into problems which I'm detailing below:
>
> I guess the problem is that GDAL doesn't read the SDS's latitude/longitude
> information. When converting this file then to GMT's grd format, I get a
> warning, which I guess doesn't really matter too much:
>
>   $ gdal_translate -of GMT datafile.hdf test.grd
>   Warning 6: A dataset opened by GDALOpenShared should have the same
> filename (datafile.hdf) and description
> (HDF4_SDS:UNKNOWN:"datafile.hdf":0)
>   Input file size is 2880, 1440
>
> The resulting grd file looks like this:
>
>   $ gdalinfo test.grd
>   Driver: GMT/GMT NetCDF Grid Format
>   Files: test.grd
>          test.grd.aux.xml
>   Size is 2880, 1440
>   Coordinate System is `'
>   Origin = (0.000000000000000,0.000000000000000)
>   Pixel Size = (1.000000000000000,1.000000000000000)
>   Metadata:
>     _FillValue=-nan
>     long_name=VCDstrat NO2
>   Corner Coordinates:
>   Upper Left  (   0.0000000,   0.0000000)
>   Lower Left  (       0.000,    1440.000)
>   Upper Right (    2880.000,       0.000)
>   Lower Right (    2880.000,    1440.000)
>   Center      (    1440.000,     720.000)
>   Band 1 Block=2880x1 Type=Float32, ColorInterp=Gray
>
> When I now try to plot this file using grdimage, I get the following:
>
>   grdimage: GMT ERROR: grid y increment <= 0.0
>   grdimage: Use grdedit -A on your grid file to make region and
> increments compatible [test.grd]
>
> However, running the suggested grdedit -A test.grd doesn't change a thing ...
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list