import arcpy # Change these 2 input parameters accordingly... fc = r'E:\schoolTestData\test.gdb\schoolJoinToPolys' outField = 'outGrades' delField = arcpy.AddFieldDelimiters(fc, outField) # This query works whether shapefile or gdb fc. query = delField + ' IS NOT NULL AND ' + delField + ' NOT IN (\' \')' rows = arcpy.UpdateCursor(fc, query) for row in rows: # This populates a list, row by row... # outGradesRaw will potentially contain 'P' vals. # outGrades is a new list with 'P' vals eliminated. outGradesRaw = row.getValue(outField).split(',') outGrades = [] for each in outGradesRaw: if not each[0:1] == 'P': outGrades.append(each) # sorted outGrades for loop, comparison of successive items outGrades.sort() # initializing count count = 0 compareVal = outGrades[0] # Loop over the sorted list to count. for each in outGrades: if each == compareVal: count += 1 else: # This conditionally sets the fieldName to load... if not compareVal[0:1] == 'K': fieldName = 'Grade_' + str(int(compareVal)) else: fieldName = 'Grade_K' # Successive K vals may not match, # so will be temp stored in att table, # then fetched to make a cumulative count. count += row.getValue(fieldName) # count committed to row obj from att table row.setValue(fieldName, count) # row obj committed to cursor obj of att table rows.updateRow(row) # resetting count to 1 count = 1 # setting compareVal to current val compareVal = each # load the count for the last val, identical to part of above block if not compareVal[0:1] == 'K': fieldName = 'Grade_' + str(int(compareVal)) else: fieldName = 'Grade_K' count += row.getValue(fieldName) row.setValue(fieldName, count) rows.updateRow(row) del rows
if not compareVal in ['KA', 'KP', 'PA', 'PP']: fieldName = 'Grade_' + str(int(compareVal)) elif not compareVal in ['PA', 'PP']: fieldName = 'Grade_K' count += row.getValue(fieldName)
if not compareVal in ['KA', 'KP', 'PA', 'PP', 'K', 'P', 'Kitchen Sink', 'other']: fieldName = 'Grade_' + str(int(compareVal)) elif not compareVal in ['PA', 'PP', 'P', 'any other preschool']: fieldName = 'Grade_K' count += row.getValue(fieldName)
if not compareVal in ['KA', 'KP', 'PA', 'PP', 'each K or P anticipated values separately listed like this']: fieldName = 'Grade_' + str(int(compareVal)) if 'P' not in compareVal: fieldName = 'Grade_K' count += row.getValue(fieldName)
query = arcpy.AddFieldDelimiters(shp, outField) + ' IS NOT NULL' rows = arcpy.UpdateCursor(shp, query) for row in rows: outGrades = row.getValue(outField).split(',') outGrades.sort() count = 0 compareVal = outGrades[0] for each in outGrades: if each == compareVal: count += 1 else: if not ('K' or 'P') in compareVal: fieldName = 'Grade_' + str(int(compareVal)) if compareVal[0:1] == 'K': fieldName = 'Grade_K' count += row.getValue(fieldName) row.setValue(fieldName, count) rows.updateRow(row) count = 1 compareVal = each # load the last unique val if not ('K' or 'P') in compareVal: fieldName = 'Grade_' + str(int(compareVal)) if compareVal[0:1] == 'K': fieldName = 'Grade_K' count += row.getValue(fieldName) row.setValue(fieldName, count) rows.updateRow(row) del row, rows
>>> testval = 'KKKKK' >>> if not ('K' and 'P') in testval: print 'true' true >>> if not 'K' in testval and not 'P' in testval: print 'true' >>>
query = arcpy.AddFieldDelimiters(shp, outField) + ' IS NOT NULL' rows = arcpy.UpdateCursor(shp, query) for row in rows: outGrades = row.getValue(outField).split(',') outGrades.sort() count = 0 compareVal = outGrades[0] for each in outGrades: if each == compareVal: count += 1 else: if not 'K' in compareVal and not 'P' in compareVal: fieldName = 'Grade_' + str(int(compareVal)) if compareVal[0:1] == 'K': fieldName = 'Grade_K' count += row.getValue(fieldName) row.setValue(fieldName, count) rows.updateRow(row) count = 1 compareVal = each # load the last unique val if not 'K' in compareVal and not 'P' in compareVal: fieldName = 'Grade_' + str(int(compareVal)) if compareVal[0:1] == 'K': fieldName = 'Grade_K' count += row.getValue(fieldName) row.setValue(fieldName, count) rows.updateRow(row) del row, rows
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.