Skip to content

Commit afa1da6

Browse files
authored
Merge pull request #34 from giswqs/v2.1
Updated to WBT v2.1
2 parents 2692a6c + c3c58b8 commit afa1da6

28 files changed

+10638
-3944
lines changed

WBT/PRE/WhiteboxTools.py

Lines changed: 4738 additions & 1909 deletions
Large diffs are not rendered by default.

WBT/PRE/automation.py

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import re
1515
import shutil
16+
import sys
1617
import whitebox
1718
import urllib.request
1819
from zipfile import ZipFile
@@ -96,7 +97,8 @@ def generate_tool_template(tool):
9697
lines.append("class {}(object):\n".format(tool["name"]))
9798
lines.append(" def __init__(self):\n")
9899
lines.append(' self.label = "{}"\n'.format(tool["label"]))
99-
lines.append(' self.description = "{}"\n'.format(tool["description"]))
100+
lines.append(' self.description = "{}"\n'.format(
101+
tool["description"]))
100102
lines.append(' self.category = "{}"\n\n'.format(tool["category"]))
101103
lines.append(" def getParameterInfo(self):\n")
102104
# Loop through parameters
@@ -120,7 +122,7 @@ def generate_tool_template(tool):
120122
lines.append(" param.clearMessage()\n")
121123
lines.append(" return\n\n")
122124
lines.append(" def execute(self, parameters, messages):\n")
123-
# Access parameters throught parameters[x].valueAsText
125+
# Access parameters through parameters[x].valueAsText
124126
lines.append(define_execute(tool["parameters"]))
125127
# redirect standard output to tool dialogue
126128
lines.append(" old_stdout = sys.stdout\n")
@@ -130,7 +132,8 @@ def generate_tool_template(tool):
130132
# line = ' wbt.{}({})\n'.format(to_snakecase(tool['name']), ', '.join(tool['parameters']).replace(", class,", ", cls,"))
131133
line = " wbt.{}({})\n".format(
132134
to_snakecase(tool["name"]),
133-
", ".join(tool_params).replace(", class=class,", ", cls=cls,").replace("input=input", "i=i"),
135+
", ".join(tool_params).replace(", class=class,",
136+
", cls=cls,").replace("input=input", "i=i"),
134137
)
135138

136139
# Deal with name conflict with reserved Python functions (and, or, not)
@@ -176,7 +179,8 @@ def define_tool_params(params):
176179
if data_type["data_type"] == '"DERasterDataset"' and direction == "Output":
177180
data_type["data_type"] = '"DEFile"'
178181
data_type["data_filter"] = '["tif"]'
179-
parameter_type = "Required" # if a filter is used, the parameter must be changed to required.
182+
# if a filter is used, the parameter must be changed to required.
183+
parameter_type = "Required"
180184
elif data_type["data_type"] == '"DERasterDataset"' and direction == "Input":
181185
data_type["data_type"] = '"GPRasterLayer"'
182186
elif data_type["data_type"] == '"DEShapefile"' and direction == "Input":
@@ -193,14 +197,18 @@ def define_tool_params(params):
193197
lines.append(" {} = arcpy.Parameter(\n".format(param))
194198
lines.append(' displayName="{}",\n'.format(items["name"]))
195199
lines.append(' name="{}",\n'.format(param))
196-
lines.append(" datatype={},\n".format(data_type["data_type"]))
197-
lines.append(' parameterType="{}",\n'.format(parameter_type))
200+
lines.append(" datatype={},\n".format(
201+
data_type["data_type"]))
202+
lines.append(
203+
' parameterType="{}",\n'.format(parameter_type))
198204
lines.append(' direction="{}")\n'.format(direction))
199205

200206
if data_type["multi_value"]:
201207
lines.append(" {}.multiValue = True\n".format(param))
202208

