PS: Not sure why code indentation is getting messed up when I paste it here...
# untested, probably needs a bit of debugging, and typo fixing CONTOUR_CLASSES = ((20, '5m Contour'), (4, '1m Contour'), # Do you really want the next class? Remove to group with 0.25m contours (3, '0.75m Contour'), (2, '0.5m Contour'), (1, '0.25m Contour')) def classify_contour_value(elevation): for cc, cc_desc in CONTOUR_CLASSES: if int(elevation * 4) % cc == 0: # if dividable by cc it belongs to that class return cc_desc
fc = r"D:/LIDAR/Lidar.gdb/Contour_pt25m" # Creates the cursor rows = gp.UpdateCursor(fc) # Looping gets so much simpler if you let python do the work for you: for row in iter(rows.Next, None): # Convert the geoprocessing iterator to a python iterator con_value = row.CONTOUR # shouldn't be named 'txt' if is a floating point value... con_txt = classify_contour_value(con_value): row.Layer = con_txt rows.UpdateRow(row) # row = rows.Next() # So easy to forget this line and you get an infinite loop. # with a for-loop instead you transfer the resposiblity for this call to the python internals # Clean up cursors ##del rows ##del row # Since the python del statement doesn't delete anything, I prefer setting values to None, but # that is mostly a matter of taste: row = None rows = None
My question is:Is this the cleanest way around this problem? Or is there some other python function I should use?
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.