Running your first script

Now that we have WbW installed, it's time to start using it. Create a new Python file called wbw_test.py and type the following script into the file.

wbw_test.py

from whitebox_workflows import WbEnvironment

wbe = WbEnvironment()

print(wbe.version())

Notice the underscore in the WbW library name whitebox_workflows compared with the hyphen used in the pip package name whitebox-workflows.

This above script does a few things. First, it imports the WbEnvrionment class from the whitebox_workflows module. Next, we set up the Whitebox Environment. WbEnvrionment is the most important class contained within the whitebox_workflows module. It's the class that is used to manipulate environmental settings, e.g. setting the current working directory. Importantly, all of the tool functions for processing spatial data are methods of the WbEnvironment class, as are the functions for reading and writing spatial data. Lastly, the version() method is called, printing information about our installed version of WbW.

When you run the above script, it should print something similar to this:

Whitebox Workflows for Python v1.1.3 by Whitebox Geospatial Inc. 
Developed by Dr. John B. Lindsay, (c) 2022-2024

Description:
Whitebox Workflows for Python is an advanced geospatial data analysis platform 
and Python extension module.

If the script runs without error, we can be assured that WbW has been installed correctly on our system.

Now let's modify the script above to show us all of the tool functions that we have available to us:

wbw_test.py

from whitebox_workflows import WbEnvironment

wbe = WbEnvironment()

wbe.available_functions()

Depending on the version of WbW that you're running, you should see an ouput similar to this:

...
419. user_defined_weights_filter                  420. vector_hex_binning
421. vector_lines_to_raster                       422. vector_points_to_raster
423. vector_polygons_to_raster                    424. vector_stream_network_analysis
425. version                                      426. viewshed
427. visibility_index                             428. voronoi_diagram
429. watershed                                    430. watershed_from_raster_pour_points
431. weighted_overlay                             432. weighted_sum
433. wetness_index                                434. wilcoxon_signed_rank_test
435. write_function_memory_insertion              436. write_lidar
437. write_raster                                 438. write_vector
439. z_scores                                     440. zonal_statistics

The standard free version of WbW contains at least 440 tool functions, while the professional tier (WbW-Pro) contains over 500 tool functions.

The license_type property of the WbEnvironment class can tell you which version of WbW you are currently running.

license_type.py

from whitebox_workflows import license_info, WbEnvironment

wbe = WbEnvironment()
print(wbe.license_type) # prints either LicenseType.WbW or LicenseType.WbWPro