convertmodis_gdal module

Convert MODIS HDF file using GDAL Python bindings. It can create GeoTiff file (or other GDAL supported formats) or HDF mosaic file for several tiles.



class pymodis.convertmodis_gdal.convertModisGDAL(hdfname, prefix, subset, res, outformat='GTiff', epsg=None, wkt=None, resampl='NEAREST_NEIGHBOR', vrt=False)[source]

A class to convert modis data from hdf to GDAL formats using GDAL

  • hdfname (str) – name of input data
  • prefix (str) – prefix for output data
  • subset (str) – the subset to consider
  • res (int) – output resolution
  • outformat (str) – output format, it is possible to use all the supported GDAL format
  • epsg (int) – the EPSG code for the preojection of output file
  • wkt (str) – the WKT string for the preojection of output file
  • resampl (str) – the resampling method to use
  • vrt (bool) – True to read GDAL VRT file created with createMosaicGDAL

Reproject all the subset of chosen layer


Reproject VRT created by createMosaicGDAL, function write_vrt with separated=True

class pymodis.convertmodis_gdal.createMosaicGDAL(hdfnames, subset, outformat='HDF4Image')[source]

A class to mosaic modis data from hdf to GDAL formats using GDAL

  • hdfnames (list) – a list containing the name of tile to mosaic
  • subset (str) – the subset of layer to consider
  • outformat (str) – the output format to use, this parameter is not used for the VRT output, supported values are HDF4Image, GTiff, HFA, and maybe something else not tested.
run(output, quiet=False)[source]

Create the mosaic

Parameters:output (str) – the name of output file

Write the XML metadata file for MODIS mosaic

Parameters:prefix (str) – the prefix for the XML file containing metadata
write_vrt(output, separate=True, quiet=False)[source]

Write VRT file

  • output (str) – the prefix of output file
  • separate (bool) – True to write a VRT file for each band, False to write an unique file
class pymodis.convertmodis_gdal.file_info[source]

A class holding information about a GDAL file.

Class copied from

Parameters:filename (str) – Name of file to read.
Returns:1 on success or 0 if the file can’t be opened.
copy_into(t_fh, s_band=1, t_band=1, nodata_arg=None)[source]

Copy this files image into target file.

This method will compute the overlap area of the file_info objects file, and the target gdal.Dataset object, and copy the image data for the common window area. It is assumed that the files are in a compatible projection. no checking or warping is done. However, if the destination file is a different resolution, or different image pixel type, the appropriate resampling and conversions will be done (using normal GDAL promotion/demotion rules).

  • t_fh – gdal.Dataset object for the file into which some or all of this file may be copied.
  • s_band
  • t_band
  • nodata_arg

1 on success (or if nothing needs to be copied), and zero one failure.


Initialize file_info from filename


Return the GDAL resampling method

Parameters:res (str) – the string of resampling method
pymodis.convertmodis_gdal.raster_copy(s_fh, s_xoff, s_yoff, s_xsize, s_ysize, s_band_n, t_fh, t_xoff, t_yoff, t_xsize, t_ysize, t_band_n, nodata=None)[source]

Copy a band of raster into the output file.

Function copied from

pymodis.convertmodis_gdal.raster_copy_with_nodata(s_fh, s_xoff, s_yoff, s_xsize, s_ysize, s_band_n, t_fh, t_xoff, t_yoff, t_xsize, t_ysize, t_band_n, nodata)[source]

Copy a band of raster into the output file with nodata values.

Function copied from