POST
|
My data frame looks like this when printed. It makes it through your code until the last InsertCursor, pasted here: with arcpy.da.InsertCursor(rollup_tbl, flds) as cur:
for index, groups in rollup.to_dict('index').items():
row = [index]
for fld in flds[1:]:
if fld.upper() == "MTRS":
split = ((i[0], i[2:5], i[6:9], i[9:]) for i in groups[fld])
secs = defaultdict(set)
for mer, twn, rng, sec in split:
mtr = "{}, T{}, R{}: ".format(mer, twn, rng)
secs[mtr].add(sec)
row.append("; ".join(i for
i in
(k + ", ".join(v) for k,v in secs.items())))
else:
row.append(", ".join(i for i in groups[fld]))
cur.insertRow(row)
Runtime error
Traceback (most recent call last):
File "<string>", line 16, in <module>
RuntimeError: The row contains a bad value. [MTRS] I don't need the zeros, maybe I could strip them out in the split on line 6. Thoughts?
... View more
06-05-2019
04:41 PM
|
0
|
0
|
452
|
POST
|
resurrecting old-ish thread. @bixby0012, this is a brilliant bit of code. I am trying to adapt it for something I am working on, but I keep getting an error that the row has a bad value and it is difficult to diagnose while in a cursor. Any ideas on how to add some error handling or a way to pass on bad values within the InsertCursor? Cheers
... View more
06-05-2019
10:13 AM
|
0
|
2
|
452
|
POST
|
I am using Desktop 10.6, basic license, Spatial Analyst, python 2.6, 2019 AD. I have 4 overlapping features in a polygon feature class. I'd like to sort the features by the depth field, calculate the acreage for the largest depth, then move to the next depth, calculate its acreage and then add it to the previous depth, and so on. This code currently does not work past adding the cumulative field. In the attached photo, the cumulative depth is what I am trying to generate. The acres field is to show the progression. Testing the code in the Python window in Desktop reveals that the running total is not behaving as I would expect (printing repeating values versus an increasing value). tempPgs = "LayerName"sort_fields = [tempPgs, "DESCENDING"]
arcpy.AddField_management(tempPgs, "cumulative", "DOUBLE")
CursorFieldNames = ["SHAPE@","cumulative"]
with arcpy.da.UpdateCursor(tempPgs, CursorFieldNames) as cursor:
for row in cursor:
AreaValue = row[0].getArea('GEODESIC', 'ACRES') #Read area value as double
running += AreaValue #Capture running total
row[1] = AreaValue #Write total area value plus the previously added values to field
cursor.updateRow(row)
del row, cursor #Clean up cursor objects
... View more
05-31-2019
05:18 PM
|
0
|
1
|
447
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|