-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStreamStats_DataPrep.py
1583 lines (1269 loc) · 50.3 KB
/
StreamStats_DataPrep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
An ESRI toolbox to prepare data for use in the USGS StreamStats application.
Tools in this toolbox are describes as classes and rely on the underlying databaseSetup, elevationTools, make_hydrodem, and topo_grid libraries. The functions in the aformentioned libraries can also be used outside of these tools in a Python session with access to ESRI ArcPy. All tools are Python 2/3 compatable with the exception of posthydrodem, which must be run using Python 2 / ESRI ArcMap at this time.
"""
import arcpy
import sys
import os
version = "4.0.3"
arcpy.AddMessage('StreamStats Data Preparation Tools version: %s'%(version))
class Toolbox(object):
"""
ESRI ArcToolbox for preparing data for USGS StreamStats.
"""
def __init__(self):
self.label = "StreamStats Data Preparation Tools"
self.alias = "StreamStatsDataPrep"
# List of tool classes associated with this toolbox
self.tools = [
databaseSetup, checkWalls,
makeELEVDATAIndex, ExtractPoly, CheckNoData, CheckNoData, FillNoData, ProjScale,
TopoGrid,
CoastalDEM, SetupBathyGrad, HydroDEM, AdjustAccum, AdjustAccumSimp, posthydrodem
]
class databaseSetup(object):
"""Set up the workspaces needed to process elevation and hydrography data.
This tool is a wrapper on :func:`databaseSetup.databaseSetup`.
"""
def __init__(self):
self.label = 'A. Database Setup'
self.description = 'This script sets up an archydro data model workspace for the StreamStats process. The script takes watershed boundaries and hydrography to create a new folder in a new workspace for each hydrologic unit. The tool creates a master filegdb that sits in the root workspace and holds the hydrologic unit polygons (hucpolys). The tool also dissolves by 12 digit and 8 digit polygons and line feature classes, creates the inner walls feature class, creates two buffered HUC feature classes.'
self.category = '1 - Setup Tools '
self.canRunInBackground = False
def getParameterInfo(self):
"""Database Setup inputs.
Parameters
----------
Output Workspace : DEWorkspace (File System)
Folder-type workspace for local folders and geodatabase to be created.
Main ArcHydro Geodatabase Name : GPString
Name of the geodatabase to be created in "Output Workspace."
Hydrologic Unit Boundary Dataset : DEShapefile or DEFeatureClass
Polygon vector defining local processing units. Should have columns for outwalls and inwalls, see below.
Outwall Field : Field
Field in "Hydrologic Unit Boundary Dataset" used to determine local folders and outwalls.
Inwall Field : Field
Field in "Hydrologic Unit Boundary Dataset" used to determine inwalls.
Hydrologic Unit Buffer Distance (m) : GPString
Distance to buffer local folder polygons.
Input Hydrography Workspace : DEWorkspace
Path to folder type workspace with National Hydrography Dataset geodatabases.
Elevation Dataset Template : DERasterBand
Raster dataset to pull projection information from, works best as an ESRI grid.
Alternative Outwall Buffer : GPString (optional)
Distance for alternative outwall buffer.
Returns
-------
parameters : list
List of input parameters passed to the execute method.
"""
param0 = arcpy.Parameter(
displayName = "Output Workspace",
name = "output_workspace",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
param0.filter.list = ["File System"]
param1 = arcpy.Parameter(
displayName = "Main ArcHydro Geodatabase Name",
name = "output_gdb_name",
datatype = "GPString",
parameterType = "Required",
direction = "Output")
param2 = arcpy.Parameter(
displayName = "Hydrologic Unit Boundary Dataset",
name = "hu_dataset",
datatype = ["DEShapefile","DEFeatureClass"],
parameterType = "Required",
direction = "Input")
param3 = arcpy.Parameter(
displayName = "Outwall Field",
name = "hu8_field",
datatype = "Field",
parameterType = "Required",
direction = "Input")
param3.value = 'HUC8'
param4 = arcpy.Parameter(
displayName = "Inwall Field",
name = "hu12_field",
datatype = "Field",
parameterType = "Required",
direction = "Input")
param4.value = 'HUC12'
param5 = arcpy.Parameter(
displayName = "Hydrologic Unit Buffer Distance (m)",
name = "hucbuffer",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
param5.value = '2000'
param6 = arcpy.Parameter(
displayName = "Input Hydrography Workspace",
name = "nhd_path",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
param6.filter.list = ["File System"]
param7 = arcpy.Parameter(
displayName = "Elevation Dataset Template",
name = "elevation_projection_template",
datatype = "DERasterBand",
parameterType = "Required",
direction = "Input")
param8 = arcpy.Parameter(
displayName = "Alternative Outwall Buffer",
name = "alt_buff",
datatype = "GPString",
parameterType = "Optional",
direction = "Input")
param8.value = "50"
parameters = [param0,param1,param2,param3,param4,param5,param6,param7, param8]
return parameters
def execute(self, parameters, messages):
from databaseSetup import databaseSetup
# Local variables
output_workspace = parameters[0].valueAsText
output_gdb_name = parameters[1].valueAsText
hu_dataset = parameters[2].valueAsText
hu8_field = parameters[3].valueAsText
hu12_field = parameters[4].valueAsText
hucbuffer = parameters[5].valueAsText
nhd_path = parameters[6].valueAsText
elevation_projection_template = parameters[7].valueAsText
alt_buff = parameters[8].valueAsText
databaseSetup(output_workspace, output_gdb_name, hu_dataset, hu8_field, hu12_field, hucbuffer, nhd_path,elevation_projection_template,alt_buff, version=version)
class checkWalls(object):
"""Check for intersections between the flowline dendrite and watershed outer walls and/or watershed inner walls.
This is a wrapper on :func:`databaseSetup.check_walls`.
"""
def __init__(self):
self.label = 'B. Check Walls'
self.description = 'Check inwall and outwall features for intersections with '
self.category = '1 - Setup Tools '
self.canRunInBackground = False
def getParameterInfo(self):
'''CheckWalls inputs.
Parameters
----------
dendrite : DEFeatureClass
Flowline dendrite.
inwall : DEFeatureClass
Inwall features.
points : DEFeatureClass
File path to output intersection points.
outwall : DEFeatureClass (optional)
Outwall features. Defaults to None.
Returns
-------
parameters : list
List of parameters passed to the execute function.
'''
parameters = []
param0 = arcpy.Parameter(
displayName = "Dendrite",
name = "dendrite",
datatype = "DEFeatureClass",
parameterType = "Required",
direction = "Input")
parameters.append(param0)
param1 = arcpy.Parameter(
displayName = "inwall",
name = "inwall",
datatype = "DEFeatureClass",
parameterType = "Required",
direction = "Input")
parameters.append(param1)
param2 = arcpy.Parameter(
displayName = "Points",
name = "points",
datatype = "DEFeatureClass",
parameterType = "Required",
direction = "Output")
parameters.append(param2)
param3 = arcpy.Parameter(
displayName = "Outwall",
name = "outwall",
datatype = "DEFeatureClass",
parameterType = "Optional",
direction = "Input")
parameters.append(param3)
return parameters
def execute(self, parameters, messages):
from databaseSetup import check_walls
dendrite = parameters[0].valueAsText
inwall = parameters[1].valueAsText
points = parameters[2].valueAsText
outwall = parameters[3].valueAsText
check_walls(dendrite, inwall, points, outwall = outwall)
return None
class makeELEVDATAIndex(object):
"""Create a seamless raster mosaic dataset from input digital elevation tiles.
This tool is a wrapper on :func:`elevationTools.elevIndex`.
"""
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "A. Make ELEVDATA Index"
self.description = "Function to make ELEVDATA into a mosaic raster dataset for clipping to the basin polygons."
self.category = "2 - Elevation Tools"
self.canRunInBackground = False
def getParameterInfo(self):
"""Make ELEV data index inputs
Parameters
----------
Output Geodatabase : DEWorkspace (Geodatabase)
Path to the geodatabase that will hold the output raster mosaic dataset.
Output Raster Mosaic Dataset Name : GPString
Name of raster mosaic dataset (RMD) to output, defaults to IndexRMD.
Coordinate System : GPCoordinateSystem
Coordinate system of input grids and raster mosaic dataset.
Input Elevation Data workspace : DEWorkspace (Folder)
Path to folder holding input digital elevation models to be included in the raster mosaic dataset.
Returns
-------
parameters : list
List of input parameters passed to the execute method.
"""
param0 = arcpy.Parameter(
displayName = "Output Geodatabase",
name = "OutLoc",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
param0.filter.list = ["Local Database"]
param1 = arcpy.Parameter(
displayName = "Output Raster Mosaic Dataset Name",
name = "rcName",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
param1.value = "IndexRMD"
param2 = arcpy.Parameter(
displayName = "Coordinate System",
name = "coordsysRaster",
datatype = "GPCoordinateSystem",
parameterType = "Required",
direction = "Input")
param3 = arcpy.Parameter(
displayName = "Input Elevation Data workspace",
name = "inputELEVws",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
param3.filter.list = ["File System"]
params = [param0,param1,param2,param3]
return params
def execute(self, parameters, messages):
from elevationTools import elevIndex
OutLoc = parameters[0].valueAsText # output geodatabase
rcName = parameters[1].valueAsText # raster catalogue name
coordsysRaster = parameters[2].valueAsText # raster coordinate system
InputELEVDATAws = parameters[3].valueAsText # geodatabase of elevation data
elevIndex(OutLoc, rcName, coordsysRaster, InputELEVDATAws, version=version)
return
class ExtractPoly(object):
"""Extract a hydrologic unit from a digital elevation model based on a clipping polygon.
This tool is a wrapper on :func:`elevationTools.extractPoly`.
"""
def __init__(self):
self.label = "B. Extract Polygons"
self.description = "Extract polygon area from ELEVDATA."
self.category = "2 - Elevation Tools"
self.canRunInBackground = False
def getParameterInfo(self):
"""Extract Polygon inputs.
Parameters
----------
Output Workspace : DEWorkspace (Folder)
Path to folder to work in.
ELEVDATA Raster Mosaic Dataset : DEMosaicDataset
Path to the raster mosaic dataset holding the elevation data.
Clip Polygon : GPFeatureLayer
Feature class of the watershed boundary being used for clipping.
Output Grid : GPString
Name of the output ESRI grid, defaults to dem_dd.
Returns
-------
parameters : list
List of input parameters passed to the execute method.
"""
param0 = arcpy.Parameter(
displayName = "Output Workspace",
name = "Input_Workspace",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
param0.filter.list = ["File System"]
param1 = arcpy.Parameter(
displayName = "ELEVDATA Raster Mosaic Dataset",
name = "nedindx",
datatype = "DEMosaicDataset",
parameterType = "Required",
direction = "Input")
param2 = arcpy.Parameter(
displayName = "Clip Polygon",
name = "clpfeat",
datatype = "GPFeatureLayer",
parameterType = "Required",
direction = "Input")
param3 = arcpy.Parameter(
displayName = "Output Grid",
name = "OutGrd",
datatype = "GPString",
parameterType = "Required",
direction = "Output")
param3.value = "dem_dd"
params = [param0,param1,param2,param3]
return params
def execute(self, parameters, messages):
from elevationTools import extractPoly
Input_Workspace = parameters[0].valueAsText #workspace
nedindx = parameters[1].valueAsText # NED Index (polygon) Layer
clpfeat = parameters[2].valueAsText # clip polygon feature layer, I think this should be a collection of features so all the clipping happens in a loop....
OutGrd = parameters[3].valueAsText # name of output grid
extractPoly(Input_Workspace, nedindx, clpfeat, OutGrd, version=version)
class CheckNoData(object):
"""Check for no data cells in a digital elevation model.
This tool is a wrapper on :func:`elevationTools.checkNoData`.
"""
def __init__(self):
self.label = "C. Check No Data"
self.description = "Finds NODATA values in a grid and makes a polygon feature class with value 1 if it is NODATA, and 0 if it contains data values."
self.category = "2 - Elevation Tools"
self.canRunInBackground = False
def getParameterInfo(self):
"""Check for no data inputs.
Parameters
----------
InputGrid : DERasterBand
Path to raster dataset to examine.
Workspace : DEWorkspace (Geodatabase)
Geodatabase-type workspace.
Output Feature Layer : GPString
Name of output feature class, defaults to DEM_NoDataSinks.
Returns
-------
parameters : list
List of input parameters passed to the execute method.
"""
param0 = arcpy.Parameter(
displayName = "InputGrid",
name = "InGrid",
datatype = "DERasterBand",
parameterType = "Required",
direction = "Input")
param1 = arcpy.Parameter(
displayName = "Workspace",
name = "tmpLoc",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
param1.filter.list = ["Local Database"]
param2 = arcpy.Parameter(
displayName = "Output Feature Layer",
name = "OutPolys",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
param2.value = "DEM_NoDataSinks"
params = [param0,param1,param2]
return params
def execute(self, parameters, messages):
from elevationTools import checkNoData
InGrid = parameters[0].valueAsText
tmpLoc = parameters[1].valueAsText
OutPolys_shp = parameters[2].valueAsText
checkNoData(InGrid, tmpLoc, OutPolys_shp, version=version)
return None
class FillNoData(object):
"""Fill no data cells in a digital elevation model.
This tool is a wrapper on :func:`elevationTools.fillNoData`.
Notes
-----
This tool can be run iteratively to fully fill no data areas that are larger than one cell.
"""
def __init__(self):
self.label = "D. Fill NoData Cells"
self.description = "Replaces NODATA values in a grid with mean values within 3x3 window. May be run repeatedly to fill in areas wider than 2 cells. Note the output is floating point, even if the input is integer. Note this will expand the data area of the grid around the outer edges of data, in addition to filling in NODATA gaps in the interior of the grid."
self.category = "2 - Elevation Tools"
self.canRunInBackground = False
def getParameterInfo(self):
"""Fill no data inputs.
Parameters
----------
Workspace : DEWorkspace (Folder)
Path to workspace folder.
Input Grid : DERasterBand
Path to raster dataset with no data values to be filled, defaults to DEM_NoDataSinks.
Output Grid : GPString
Path to write out filled raster dataset to, defaults to DEM_filled.
Returns
-------
parameters : list
List of input parameters passed to the execute method.
"""
param0 = arcpy.Parameter(
displayName = "Workspace",
name = "workspace",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
param0.filter.list = ["File System"]
param1 = arcpy.Parameter(
displayName = "Input Grid",
name = "InGrid",
datatype = "DERasterBand",
parameterType = "Required",
direction = "Input")
param1.value = "DEM_NoDataSinks"
param2 = arcpy.Parameter(
displayName = "Output Grid",
name = "OutGrid",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
param2.value = "DEM_filled"
params = [param0, param1, param2]
return params
def execute(self, parameters, messages):
from elevationTools import fillNoData
# load parameters
workspace = parameters[0].valueAsText
InGrid = parameters[1].valueAsText
OutGrid = parameters[2].valueAsText
fillNoData(workspace, InGrid, OutGrid, version = version)
return
class ProjScale(object):
"""Project and scale a digital elevation model. The default settings assume the digital elevation model uses meters (m) as the z-units.
This tool is a wrapper on :func:`elevationTools.projScale`.
Notes
-----
After scaling, this tool attempts to set the correct z-units; however, if your vertical units are different from your horizontal units it is advised to check the z-units manually.
"""
def __init__(self):
self.label = "E. Project and Scale Elevation Data"
self.description = "Project a NED grid to a user-specified coordinate system. Handles setting a cell registration point. Also multiplies by 100 and converts to integer grid format."
self.category = "2 - Elevation Tools"
self.canRunInBackground = False
def getParameterInfo(self):
"""Project and scale digital elevation model inputs.
Parameters
----------
InWorkSpace : DEWorkspace (Folder)
Path to the workspace folder.
InGrid : DERasterBand
Path to the raster dataset to project and scale.
OutGrid : GPString
Name for the projected and scaled raster, defaults to dem_raw.
OutCoordSys : GPCoordinateSystem
Coordinate system with which to project or preproject the input raster.
OutCellSize : analysis_cell_size
Output cell size to project the input raster to, defaults to 10 horizontal map units.
RegPt : GPString
Registration point for the projected raster, defaults to "0 0".
scaleFact : GPString
Scale factor to use to convert the projected raster to integers, defaults to 100, converting m to cm. Consider using a larger scale factor as cell-size decreases.
Returns
-------
parameters : list
List of input parameters passed to the execute method.
"""
param0 = arcpy.Parameter(
displayName = "Input Workspace",
name = "InWorkSpace",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
param0.filter.list = ['File System']
param1 = arcpy.Parameter(
displayName = "Input Grid",
name = "InGrid",
datatype = "DERasterBand",
parameterType = "Required",
direction = "Input")
param2 = arcpy.Parameter(
displayName = "Output Grid",
name = "OutGrid",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
param2.value = "dem_raw"
param3 = arcpy.Parameter(
displayName = "Output Coordinate System",
name = "OutCoordSys",
datatype = "GPCoordinateSystem",
parameterType = "Required",
direction = "Input")
param4 = arcpy.Parameter(
displayName = "Output Cell Size",
name = "OutCellSize",
datatype = "analysis_cell_size",
parameterType = "Required",
direction = "Input")
param4.value = 10
param5 = arcpy.Parameter(
displayName = "registration Point",
name = "RegPt",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
param5.value = "0 0"
param6 = arcpy.Parameter(
displayName = "Scale Factor",
name = "scaleFact",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
param6.value = "100"
params = [param0,param1,param2,param3,param4,param5,param6]
return params
def execute(self, parameters, messages):
from elevationTools import projScale
# get parameters from tools
Input_Workspace = parameters[0].valueAsText # Input workspace. (type Workspace)
InGrd = parameters[1].valueAsText # Input grid name. (type String)
OutGrd = parameters[2].valueAsText # Output grid name. (type String)
OutCoordsys = parameters[3].valueAsText # Coordinate system for output grid. (type Coordinate System)
OutCellSize = parameters[4].valueAsText # Cell size for output grid. (type Analysis cell size)
RegistrationPoint = parameters[5].valueAsText # Registration point. Space separated coordinates. (type String)
scaleFact = int(parameters[6].valueAsText)
projScale(Input_Workspace, InGrd, OutGrd, OutCoordsys, OutCellSize, RegistrationPoint, scaleFact = scaleFact, version = version)
return None
class TopoGrid(object):
"""Condition an input DEM using a flowline dendrite prior to hydro-enforcement.
This tool is a wrapper on :func:`topo_grid.topogrid`.
Notes
-----
This function turns the input DEM into a 3D point cloud, thinned using the VIP algorithm so that not all points are retained from the original DEM. The point cloud is used in conjunction with the supplied flowlines to re-interpolate a DEM that is aware of the location of the flowlines and their flow direction.
This is a computationally intensive function. Running it via ESRI ArcPro or Python 3 will be faster than using ESRI ArcMap or Python 2.
"""
def __init__(self):
self.label = "TopoGrid"
self.description = "This script runs topo to raster as a prelimary burning and walling process before HydroDEM is run. It takes a buffered DEM dataset and runs raster to multipoint with VIP filtering based on the percentage set in the tool. The output of the script is a new DEM to be used by HydroDEM."
self.category = "3 - TopoGrid (optional)"
self.canRunInBackground = False
def getParameterInfo(self):
"""TopoGrid inputs.
Parameters
----------
Output Workspace : DEWorkspace (Geodatabase)
Path to a geodatabase workspace.
Dissolved HUC8 boundary : DEFeatureClass or DEShapefile
Feature class to use in bounding the topogrid conditioning process.
Topogrid Buffer Distance : GPDouble
Distance to buffer the input HUC8 boundary, in the units of the HUC8 boundary.
12 Digit Hydrologic Unit Datasets if dissolved HUC8 boundary failed : DEFeatureClass or DEShapefile (Optional)
List of HUC12 boundaries to split up TopoGrid computations if the whole domain fails.
Dendritic Flowline Features : DEFeatureClass or DEShapefile
Dendrite used for enforcing flow direction in topogrid.
Buffered and Projected Elevation Data : DERasterBand or DERasterDataset
Input digital elevation model to be conditioned using topogrid.
Output Cell Size : GPString
Cell size for output digital elevation model, defaults to 10 horizontal map units.
VIP Percentage : GPString
Thinning value used in the Very Important Points (VIP) algorithm to decide how many points from the original raster are retained, defaults to 5 percent.
SnapGrid : DERasterBand (Optional)
Raster to snap output grid to.
Returns
-------
parameters : list
List of input parameters passed to the execute method.
"""
param0 = arcpy.Parameter(
displayName = "Output Workspace",
name = "Workspace",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input"
)
param0.filter.list = ["Local Database"]
param1 = arcpy.Parameter(
displayName = "Dissolved HUC8 boundary",
name = "huc8",
datatype = ["DEFeatureClass","DEShapefile"],
parameterType = "Required",
direction = "Input"
)
param2 = arcpy.Parameter(
displayName = "Topogrid Buffer Distance",
name = "buffdist",
datatype = "GPDouble",
parameterType = "Required",
direction = "Input"
)
param2.value = "50" # default value in horizontal map units.
param3 = arcpy.Parameter(
displayName = "12 Digit Hydrologic Unit Datasets if dissolved HUC8 boundary failed.",
name = "huc12",
datatype = ["DEFeatureClass","DEShapefile"],
parameterType = "Optional",
direction = "Input",
multiValue = True
)
param4 = arcpy.Parameter(
displayName = "Dendritic Flowline Features",
name = "dendrite",
datatype = ["DEFeatureClass","DEShapefile"],
parameterType = "Required",
direction = "Input"
)
param5 = arcpy.Parameter(
displayName = "Buffered and Projected Elevation Data",
name = "dem",
datatype = ["DERasterBand","DERasterDataset"],
parameterType = "Required",
direction = "Input"
)
param6 = arcpy.Parameter(
displayName = "Output Cell Size",
name = "cellSize",
datatype = "GPString",
parameterType = "Required",
direction = "Input"
)
param6.value = '10'
param7 = arcpy.Parameter(
displayName = "VIP Percentage",
name = "vipPer",
datatype = "GPString",
parameterType = "Required",
direction = "Input"
)
param7.value = "5" # default in arcPro
param8 = arcpy.Parameter(
displayName = "SnapGrid",
name = "snapgrid",
datatype = "DERasterBand",
parameterType = "Optional",
direction = "Input"
)
params = [param0,param1,param2,param3,param4,param5,param6,param7,param8]
return params
def execute(self,parameters, messages):
from topo_grid import topogrid
workspace = parameters[0].valueAsText
huc8 = parameters[1].valueAsText
buffDist = parameters[2].valueAsText
huc12 = parameters[3].valueAsText
dendrite = parameters[4].valueAsText
dem = parameters[5].valueAsText
cellSize = parameters[6].valueAsText
vipPer = parameters[7].valueAsText
snapgrid = parameters[8].valueAsText
topogrid(workspace,huc8,buffDist,dendrite,dem,cellSize,vipPer,snapgrid = snapgrid, huc12=huc12)
return None
class SetupBathyGrad(object):
"""Prepare bathymetric gradient inputs for use in hydro-enforcement.
This tool is a wrapper on :func:`make_hydrodem.bathymetricGradient`.
Notes
-----
The bathymetric gradient refers to generating a sloping area around the flowline dendrite that ensures the landscape around the dendrite flows to the stream. This also adds a sloping surface to double-line streams and waterbodies to help ensure proper drainage after hydro-enforcement.
"""
def __init__(self):
self.label = "B. Bathymetric Gradient Setup"
self.description = "This script creates a set of NHD Hydrography Datasets, extracts the appropriate features and converts them to rasters for input into HydroDEM."
self.category = "4 - HydroDEM"
self.canRunInBackground = False
def getParameterInfo(self):
"""Setup Bathymetric Gradient inputs.
Parameters
----------
Output Workspace : DEWorkspace (Geodatabase)
Path to a geodatabase workspace.
Digital Elevation Model (used for snapping) : DERasterBand
Path to a digital elevation model to use for aligning output grids to the rest of the project.
Dissolved Eight-Digit Hydrologic Unit Code (HUC8) Dataset : DEFeatureClass
Feature class of the local folder boundary.
NHD Area : DEFeatureClass
Feature class of NHD double line streams.
NHD Dendrite : DEFeatureClass
Feature class of the flowline dendrite.
NHD Waterbody : DEFeatureClass
Feature class of the NHD water bodies.
Cell Size : GPString
Output grid cell size, defaults to 10 horizontal map units.
Returns
-------
parameters : list
List of input parameters passed to the execute method.
Notes
-----
This tool expects that the NHD Dendrite and NHD Area features have an attribute column with the name "FType" populated with feature type codes. In the newer NHD High-Resolution data-sets this attribute is called "FTYPE." The query used to select features is case sensitive; as such, this attribute needs to be renamed to "FType" for NHD High-Resolution data.
"""
param0 = arcpy.Parameter(
displayName = "Output Workspace",
name = "Workspace",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input") # maybe should be Output
param0.filter.list = ["Local Database"]
param1 = arcpy.Parameter(
displayName = "Digital Elevation Model (used for snapping)",
name = "SnapGrid",
datatype = "DERasterBand",
parameterType = "Required",
direction = "Input")
param2 = arcpy.Parameter(
displayName = "Dissolved Eight-Digit Hydrologic Unit Code (HUC8) Dataset",
name = "hucpoly",
datatype = "DEFeatureClass",
parameterType = "Required",
direction = "Input")
param3 = arcpy.Parameter(
displayName = "NHD Area",
name = "NHDArea",
datatype = "DEFeatureClass",
parameterType = "Required",
direction = "Input")
param4 = arcpy.Parameter(
displayName = "NHD Dendrite",
name = "NHDFlowline",
datatype = "DEFeatureClass",
parameterType = "Required",
direction = "Input")
param5 = arcpy.Parameter(
displayName = "NHD Waterbody",
name = "NHDWaterbody",
datatype = "DEFeatureClass",
parameterType = "Required",
direction = "Input")
param6 = arcpy.Parameter(
displayName = "Cell Size",
name = "cellSize",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
param6.value = "10"
params = [param0,param1,param2,param3,param4,param5,param6]
return params
def execute(self, parameters, messages):
from make_hydrodem import bathymetricGradient, SnapExtent
Workspace = parameters[0].valueAsText
SnapGrid = parameters[1].valueAsText
hucpoly = parameters[2].valueAsText
NHDArea = parameters[3].valueAsText
NHDFlowline = parameters[4].valueAsText
NHDWaterbody = parameters[5].valueAsText
cellSize = parameters[6].valueAsText
bathymetricGradient(Workspace,SnapGrid, hucpoly, NHDArea, NHDFlowline, NHDWaterbody, cellSize, version = version)
return None
class CoastalDEM(object):
"""Prepare coastal areas for hydro-enforcement.
This tool is a wrapper on :func:`make_hydrodem.coastaldem`.
"""
def __init__(self):
self.label = "A. Coastal DEM Processing (Optional)"
self.description = "Lowers the level of the sea to ensure it is always below land level. Also raises any land cells to 1 cm unless they are within a polygon with Land attribute of 0. The input polygons (LandSea) needs to identify the sea with a Land attribute of -1. Land is identified with a Land value of 1. No change polygons should have Land value of 0."
self.canRunInBackground = False
self.category = "4 - HydroDEM"
def getParameterInfo(self):
"""Coastal digital elevation model processing inputs.
Parameters
----------
Workspace : DEWorkspace (Folder)
Path to a folder-type workspace.
Input raw DEM : DERasterBand
Original digital elevation model to be corrected for coastal areas, defaults to dem_raw.
Input LandSea polygon feature class : DEFeatureClass
Feature class indicating areas of land and sea.
Output DEM : DERasterBand
Output digital elevation model name, defaults to dem_sea.
Sea Level : GPString
Value to insert into areas identified as the sea, defaults to -60000 vertical map units.
Returns
-------
parameters : list
List of input parameters passed to the execute method.
"""
param0 = arcpy.Parameter(
displayName = "Workspace",
name = "Input_Workspace",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input") # maybe should be Output
param1 = arcpy.Parameter(
displayName = "Input raw DEM",
name = "grdName",
datatype = "DERasterBand",
parameterType = "Required",
direction = "Input")
param1.value = "dem_raw"
param2 = arcpy.Parameter(
displayName = "Input LandSea polygon feature class",
name = "InFeatureClass",
datatype = "DEFeatureClass",
parameterType = "Required",