-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSSURGO_CheckgSSURGO.py
1489 lines (1135 loc) · 54.7 KB
/
SSURGO_CheckgSSURGO.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
# SSURGO_CheckgSSURGO.py
#
# Steve Peaslee, USDA-NRCS NCSS
#
# Run basic completeness check on seleced file geodatabases in the specified folder.
# Assumes that all databases were created by the SSURGO Download tools.
#
# Checklist:
# 1. Looks for all 6 SSURGO featureclasses but does not check contents or projection
# 2. Looks for all 69 standalone attribute tables
# 3. Looks for MapunitRaster layer, checking for attribute table with MUKEY and statistics.
# 4. Compares mapunit count in raster with MAPUNIT table. A mismatch is not considered to
# be an error, but a warning.
# Original coding 01-05-2014
#
# Updated 2014-09-27
#
# Updated 2014-11-24. Added comparison of gSSURGO and SDM record counts for most attribute tables
## ===================================================================================
class MyError(Exception):
pass
## ===================================================================================
def errorMsg():
try:
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
theMsg = tbinfo + " \n" + str(sys.exc_type)+ ": " + str(sys.exc_value) + " \n"
PrintMsg(theMsg, 2)
except:
PrintMsg("Unhandled error in errorMsg method", 2)
pass
## ===================================================================================
def PrintMsg(msg, severity=0):
# Adds tool message to the geoprocessor
#
#Split the message on \n first, so that if it's multiple lines, a GPMessage will be added for each line
try:
for string in msg.split('\n'):
#Add a geoprocessing message (in case this is run as a tool)
if severity == 0:
arcpy.AddMessage(string)
elif severity == 1:
arcpy.AddWarning(string)
elif severity == 2:
arcpy.AddMessage(" ")
arcpy.AddError(string)
except:
pass
## ===================================================================================
def GetFieldInfo(gdb):
# Not being used any more.
#
# Assumption is that this is all dictated by the XML Workspace document so schema problems
# should not occur as long as the standard tools were used to create all databases.
#
# Create standard schema description for each geodatabase and use it in comparison
# to the rest of the tables
try:
env.workspace = gdb
tblList = arcpy.ListTables()
tblList.extend(arcpy.ListFeatureClasses())
tblList.extend(arcpy.ListRasters())
dSchema = dict()
arcpy.SetProgressorLabel("Reading geodatabase schema...")
arcpy.SetProgressor("step", "Reading geodatabase schema...", 0, len(tblList), 1)
for tbl in tblList:
tblName = tbl.encode('ascii').upper()
arcpy.SetProgressorLabel("Reading schema for " + os.path.basename(gdb) + ": " + tblName )
desc = arcpy.Describe(tblName)
fields = desc.fields
stdSchema = list()
for fld in fields:
stdSchema.append((fld.baseName.encode('ascii').upper(), fld.length, fld.precision, fld.scale, fld.type.encode('ascii').upper()))
#stdSchema.append((fld.baseName.encode('ascii').upper(), fld.length, fld.precision, fld.scale, fld.type.encode('ascii').upper(), fld.aliasName.encode('ascii').upper()))
dSchema[tblName] = stdSchema
arcpy.SetProgressorPosition()
arcpy.ResetProgressor()
return dSchema
except:
errorMsg()
return dict()
## ===================================================================================
def CheckFeatureClasses(theWS):
# Simply make sure that each featureclass is present.
#
try:
PrintMsg(" \n\tChecking for existence of featureclasses", 0)
env.workspace = theWS
missingFC = list()
badFields = list()
lFC = ['MUPOLYGON', 'FEATLINE', 'FEATPOINT', 'MULINE', 'SAPOLYGON', 'MUPOINT']
# Create dictionary containing valid, ordered field names
dFields = dict()
dFields['MUPOLYGON'] = ['OBJECTID', 'SHAPE', 'AREASYMBOL', 'SPATIALVER', 'MUSYM', 'MUKEY', 'SHAPE_LENGTH', 'SHAPE_AREA']
dFields['FEATLINE'] = ['OBJECTID', 'SHAPE', 'AREASYMBOL', 'SPATIALVER', 'FEATSYM', 'FEATKEY', 'SHAPE_LENGTH']
dFields['FEATPOINT'] = ['OBJECTID', 'SHAPE', 'AREASYMBOL', 'SPATIALVER', 'FEATSYM', 'FEATKEY']
dFields['MULINE'] = ['OBJECTID', 'SHAPE', 'AREASYMBOL', 'SPATIALVER', 'MUSYM', 'MUKEY', 'SHAPE_LENGTH']
dFields['SAPOLYGON'] = ['OBJECTID', 'SHAPE', 'AREASYMBOL', 'SPATIALVER', 'LKEY', 'SHAPE_LENGTH', 'SHAPE_AREA']
dFields['MUPOINT'] = ['OBJECTID', 'SHAPE', 'AREASYMBOL', 'SPATIALVER', 'MUSYM', 'MUKEY']
for fc in lFC:
fieldNames = list()
if not arcpy.Exists(fc):
# if a featureclass is missing from the geodatabase, add it to the list
missingFC.append(fc)
else:
# Print a list of field names present in the featureclass
fields = arcpy.Describe(fc).fields
for fld in fields:
fieldNames.append(fld.name.upper())
if fieldNames != dFields[fc]:
badFields.append(fc)
PrintMsg("\t" + fc + " has a schema problem: " + "', '".join(fieldNames) + "')", 0 )
if len(missingFC) > 0:
PrintMsg("\t" + os.path.basename(theWS) + " is missing the following gSSURGO featureclasses: " + ", ".join(missingFC), 2)
return False
if len(badFields) > 0:
# One or more featureclasses have a problem with fields or field order
return False
return True
except:
errorMsg()
return False
## ===================================================================================
def CheckTables(theWS):
# Simply make sure that each table is present and that the SACATALOG table has at least one record
# The rest of the tables will be checked for record count and existence
try:
PrintMsg(" \n\t\tChecking for existence of metadata and SDV attribute tables")
env.workspace = theWS
missingTbl = list()
lTbl = ['mdstatdomdet', 'mdstatdommas', 'mdstatidxdet', 'mdstatidxmas',
'mdstatrshipdet', 'mdstatrshipmas', 'mdstattabcols', 'mdstattabs', 'sdvalgorithm', 'sdvattribute', 'sdvfolder',
'sdvfolderattribute']
for tbl in lTbl:
if not arcpy.Exists(tbl):
missingTbl.append(tbl)
if len(missingTbl) > 0:
PrintMsg("\t" + os.path.basename(theWS) + " is missing the following gSSURGO attribute tables: " + ", ".join(missingTbl), 2)
return False
return True
except:
errorMsg()
return False
## ===================================================================================
def CheckCatalog(theWS):
# Simply make sure that at least one survey is populated in the SACATALOG table
try:
env.workspace = theWS
saTbl = os.path.join(theWS, "sacatalog")
if arcpy.Exists(saTbl):
# parse Areasymbol from database name. If the geospatial naming convention isn't followed,
# then this will not work.
surveyList = list()
with arcpy.da.SearchCursor(saTbl, ("AREASYMBOL")) as srcCursor:
for rec in srcCursor:
# Get Areasymbol from SACATALOG table, assuming just one survey is present in the database
surveyList.append(rec[0])
if len(surveyList) == 0:
PrintMsg("\t" + os.path.basename(theWS) + "\\SACATALOG table contains no surveys", 2)
return False
else:
PrintMsg(os.path.basename(theWS) + " contains " + str(len(surveyList)) + " soil surveys", 0)
else:
# unable to open SACATALOG table in existing dataset
PrintMsg("\tSACATALOG table not found in " + os.path.basename(theWS), 2)
return False
except:
errorMsg()
return False
## ===================================================================================
def CheckRaster(theWS):
# Simply make sure that at least one Mapunit Raster is present and that it has
# a proper attribute table and statistics.
env.workspace = theWS
try:
lRASTER = arcpy.ListRasters("MapunitRaster*")
if len(lRASTER) == 0:
PrintMsg("\t" + os.path.basename(theWS) + " has no MapunitRaster layer", 2)
return False
else:
# Just check the first one found
inRas = lRASTER[0]
desc = arcpy.Describe(inRas)
SR = desc.spatialReference
gcs = SR.GCS
dn = gcs.datumName
PrintMsg(" \n\tChecking raster " + inRas, 0)
PrintMsg(" \n\t\tCoordinate system: " + SR.name + ", " + dn, 0)
# Make sure raster has statistics and check the MUKEY count
try:
# Get the statistic (MAX value) for the raster
maxValue = int(arcpy.GetRasterProperties_management (inRas, "MAXIMUM").getOutput(0))
PrintMsg(" \n\t\tRaster has statistics", 0)
except:
# Need to test it against a raster with no statistics
#
raise MyError, "\t" + inRas + " is missing raster statistics"
try:
# Get the raster mapunit count
# This same check is run during the PolygonToRaster conversion.
uniqueValues = int(arcpy.GetRasterProperties_management (inRas, "UNIQUEVALUECOUNT").getOutput(0))
# Get the number of MUKEY values in the MAPUNIT table
muCnt = MapunitCount(theWS, uniqueValues)
# Compare tabular and raster MUKEY count
if muCnt <> uniqueValues:
PrintMsg("\t\tDiscrepancy in mapunit count for " + inRas, 1)
PrintMsg("\t\t\t Raster mapunits: " + Number_Format(uniqueValues, 0, True), 0)
PrintMsg("\t\t\tTabular mapunits: " + Number_Format(muCnt, 0, True), 0)
else:
PrintMsg(" \n\t\tMap unit count in raster matches featureclass", 0)
except:
# Need to test it against a raster with no statistics
#
PrintMsg("\t" + inRas + " has no raster attribute table", 2)
return False
# Make sure raster has MUKEY field
lFlds = arcpy.ListFields(inRas)
if lFlds is None:
PrintMsg("\t" + inRas + " has no attributes fields", 2)
return False
if len(lFlds):
hasMukey = False
for fld in lFlds:
#PrintMsg("\t\t" + fld.name.upper(), 1)
if fld.name.upper() == "MUKEY":
hasMukey = True
# Make sure MUKEY is populated
cellCnt = 0
wc= "MUKEY = ''"
with arcpy.da.SearchCursor(inRas, ("MUKEY", "COUNT"), where_clause=wc) as srcCursor:
for rec in srcCursor:
# Get Areasymbol from SACATALOG table, assuming just one survey is present in the database
theMukey, cellCnt = rec
if cellCnt> 0:
PrintMsg("\t" + inRas + " is missing MUKEY values for " + Number_Format(cellCnt, 0, True) + " cells", 2 )
return False
break
else:
hasMukey = False
if hasMukey == False:
PrintMsg("\t" + inRas + " is missing the MUKEY field", 2)
return False
return True
except:
errorMsg()
return False
## ===================================================================================
def MapunitCount(theWS, uniqueValues):
# Return number of mapunits (mukey) in this survey using the MUPOLYGON featureclass
#
try:
env.workspace = theWS
muTbl = os.path.join(theWS, "mapunit")
muPoly = os.path.join(theWS, "MUPOLYGON")
if arcpy.Exists(muPoly):
# use cursor to generate list of values
# Originally used SET, but this causing MEMORY errors with CONUS database
PrintMsg("\tGetting mapunit list from " + muPoly + "...", 0)
valList = list()
cntr = 0
with arcpy.da.SearchCursor(muPoly, ['mukey']) as cur:
cntr += 1
for rec in cur:
valList.append(rec[0])
if cntr == 100000:
cntr = 0
valSet = set(valList)
valList = list(valSet)
del valSet
# convert long list to a sorted list of unique values
valSet = set(valList)
valList = list(valSet)
del valSet
valList.sort()
return len(valList)
else:
# unable to find MUPOLYGON featureclass
PrintMsg("\tMUPOLYGON featureclass not found in " + os.path.basename(theWS), 2)
return 0
except:
errorMsg()
return 0
## ===================================================================================
def Number_Format(num, places=0, bCommas=True):
try:
# Format a number according to locality and given places
#locale.setlocale(locale.LC_ALL, "")
if bCommas:
theNumber = locale.format("%.*f", (places, num), True)
else:
theNumber = locale.format("%.*f", (places, num), False)
return theNumber
except:
errorMsg()
return False
## ===================================================================================
def QuerySDA(sQuery, tbl):
# Pass a query (from GetSDMCount function) to Soil Data Access designed to get the count of the selected records
import time, datetime, urllib2, json
try:
# Create empty value list to contain the count
# Normally the list should only contain one item
valList = list()
#PrintMsg("\t" + sQuery + " \n", 0)
# NEW POST REST REQUEST BEGINS HERE
#
# Uses new HTTPS URL
# Post Rest returns
theURL = "https://sdmdataaccess.nrcs.usda.gov"
url = theURL + "/Tabular/SDMTabularService/post.rest"
# Create request using JSON, return data as JSON
dRequest = dict()
dRequest["format"] = "JSON"
dRequest["query"] = sQuery
jData = json.dumps(dRequest)
# Send request to SDA Tabular service using urllib2 library
req = urllib2.Request(url, jData)
resp = urllib2.urlopen(req)
jsonString = resp.read()
# Convert the returned JSON string into a Python dictionary.
data = json.loads(jsonString)
del jsonString, resp, req
# Find data section (key='Table')
valList = list()
if "Table" in data:
dataList = data["Table"] # Data as a list of lists. All values come back as string.
# Iterate through dataList and reformat the data to create the menu choicelist
for rec in dataList:
val = rec[0]
valList.append(int(val))
else:
# No data returned for this query
raise MyError, "SDA query failed to return requested information: " + sQuery
if len(valList) == 0:
raise MyError, "SDA query failed: " + sQuery
return valList[0]
except MyError, e:
# Example: raise MyError, "This is an error message"
PrintMsg(str(e), 2)
return 0
except httplib.HTTPException, e:
PrintMsg("HTTP Error: " + str(e) + " for " + tbl, 2)
return -1
except urllib2.URLError:
PrintMsg(sQuery, 1)
raise MyError, "Connection error for " + tbl
except socket.error, e:
raise MyError, "Soil Data Access problem for " + tbl + ": " + str(e)
return -1
except:
#PrintMsg(" \nSDA query failed: " + sQuery, 1)
errorMsg()
return -1
## ===================================================================================
def GetSDMCount(theInputDB):
# Run all SDA queries necessary to get the count for each SDM - soil attribute table
# Can be vulnerable to failure if the SDM database changes before the gSSURGO database is checked.
#
try:
dCount = dict() # store SDM count for each table in a dictionary
Q = "SELECT COUNT(*) AS RESULT FROM " # Base part of each query
# Get list of areasymbols
PrintMsg(" \n\tChecking attribute tables", 0)
bigList = list()
saTbl = os.path.join(theInputDB, "LEGEND")
with arcpy.da.SearchCursor(saTbl, ["AREASYMBOL"]) as cur:
for rec in cur:
bigList.append("'" + rec[0] + "'")
size = 4 # limit to number of areasymbols in each
test = 0
iterNum = len(bigList) / size
if (len(bigList) % size) or (len(bigList) < size):
iterNum += 1
PrintMsg(" \n\t\tGetting record count from SDM tables in " + str(iterNum) + " iterations...", 0)
for i in range(0, len(bigList), size):
test += 1
asList = bigList[i:i + size]
if len(asList) > 1:
theAS = ",".join(asList)
else:
theAS = asList[0]
subQuery = "SELECT MUKEY FROM MAPUNIT M, LEGEND L WHERE m.LKEY = L.LKEY AND L.AREASYMBOL IN (" + theAS + ")"
arcpy.SetProgressor("step", "Getting record count from Soil Data Access...", 1, 55, 1)
# CHORIZON
tb1 = "chorizon"
tb2 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = chorizon.cokey )"
cnt = QuerySDA(sQuery, tb1)
if cnt == -1:
# return empty dictionary, which will let the calling function know there is a serious problem
# Record checks will be halted for all tables if this occurs
return dCount
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHAASHTO
tb1 = "chaashto"
tb2 = "chorizon"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chorizon.chkey = chaashto.chkey AND component.cokey = chorizon.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHCONSISTENCE
tb1 = "chconsistence"
tb2 = "chorizon"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chorizon.chkey = chconsistence.chkey AND component.cokey = chorizon.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHDESGNSUFFIX
tb1 = "chdesgnsuffix"
tb2 = "chorizon"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chorizon.chkey = chdesgnsuffix.chkey AND component.cokey = chorizon.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHFRAGS
tb1 = "chfrags"
tb2 = "chorizon"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chorizon.chkey = chfrags.chkey AND component.cokey = chorizon.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHPORES
tb1 = "chpores"
tb2 = "chorizon"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chorizon.chkey = chpores.chkey AND component.cokey = chorizon.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHSTRUCTGRP
tb1 = "chstructgrp"
tb2 = "chorizon"
tb3 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chorizon.chkey = chstructgrp.chkey AND component.cokey = chorizon.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHTEXT
tb1 = "chtext"
tb2 = "chorizon"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chorizon.chkey = chtext.chkey AND component.cokey = chorizon.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHTEXTUREGRP
tb1 = "chtexturegrp"
tb2 = "chorizon"
tb3 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chorizon.chkey = chtexturegrp.chkey AND component.cokey = chorizon.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHUNIFIED
tb1 = "chunified"
tb2 = "chorizon"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chorizon.chkey = chunified.chkey AND component.cokey = chorizon.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHSTRUCT
tb1 = "chstruct"
tb2 = "chstructgrp"
tb3 = "component"
tb4 = "chorizon"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + ", " + tb4.upper() +" WHERE component.mukey IN (" + subQuery + ") AND ( chstructgrp.chstructgrpkey = chstruct.chstructgrpkey AND chorizon.chkey = chstructgrp.chkey AND component.cokey = chorizon.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHTEXTURE
tb1 = "chtexture"
tb2 = "chtexturegrp"
tb3 = "component"
tb4 = "chorizon"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + ", " + tb4.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chtexturegrp.chtgkey = chtexture.chtgkey AND chorizon.chkey = chtexturegrp.chkey AND component.cokey = chorizon.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CHTEXTUREMOD
tb1 = "chtexturemod"
tb2 = "chtexture"
tb3 = "chtexturegrp"
tb4 = "component"
tb5 = "chorizon"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + ", " + tb4.upper() + ", " + tb5.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( chtexture.chtkey = chtexturemod.chtkey AND chtexturegrp.chtgkey = chtexture.chtgkey AND chorizon.chkey = chtexturegrp.chkey AND component.cokey = chorizon.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COCANOPYCOVER
tb1 = "cocanopycover"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = cocanopycover.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COCROPYLD
tb1 = "cocropyld"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = cocropyld.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CODIAGFEATURES
tb1 = "codiagfeatures"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = codiagfeatures.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COECOCLASS
tb1 = "coecoclass"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = coecoclass.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
# COEROSIONACC
tb1 = "coerosionacc"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = coerosionacc.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COEPLANTS
tb1 = "coeplants"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = coeplants.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COFORPROD
tb1 = "coforprod"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = coforprod.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COFORPRODO
tb1 = "coforprodo"
tb2 = "coforprod"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( coforprod.cofprodkey = coforprodo.cofprodkey AND component.cokey = coforprod.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COGEOMORDESC
tb1 = "cogeomordesc"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = cogeomordesc.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COHYDRICCRITERIA
tb1 = "cohydriccriteria"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = cohydriccriteria.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COINTERP
# Beginning with FY2020, only some records are imported into gSSURGO
tb1 = "cointerp"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = cointerp.cokey ) AND (cointerp.ruledepth = 0 OR cointerp.mrulekey = 54955)"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COMONTH
tb1 = "comonth"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = comonth.cokey )"
cnt = QuerySDA(sQuery, tb1)
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COMPONENT
tb1 = "component"
sQuery = Q + tb1.upper() + " WHERE component.mukey IN (" + subQuery + ")"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COPM
tb1 = "copm"
tb2 = "copmgrp"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( copmgrp.copmgrpkey = copm.copmgrpkey AND component.cokey = copmgrp.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COPMGRP
tb1 = "copmgrp"
tb2 = "component"
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = copmgrp.cokey )"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COPWINDBREAK
tb1 = "copwindbreak"
tb2 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = copwindbreak.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# CORESTRICTIONS
tb1 = "corestrictions"
tb2 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = corestrictions.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COSOILMOIST
tb1 = "cosoilmoist"
tb2 = "comonth"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( comonth.comonthkey = cosoilmoist.comonthkey AND component.cokey = comonth.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COSOILTEMP
tb1 = "cosoiltemp"
tb2 = "comonth"
tb3 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + ", " + tb3.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( comonth.comonthkey = cosoiltemp.comonthkey AND component.cokey = comonth.cokey )"
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COSURFFRAGS
tb1 = "cosurffrags"
tb2 = "component"
arcpy.SetProgressorLabel("SDM pass number " + str(test) + " of " + str(iterNum) + ": " + tb1)
sQuery = Q + tb1.upper() + ", " + tb2.upper() + " WHERE component.mukey IN (" + subQuery + ") AND ( component.cokey = cosurffrags.cokey) "
cnt = QuerySDA(sQuery, tb1)
if tb1 in dCount:
dCount[tb1] = dCount[tb1] + cnt
else:
dCount[tb1] = cnt
arcpy.SetProgressorPosition()
# COTAXFMMIN