Reading and writing data

WbW supports reading and writing many types of raster, vector, and LiDAR data formats.

from whitebox_workflows import WbEnvironment

wbe = WbEnvironment()

wbe.working_directory = 'path/containing/data/files'

# Reading raster data
my_raster = wbe.read_raster('file_name.tif')

# Or read_rasters (with an 's') for multiple rasters at once...
my_raster1, my_raster2 = wbe.read_rasters('file_name1.tif', 'file_name2.tif')

# Writing raster data
wbe.write_raster(my_raster, 'output.tif')

# You can also ask WbW to compress the written raster
wbe.write_raster(my_raster, 'output.tif', compress=True) # Only GeoTIFF compression is supported.

# Reading vector data
my_vector = wbe.read_vector('file_name.shp')

my_vector1, my_vector2 = wbe.read_vectors('file_name1.shp', 'file_name2.shp')

# Writing vector data
wbe.write_vector(my_vector, 'output.shp')

# Reading LiDAR data
my_lidar = wbe.read_lidar('file_name.laz')

my_lidar1, my_lidar2 = wbe.read_lidars('file_name1.laz', 'file_name2.laz')

# Writing LiDAR data
wbe.write_lidar(my_lidar, 'output.laz')

Supported Data Formats

Raster formats

WbW can currently support reading/writing raster data in several common formats.

FormatExtensionReadWrite
GeoTIFF*.tif, *.tiffXX
Big GeoTIFF*.tif, *.tiffXX
Esri ASCII*.txt, *.ascXX
Esri BIL*.bil, *.hdrXX
Esri Binary*.flt and *.hdrXX
GRASS ASCII*.txt, *.ascXX
Idrisi*.rdc and *.rstXX
SAGA Binary*.sdat and *.sgrdXX
Surfer ASCII*.grdXX
Surfer Binary*.grdXX
Whitebox*.tas and *.depXX

Throughout this manual code examples that manipulate raster files all use the GeoTIFF format (.tif) but any of the supported file extensions can be used in its place.

WbW is able to read GeoTIFFs compressed using the PackBits, DEFLATE, and LZW methods. Compressed GeoTIFFs, created using the DEFLATE algorithm, can also be output from any tool that generates raster output files by using compress=True.

Vector Formats

At present, there is limited support in WbW for working with vector geospatial data formats. The only supported vector format is the ESRI Shapefile. Shapefiles geometries (.shp) and attributes (.dbf) can be read and written.

While the Shapefile format is extremely common, it does have certain limitations for vector representation. For example, owing to their 32-bit indexing, Shapefiles are limited in the number of geometries that can be stored in these files. Furthermore, Shapefiles are incapable of storing geometries of more than one type (point, lines, polygons) within the same file. As such, the vector-related tools in WhiteboxTools also carry these same limitations imposed by the Shapefile format.

Point Cloud (LiDAR) Formats

LiDAR data can be read/written in the common LAS and compressed LAZ data formats.