203209
if len(data_type["dependency_field"]) > 0:
210+
if data_type["dependency_field"] == "input":
211+
data_type["dependency_field"] = "i"
204212
lines.append(
205213
" {}.parameterDependencies = [{}.name]\n".format(
206214
param, data_type["dependency_field"]
@@ -209,7 +217,8 @@ def define_tool_params(params):
209217

210218
if data_type["data_filter"] != "[]":
211219
if data_type["filter_type"] == '"ValueList"':
212-
lines.append(' {}.filter.type = "ValueList"\n'.format(param))
220+
lines.append(
221+
' {}.filter.type = "ValueList"\n'.format(param))
213222

214223
if (
215224
data_type["data_filter"]
@@ -231,7 +240,8 @@ def define_tool_params(params):
231240
items["default_value"] = True
232241

233242
lines.append(
234-
" {}.value = '{}'\n\n".format(param, items["default_value"])
243+
" {}.value = '{}'\n\n".format(
244+
param, items["default_value"])
235245
)
236246
else:
237247
lines.append("\n")
@@ -281,7 +291,8 @@ def define_execute(params):
281291
param = "i"
282292

283293
# deal with multi-value inputs
284-
lines.append(" {} = parameters[{}].valueAsText\n".format(param, index))
294+
lines.append(
295+
" {} = parameters[{}].valueAsText\n".format(param, index))
285296
if data_type["multi_value"]:
286297
lines.append(" if {} is not None:\n".format(param))
287298
lines.append(' items = {}.split(";")\n'.format(param))
@@ -290,22 +301,27 @@ def define_execute(params):
290301
lines.append(
291302
" items_path.append(arcpy.Describe(item).catalogPath)\n"
292303
)
293-
lines.append(' {} = ";".join(items_path)\n'.format(param))
304+
lines.append(
305+
' {} = ";".join(items_path)\n'.format(param))
294306

295307
if param_type in inputRasVec:
296308
# lines.append(' desc = arcpy.Describe({})\n'.format(param))
297309
# lines.append(' {} = desc.catalogPath\n'.format(param))
298310
# if param_type == "Optional":
299311
lines.append(" if {} is not None:\n".format(param))
300-
lines.append(" desc = arcpy.Describe({})\n".format(param))
312+
lines.append(
313+
" desc = arcpy.Describe({})\n".format(param))
301314
lines.append(" {} = desc.catalogPath\n".format(param))
302315
elif param_type == {"ExistingFileOrFloat": "Raster"}:
303316
lines.append(" if {} is not None:\n".format(param))
304317
lines.append(" try:\n")
305-
lines.append(" {} = str(float({}))\n".format(param, param))
318+
lines.append(
319+
" {} = str(float({}))\n".format(param, param))
306320
lines.append(" except:\n")
307-
lines.append(" desc = arcpy.Describe({})\n".format(param))
308-
lines.append(" {} = desc.catalogPath\n".format(param))
321+
lines.append(
322+
" desc = arcpy.Describe({})\n".format(param))
323+
lines.append(
324+
" {} = desc.catalogPath\n".format(param))
309325

310326
# lines.append(' if ({} is not None) and {}.isnumeric() == False:\n'.format(param, param))
311327

@@ -438,7 +454,7 @@ def get_github_tag(tool_name, category):
438454

439455
def get_book_url(tool_name, category):
440456
"""
441-
Get link to WhiteboxTools User Mannual
457+
Get link to WhiteboxTools User Manual
442458
"""
443459
prefix = "https://www.whiteboxgeo.com/manual/wbt_book/available_tools"
444460
url = "{}/{}.html#{}".format(prefix, category, tool_name)
@@ -451,7 +467,8 @@ def get_book_tag(tool_name, category):
451467
"""
452468
prefix = "https://www.whiteboxgeo.com/manual/wbt_book/available_tools"
453469
url = "{}/{}.html#{}".format(prefix, category, tool_name)
454-
html_tag = "<a href='{}' target='_blank'>WhiteboxTools User Manual</a>".format(url)
470+
html_tag = "<a href='{}' target='_blank'>WhiteboxTools User Manual</a>".format(
471+
url)
455472
return html_tag
456473

457474

@@ -531,8 +548,31 @@ def get_book_tag(tool_name, category):
531548
with open(wbt_py) as f:
532549
lines = f.readlines()
533550
for line in lines:
551+
if line.strip() == "import urllib.request":
552+
line = ""
553+
if line.strip() == "from subprocess import CalledProcessError, Popen, PIPE, STDOUT":
554+
line = """
555+
from subprocess import CalledProcessError, Popen, PIPE, STDOUT
556+
if sys.version_info.major == 2:
557+
import urllib2 as urlopen
558+
else:
559+
import urllib.request as urlopen
560+
"""
534561
if 'f"={toolname}"' in line:
535562
line = ' args.append("={}".format(toolname))'
563+
if 'f"Warning: Unrecognized extension ext_name {ext_name}' in line:
564+
line = ' print("Warning: Unrecognized extension ext_name {}. Installing the GTE instead...".format(ext_name))\n'
565+
if line.strip() == "for entry in os.scandir(f'./{unzipped_dir_name}'):":
566+
line = " for entry in os.scandir('./{}'.format(unzipped_dir_name)):\n"
567+
if line.strip() == "new_path = entry.path.replace(f'{unzipped_dir_name}', 'plugins')":
568+
line = " new_path = entry.path.replace('{}'.format(unzipped_dir_name), 'plugins')\n"
569+
if line.strip() == "if os.path.exists(f'./{unzipped_dir_name}'):":
570+
line = " if os.path.exists('./{}'.format(unzipped_dir_name)):\n"
571+
if line.strip() == "shutil.rmtree(f'./{unzipped_dir_name}')":
572+
line = " shutil.rmtree('./{}'.format(unzipped_dir_name))\n"
573+
if "urllib.request" in line:
574+
line = line.replace("urllib.request", "urlopen")
575+
536576
outlines.append(line)
537577

538578
with open(wbt_py, "w") as f:

WBT/PRE/file_header.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
tool_labels = []
1212

1313
tool_labels.append("Absolute Value")
14+
tool_labels.append("Accumulation Curvature")
1415
tool_labels.append("Adaptive Filter")
1516
tool_labels.append("Add")
1617
tool_labels.append("Add Point Coordinates To Table")
@@ -84,18 +85,21 @@
8485
tool_labels.append("Cross Tabulation")
8586
tool_labels.append("Csv Points To Vector")
8687
tool_labels.append("Cumulative Distribution")
88+
tool_labels.append("Curvedness")
8789
tool_labels.append("D Inf Flow Accumulation")
8890
tool_labels.append("D Inf Mass Flux")
8991
tool_labels.append("D Inf Pointer")
9092
tool_labels.append("D8 Flow Accumulation")
9193
tool_labels.append("D8 Mass Flux")
9294
tool_labels.append("D8 Pointer")
95+
tool_labels.append("Dbscan")
9396
tool_labels.append("Decrement")
9497
tool_labels.append("Depth In Sink")
9598
tool_labels.append("Dev From Mean Elev")
9699
tool_labels.append("Diff From Mean Elev")
97100
tool_labels.append("Diff Of Gaussian Filter")
98101
tool_labels.append("Difference")
102+
tool_labels.append("Difference Curvature")
99103
tool_labels.append("Direct Decorrelation Stretch")
100104
tool_labels.append("Directional Relief")
101105
tool_labels.append("Dissolve")
@@ -167,7 +171,13 @@
167171
tool_labels.append("Flow Length Diff")
168172
tool_labels.append("Gamma Correction")
169173
tool_labels.append("Gaussian Contrast Stretch")
174+
tool_labels.append("Gaussian Curvature")
170175
tool_labels.append("Gaussian Filter")
176+
tool_labels.append("Gaussian Scale Space")
177+
tool_labels.append("Generalize Classified Raster")
178+
tool_labels.append("Generalize With Similarity")
179+
tool_labels.append("Generating Function")
180+
tool_labels.append("Geomorphons")
171181
tool_labels.append("Greater Than")
172182
tool_labels.append("Hack Stream Order")
173183
tool_labels.append("Height Above Ground")
@@ -181,6 +191,7 @@
181191
tool_labels.append("Histogram Matching Two Images")
182192
tool_labels.append("Hole Proportion")
183193
tool_labels.append("Horizon Angle")
194+
tool_labels.append("Horizontal Excess Curvature")
184195
tool_labels.append("Horton Stream Order")
185196
tool_labels.append("Hydrologic Connectivity")
186197
tool_labels.append("Hypsometric Analysis")
@@ -212,6 +223,8 @@
212223
tool_labels.append("K Means Clustering")
213224
tool_labels.append("K Nearest Mean Filter")
214225
tool_labels.append("Kappa Index")
226+
tool_labels.append("Knn Classification")
227+
tool_labels.append("Knn Regression")
215228
tool_labels.append("Ks Test For Normality")
216229
tool_labels.append("Laplacian Filter")
217230
tool_labels.append("Laplacian Of Gaussian Filter")
@@ -251,6 +264,7 @@
251264
tool_labels.append("Lidar Rooftop Analysis")
252265
tool_labels.append("Lidar Segmentation")
253266
tool_labels.append("Lidar Segmentation Based Filter")
267+
tool_labels.append("Lidar Shift")
254268
tool_labels.append("Lidar Sibson Interpolation")
255269
tool_labels.append("Lidar Sort By Time")
256270
tool_labels.append("Lidar Thin")
@@ -266,8 +280,11 @@
266280
tool_labels.append("Lines To Polygons")
267281
tool_labels.append("List Unique Values")
268282
tool_labels.append("Ln")
283+
tool_labels.append("Local Hypsometric Analysis")
284+
tool_labels.append("Local Quadratic Regression")
269285
tool_labels.append("Log10")
270286
tool_labels.append("Log2")
287+
tool_labels.append("Logistic Regression")
271288
tool_labels.append("Long Profile")
272289
tool_labels.append("Long Profile From Points")
273290
tool_labels.append("Longest Flowpath")
@@ -285,9 +302,12 @@
285302
tool_labels.append("Max Elev Dev Signature")
286303
tool_labels.append("Max Elevation Deviation")
287304
tool_labels.append("Max Overlay")
305+
tool_labels.append("Max Upslope Elev Change")
288306
tool_labels.append("Max Upslope Flowpath Length")
307+
tool_labels.append("Maximal Curvature")
289308
tool_labels.append("Maximum Filter")
290309
tool_labels.append("Md Inf Flow Accumulation")
310+
tool_labels.append("Mean Curvature")
291311
tool_labels.append("Mean Filter")
292312
tool_labels.append("Median Filter")
293313
tool_labels.append("Medoid")
@@ -300,6 +320,7 @@
300320
tool_labels.append("Min Downslope Elev Change")
301321
tool_labels.append("Min Max Contrast Stretch")
302322
tool_labels.append("Min Overlay")
323+
tool_labels.append("Minimal Curvature")
303324
tool_labels.append("Minimum Bounding Box")
304325
tool_labels.append("Minimum Bounding Circle")
305326
tool_labels.append("Minimum Bounding Envelope")
@@ -369,6 +390,8 @@
369390
tool_labels.append("Radius Of Gyration")
370391
tool_labels.append("Raise Walls")
371392
tool_labels.append("Random Field")
393+
tool_labels.append("Random Forest Classification")
394+
tool_labels.append("Random Forest Regression")
372395
tool_labels.append("Random Sample")
373396
tool_labels.append("Range Filter")
374397
tool_labels.append("Raster Area")
@@ -403,8 +426,10 @@
403426
tool_labels.append("Rgb To Ihs")
404427
tool_labels.append("Rho8 Flow Accumulation")
405428
tool_labels.append("Rho8 Pointer")
429+
tool_labels.append("Ring Curvature")
406430
tool_labels.append("Roberts Cross Filter")
407431
tool_labels.append("Root Mean Square Error")
432+
tool_labels.append("Rotor")
408433
tool_labels.append("Round")
409434
tool_labels.append("Ruggedness Index")
410435
tool_labels.append("Scharr Filter")
@@ -415,13 +440,15 @@
415440
tool_labels.append("Shadow Image")
416441
tool_labels.append("Shape Complexity Index")
417442
tool_labels.append("Shape Complexity Index Raster")
443+
tool_labels.append("Shape Index")
418444
tool_labels.append("Shreve Stream Magnitude")
419445
tool_labels.append("Sigmoidal Contrast Stretch")
420446
tool_labels.append("Sin")
421447
tool_labels.append("Single Part To Multi Part")
422448
tool_labels.append("Sinh")
423449
tool_labels.append("Sink")
424450
tool_labels.append("Slope")
451+
tool_labels.append("Slope Vs Aspect Plot")
425452
tool_labels.append("Slope Vs Elevation Plot")
426453
tool_labels.append("Smooth Vectors")
427454
tool_labels.append("Smooth Vegetation Residual")
@@ -449,6 +476,8 @@
449476
tool_labels.append("Subtract")
450477
tool_labels.append("Sum Overlay")
451478
tool_labels.append("Surface Area Ratio")
479+
tool_labels.append("Svm Classification")
480+
tool_labels.append("Svm Regression")
452481
tool_labels.append("Symmetrical Difference")
453482
tool_labels.append("Tan")
454483
tool_labels.append("Tangential Curvature")
@@ -473,6 +502,7 @@
473502
tool_labels.append("Union")
474503
tool_labels.append("Unnest Basins")
475504
tool_labels.append("Unsharp Masking")
505+
tool_labels.append("Unsphericity")
476506
tool_labels.append("Update Nodata Cells")
477507
tool_labels.append("Upslope Depression Storage")
478508
tool_labels.append("User Defined Weights Filter")
@@ -481,6 +511,7 @@
481511
tool_labels.append("Vector Points To Raster")
482512
tool_labels.append("Vector Polygons To Raster")
483513
tool_labels.append("Vector Stream Network Analysis")
514+
tool_labels.append("Vertical Excess Curvature")
484515
tool_labels.append("Viewshed")
485516
tool_labels.append("Visibility Index")
486517
tool_labels.append("Voronoi Diagram")
-25 KB
Binary file not shown.

WBT/plugins/conditional_evaluation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"tool_name": "ConditionalEvaluation",
33
"exe": "conditional_evaluation",
4-
"short_description": "This tool performs a conditional evaluaton (if-then-else) operation on a raster.",
4+
"short_description": "This tool performs a conditional evaluation (if-then-else) operation on a raster.",
55
"toolbox": "Math and Stats Tools",
66
"license": "MIT",
77
"example": ".*EXE_NAME -r=ConditionalEvaluation -i=DEM.tif --statement='value > 2500.0' --true=2500.0 --false=DEM.tif --output=onlyLowPlaces.tif",

WBT/plugins/edge_contamination.exe

-21.5 KB
Binary file not shown.
-19.5 KB
Binary file not shown.

WBT/plugins/exposure_towards_wind_flux.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"short_description": "This tool evaluates hydrologic connectivity within a DEM",
55
"toolbox": "Geomorphometric Analysis",
66
"license": "MIT",
7-
"example": ".*EXE_NAME -r=ExposureTowardsWindFlux -i=input.tif -s=streams.tif -o=new.tif",
7+
"example": ".*EXE_NAME -r=ExposureTowardsWindFlux -dem=input.tif -o=exposure.tif --azimuth=35.0 --max_dist=500.0",
88
"parameters": [
99
{
1010
"name": "Input DEM Raster",
3.5 MB
Binary file not shown.

0 commit comments

Comments
 (0)