lib.warplib module

Library of functions required for raster warping in memory or on disk

The guts of warptool.py

pygeotools.lib.warplib.diskwarp(src_ds, res=None, extent=None, t_srs=None, r='cubic', outdir=None, dst_fn=None, dst_ndv=None, verbose=True)[source]

Helper function that calls warp for single input Dataset with output to disk (GDAL GeoTiff Driver)

pygeotools.lib.warplib.diskwarp_multi(src_ds_list, res='first', extent='intersection', t_srs='first', r='cubic', verbose=True, outdir=None, dst_ndv=None)[source]

Helper function for diskwarp of multiple input GDAL Datasets

pygeotools.lib.warplib.diskwarp_multi_fn(src_fn_list, res='first', extent='intersection', t_srs='first', r='cubic', verbose=True, outdir=None, dst_ndv=None)[source]

Helper function for diskwarp of multiple input filenames

pygeotools.lib.warplib.memwarp(src_ds, res=None, extent=None, t_srs=None, r=None, oudir=None, dst_ndv=0, verbose=True)[source]

Helper function that calls warp for single input Dataset with output to memory (GDAL Memory Driver)

pygeotools.lib.warplib.memwarp_multi(src_ds_list, res='first', extent='intersection', t_srs='first', r='cubic', verbose=True, dst_ndv=0)[source]

Helper function for memwarp of multiple input GDAL Datasets

pygeotools.lib.warplib.memwarp_multi_fn(src_fn_list, res='first', extent='intersection', t_srs='first', r='cubic', verbose=True, dst_ndv=0)[source]

Helper function for memwarp of multiple input filenames

pygeotools.lib.warplib.parse_extent(extent, src_ds_list=None, t_srs=None)[source]

Parse arbitrary input extent

Parameters:
  • extent (str or gdal.Dataset or filename or list of float) – Arbitrary input extent
  • src_ds_list (list of gdal.Dataset objects, optional) – Needed if specifying ‘first’, ‘last’, ‘intersection’, or ‘union’
  • t_srs (osr.SpatialReference() object, optional) – Projection for res calculations
Returns:

extent – Output extent [xmin, ymin, xmax, ymax] None if source extent should be preserved

Return type:

list of float

pygeotools.lib.warplib.parse_res(res, src_ds_list=None, t_srs=None)[source]

Parse arbitrary input res

Parameters:
  • res (str or gdal.Dataset or filename or float) – Arbitrary input res
  • src_ds_list (list of gdal.Dataset objects, optional) – Needed if specifying ‘first’ or ‘last’
  • t_srs (osr.SpatialReference() object) – Projection for res calculations, optional
Returns:

res – Output resolution None if source resolution should be preserved

Return type:

float

pygeotools.lib.warplib.parse_rs_alg(r)[source]

Parse resampling algorithm

pygeotools.lib.warplib.parse_srs(t_srs, src_ds_list=None)[source]

Parse arbitrary input t_srs

Parameters:
  • t_srs (str or gdal.Dataset or filename) – Arbitrary input t_srs
  • src_ds_list (list of gdal.Dataset objects, optional) – Needed if specifying ‘first’ or ‘last’
Returns:

t_srs – Output spatial reference system

Return type:

osr.SpatialReference() object

pygeotools.lib.warplib.warp(src_ds, res=None, extent=None, t_srs=None, r='cubic', driver=<Mock name='mock.GetDriverByName()' id='140299429610320'>, dst_fn=None, dst_ndv=None, options=[], verbose=True)[source]

Warp an input dataset with predetermined arguments specifying output res/extent/srs

This is the function that actually calls gdal.ReprojectImage

Parameters:
  • src_ds (gdal.Dataset object) – Dataset to be warped
  • res (float) – Desired output resolution
  • extent (list of float) – Desired output extent in t_srs coordinate system
  • t_srs (osr.SpatialReference()) – Desired output spatial reference
  • r (str) – Desired resampling algorithm
  • driver (GDAL Driver to use for warp) – Either MEM or GTiff
  • dst_fn (str) – Output filename (for disk warp)
  • dst_ndv (float) – Desired output NoData Value
  • options (list) – GDAL creation options for specified driver e.g., [‘COMPRESS=LZW’, ‘TILED=YES’, ‘BIGTIFF=IF_SAFER’]
Returns:

dst_ds – Warped dataset (either in memory or on disk)

Return type:

gdal.Dataset object

pygeotools.lib.warplib.warp_multi(src_ds_list, res='first', extent='intersection', t_srs='first', r='cubic', warptype=<function memwarp>, outdir=None, dst_ndv=None, verbose=True, debug=False)[source]

This parses and checks inputs, then calls desired warp function with appropriate arguments for each input ds

Parameters:
  • src_ds_list (list of gdal.Dataset objects) – List of original datasets to be warped
  • res (arbitrary type) – Desired output resolution
  • extent (arbitrary type) – Desired output extent
  • t_srs (arbitrary type) – Desired output spatial reference
  • r (str) – Desired resampling algorithm
  • warptype (function) – Desired warp type (write to memory or disk)
  • outdir (str) – Desired output directory (for disk warp)
  • dst_ndv (float) – Desired output NoData Value
  • verbose (bool) – Print warp parameters
  • debug (bool) – Print extra information for debugging purposes
Returns:

out_ds_list – List of warped datasets (either in memory or on disk)

Return type:

list of gdal.Dataset objects

pygeotools.lib.warplib.writeout(ds, outfn)[source]

Write ds to disk

Note: Depreciated function - use diskwarp functions when writing to disk to avoid unnecessary CreateCopy