veranda.raster package

Subpackages

Submodules

veranda.raster.gdalport module

Some handy functions using GDAL to manage geospatial raster data.

veranda.raster.gdalport.call_gdal_util(util_name, src_files, dst_file=None, options=None, gdal_path=None) Tuple[bool, str][source]

Call a GDAL utility to run a GDAL operation (see http://www.gdal.org/gdal_utilities.html).

Parameters:
  • util_name (str) – Pre-defined name of the utility, e.g. “gdal_translate”, which converts raster data between different formats, potentially performing some operations like sub-settings, resampling, or rescaling pixels.

  • src_files (str or list of str) – The name(s) of the source data. It can be either a file path, URL to the data source or a sub-dataset name for multi-dataset file.

  • dst_file (str, optional) – Full system path to the output file. Defaults to None, i.e. the GDAL utility itself deals with defining a file path.

  • options (dict, optional) – A dictionary storing additional settings for the process. You can find all options at http://www.gdal.org/gdal_utilities.html

  • gdal_path (str, optional) – The path where your GDAL utilities are installed. By default, this function tries to look up this path in the environment variable “GDAL_UTIL_HOME”. If this variable is not set, then gdal_path must be provided as a key-word argument.

Returns:

  • successful (bool) – True if process was successful.

  • output (str) – Console output.

veranda.raster.gdalport.convert_gdal_options_to_command_list(options) list[source]

Prepares command line arguments for a GDAL utility.

Parameters:

options (dict, optional) – A dictionary storing additional settings for the process. You can find all options at http://www.gdal.org/gdal_utilities.html

Returns:

cmd_options – Command line options for a GDAL utility given as a list of strings.

Return type:

list of str

veranda.raster.gdalport.dtype_np2gdal(np_dtype) object[source]

Get GDAL data type from a NumPy-style data type.

Parameters:

np_dtype (str) – NumPy-style data type, e.g. “uint8”.

Returns:

GDAL data type.

Return type:

str

veranda.raster.gdalport.gen_qlook(src_file, dst_file=None, src_nodata=None, stretch=None, resize_factor=('3%', '3%'), ct=None, scale=True, output_format='GTiff', gdal_path=None) Tuple[bool, str][source]

Generates a quick-look image.

Parameters:
  • src_file (str) – The name(s) of the source data. It can be either a file path, URL to the data source or a sub-dataset name for multi-dataset file.

  • dst_file (str, optional) – Full system path to the output file. If not provided, the output file path will be a combination of src_file + ‘_qlook’.

  • src_nodata (int, optional) – No data value of the input image. Defaults to None. If it is not None, then it will be transformed to 0 if it is smaller than minimum value range or to 255 if it is larger than the maximum value range.

  • stretch (2-tuple of number, optional) – Minimum and maximum input pixel value to consider for scaling pixels to 0-255. If omitted (default), pixel values will be scaled to the minimum and maximum value.

  • resize_factor (2-tuple of str, optional) – Size of the output file in pixels and lines, unless ‘%’ is attached in which case it is as a fraction of the input image size. The default is (‘3%’, ‘3%’).

  • ct (gdal.ColorTable, optional) – GDAL’s color table used for displaying the quick-look data. Defaults to None.

  • scale (bool, optional) – If True, pixel values will be scaled to 0-255 if stretch is given.

  • output_format (str) – Output format of the quick-look. At the moment, ‘GTiff’ (default) and ‘JPEG’ are supported.

  • gdal_path (str, optional) – The path where your GDAL utilities are installed. By default, this function tries to look up this path in the environment variable “GDAL_UTIL_HOME”. If this variable is not set, then gdal_path must be provided as a key-word argument.

Returns:

  • successful (bool) – True if process was successful.

  • output (str) – Console output.

veranda.raster.gdalport.rtype_str2gdal(resampling_method) object[source]

Get GDAL resample type from resampling method.

Parameters:

resampling_method (str) – Resampling method, e.g. “cubic”.

Returns:

GDAL resampling.

Return type:

object

veranda.raster.gdalport.string2cli_arg(string) str[source]

Decorates the given string with double quotes.

veranda.raster.gdalport.try_get_gdal_installation_path(gdal_path=None) str[source]

Tries to find the system path to the GDAL utilities if not already provided.

Parameters:

gdal_path (str, optional) – The path where your GDAL utilities are installed. By default, this function tries to look up this path in the environment variable “GDAL_UTIL_HOME”. If this variable is not set, then gdal_path must be provided as a key-word argument.

Returns:

gdal_path – Path to installed GDAL utilities.

Return type:

str

Module contents