According to http://gdal.org/python/ the gdal.Warp()
and gdal.WarpOptions()
can be used to warp image from HDF to GeoTIFF format by geolocation arrays, but there is no any example. It would not run, even I try to use .vrt
file including lat/lon and database layers sites.
the VRT file:
<?xml version='1.0' encoding='UTF-8'?>
<VRTDataset rasterXSize="" rasterYSize="">
<Metadata domain="GEOLOCATION">
<MDI key="LINE_OFFSET">0</MDI>
<MDI key="LINE_STEP">1</MDI>
<MDI key="PIXEL_OFFSET">0</MDI>
<MDI key="PIXEL_STEP">1</MDI>
<MDI key="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"]]</MDI>
<MDI key="X_BAND">1</MDI>
<MDI key="X_DATASET">HDF4_SDS:UNKNOWN:"C:/Users/TLQ/Desktop/11/MYD09.A2011093.0410.006.2015217030905.hdf":38', '[2030x1354] Longitude (32-bit floating-point)</MDI>
<MDI key="Y_BAND">1</MDI>
<MDI key="Y_DATASET">HDF4_SDS:UNKNOWN:"C:/Users/TLQ/Desktop/11/MYD09.A2011093.0410.006.2015217030905.hdf":37', '[2030x1354] Latitude (32-bit floating-point)</MDI>
</Metadata>
<VRTRasterBand dataType="Float32" band="1">
<SimpleSource>
<SourceFilename relativeToVRT="0">HDF4_SDS:UNKNOWN:"C:/Users/TLQ/Desktop/11/MYD09.A2011093.0410.006.2015217030905.hdf":45', '[2030x1354] 1km Band 3 Path Radiance (16-bit integer)</SourceFilename>
<SourceBand>1</SourceBand>
</SimpleSource>
</VRTRasterBand>
</VRTDataset>
the code:
vrtfile = "C:/test/MYD09.A2011093.0410.006.2015217030905.hdf"
ds = gdal.Open(file)
subDatasets = ds.GetSubDatasets()
gdal.WarpOptions(geoloc=True, format='GTiff')
gdal.Warp("C:/test/MYD09.A2011093.0410.006.2015217030905.tif",'C:/test/tel.vrt',\ options=gdal.WarpOptions(geoloc=True, format='GTiff'))