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>
  <VRTRasterBand dataType="Float32" band="1">
      <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>

the code:

file = "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'))

1 Answer 1


You have two options here:

1) Create a gdal.WarpOptions object and pass it to gdal.Warp as the options argument, just as you are doing (although you can skip the fourth line as you are creating the same object on the fifth line).

2) Create a dictionary with the arguments and pass it as keyword arguments to gdal.Warp. For example:

kwargs = {'format': 'GTiff', 'geoloc': True}
ds = gdal.Warp('C:/test/MYD09.A2011093.0410.006.2015217030905.tif', 'C:/test/tel.vrt', **kwargs)
del ds

Check the gdal.WarpOptions documentation to see what other keywords you can pass, as their names slightly differ from the gdalwarp command line utility.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.