Version 26 (modified by jjr8, 6 years ago)

--

A Simple Example: The HDF SDS to ArcGIS Raster Tool

Many oceanography products are published in HDF format but ArcGIS, as of version 9.2, still cannot read this format. Conversion utilities exist but as far as I've seen, none are available as geoprocessing tools. This tool will convert a Scientific Data Set in an HDF file to ArcGIS raster format. It automatically detects the data type and dimensions from the HDF metadata but you must provide the coordinates of the lower-left corner, the cell size, and the NODATA value. These values may also be present in the metadata as attributes but there is no reliable naming convention for these attributes so the tool does not attempt to guess what they might be.

Invoking the tool from ArcGIS

source:/WikiFiles/Images/HDFSDSToArcGISRaster/HDFSDSToArcGISRaster.png

Example output

Here is  199001.s04m1pfv50-sst-16b.hdf from the  NOAA NODC 4 km AVHRR Pathfinder Project in ArcMap, zoomed to the eastern United States.

source:/WikiFiles/Images/HDFSDSToArcGISRaster/199001.s04m1pfv50-sst-16b.png

Invoking the tool from Python

Each tool is exposed as a Python method. To invoke the tool, you simply import the appropriate module and call the method.

# Initialize the logging system (optional)

from GeoEco.Logging import Logger
Logger.Initialize()

# Convert the HDF to an ArcGIS raster

from GeoEco.DataManagement.HDFs import HDF

HDF.SDSToArcGISRaster(u'c:\\temp16\\199001.s04m1pfv50-sst-16b.hdf', u'c:\\temp16\\sst199001',
                      u'sst', -180.0, -90.0, 0.0439453125, 0.0, buildPyramids=True, overwriteExisting=True)

For brevity, this example omitted the defineProjection parameter (the long projection string does not show up well in the Trac Wiki system).

Invoking the tool through Windows COM Automation

On Windows, each tool is exposed as a COM Automation class. This allows easy invocation from many programming environments, for example:

VBScript

' Initialize the logging system (optional)

Set logger = WScript.CreateObject("GeoEco.Logger") 
logger.Initialize 

' Convert the HDF to an ArcGIS raster

Set hdf = WScript.CreateObject("GeoEco.HDF")

hdf.SDSToArcGISRaster "c:\\temp16\\199001.s04m1pfv50-sst-16b.hdf", "c:\\temp16\\sst199001", _
                      "sst", -180.0, -90.0, 0.0439453125, 0.0, Nothing, True, True

JScript

// Initialize the logging system (optional)

var logger = WScript.CreateObject("GeoEco.Logger");
logger.Initialize();

// Convert the HDF to an ArcGIS raster

var hdf = WScript.CreateObject("GeoEco.HDF");

hdf.SDSToArcGISRaster("c:\\temp16\\199001.s04m1pfv50-sst-16b.hdf", "c:\\temp16\\sst199001",
                      "sst", -180.0, -90.0, 0.0439453125, 0.0, null, true, true);

R

First install the rcom package so you can call COM Automation components from R. Then:

> library(rcom)
> logger <- comCreateObject("GeoEco.Logger")
> comInvoke(logger, "Initialize")
NULL
> hdf <- comCreateObject("GeoEco.HDF")
> comInvoke(hdf, "SDSToArcGISRaster", "c:\\temp16\\199001.s04m1pfv50-sst-16b.hdf", "c:\\temp16\\sst199001", "sst", -180.0, -90.0, 0.0439453125, 0.0)
NULL
> 

MATLAB

>> logger = actxserver('GeoEco.Logger');
>> logger.Initialize();
>> hdf = actxserver('GeoEco.HDF');
>> hdf.SDSToArcGISRaster('c:\\temp16\\199001.s04m1pfv50-sst-16b.hdf', 'c:\\temp16\\sst199001', 'sst', -180.0, -90.0, 0.0439453125, 0.0);
>>

Invoking the tool through Windows COM

Each tool is also exposed on Windows as a normal COM class using a dual interface. For example, the interface to the HDF class is defined in IDL as follows:

[
    dual,
    uuid(478E9F8D-0D41-4630-9D7B-271B2D47CB9E),
    helpstring("IHDF Interface"),
    pointer_default(unique)
]
interface IHDF : IDispatch
{
    // Methods
    [id(1), helpstring("ExtractHeader Method")] HRESULT ExtractHeader([in] BSTR inputFile, [in] BSTR outputFile, [in, defaultvalue(0)] VARIANT_BOOL overwriteExisting);
    [id(2), helpstring("GetSDSDataType Method")] HRESULT GetSDSDataType([in] BSTR inputFile, [in] BSTR sdsName, [out, retval] BSTR *dataType);
    [id(3), helpstring("GetSDSDimensions Method")] HRESULT GetSDSDimensions([in] BSTR inputFile, [in] BSTR sdsName, [out, retval] VARIANT *dimensions);
    [id(4), helpstring("GetSDSNames Method")] HRESULT GetSDSNames([in] BSTR inputFile, [out, retval] VARIANT *sdsNames);
    [id(5), helpstring("SDSToArcGISRaster Method")] HRESULT SDSToArcGISRaster([in] BSTR inputFile, [in] BSTR outputRaster, [in] BSTR sdsName, [in] double xLowerLeftCorner, [in] double yLowerLeftCorner, [in] double cellSize, [in, optional] VARIANT nodataValue, [in, optional] VARIANT coordinateSystem, [in, optional] VARIANT buildPyramids, [in, optional] VARIANT overwriteExisting);
    [id(6), helpstring("SDSToArcInfoASCIIGrid Method")] HRESULT SDSToArcInfoASCIIGrid([in] BSTR inputFile, [in] BSTR outputFile, [in] BSTR sdsName, [in] double xLowerLeftCorner, [in] double yLowerLeftCorner, [in] double cellSize, [in, optional] VARIANT nodataValue, [in, optional] VARIANT overwriteExisting);
    [id(7), helpstring("SDSToBinaryRaster Method")] HRESULT SDSToBinaryRaster([in] BSTR inputFile, [in] BSTR outputFile, [in] BSTR sdsName, [in, defaultvalue(0)] VARIANT_BOOL overwriteExisting);
};

The IDL is automatically generated during the Windows installation package build procedure, and is compiled into a COM type library which is registered during installation. This allows early-bound languages such as C# to instantiate the classes and invoke the methods through normal COM (a "vtable call"):

using GeoEco;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initialize the logging system (optional)

            Logger logger = new Logger();

            logger.Initialize(false, null);

            // Convert the HDF to an ArcGIS raster

            HDF hdf = new HDF();

            hdf.SDSToArcGISRaster("c:\\temp16\\199001.s04m1pfv50-sst-16b.hdf",
                                  "c:\\temp16\\sst199001",
                                  "sst",
                                  -180.0,
                                  -90.0,
                                  0.0439453125,
                                  0.0,
                                  null,
                                  true,
                                  true);
        }
    }
}

Before compiling this code in Microsoft Visual Studio, you must add a reference to the COM component named "GeoEco? 0.1 Type Library".