pyrsgis.raster.trim_file

pyrsgis.raster.trim_file(filename, remove, outfile)[source]

Trim and export raster file

This function trims and exports the raster array by removing the given unwanted value Note that the function will trim raster file for the smallest possible bounding box outside which all the cells in the raster have the value equal to the value passed using remove parameter. This function is built on the pyrsgis.raster.trim function.

Parameters
filestring

Input file name or path to trim.

removeinteger or float or string

The value to be considered as irrelevant at the edges. It can be a integer or a float number. An additional option ‘negative’ is also available that will treat negative values of the array as unnecessary.

outfilestring

Name or path to store the trimemd raster file.

Examples

>>> from pyrsgis import raster
>>> infile = r'E:/path_to_your_file/your_file.tif'
>>> outfile = r'E:/path_to_your_file/trimmed_file.tif'
>>> raster.trim_file(infile, -9999, outfile)

In the above example a raster file which was masked using a polygon but the option ‘match extent of the raster with extent of the input polygon’ was disabled has been used for demonstration. Although this is a classic example of observing unnecessary padding at the edges of a raster file, there can be many more reason for the same. In this particular case, useful values were only towards a corner of the raster surround by NoData cells. Hence, the actual extent of the file was much larger (and unnecessary).

In a similar fashion, any other value can be used to trim the raster array. Using the ‘negative’ option for the remove parameter will treat negative values as unnecessary. It should be noted that cells within the ‘meaningful’ region of the raster that have value same as the remove value will remain unaffected by the trimming process.