Python: generating contour types using contour values

Discussion created by dedge on Mar 28, 2011
Greetings All

Apologies for the cross-posting

I've looked around and can't seem to find a ready-made solution to my problem. (Maybe I'm looking in the wrong place)

Anyhoo....I have generated a whole bunch of contours from a DEM and would like an attribute that would separate the contours into: 5m contours, 1m contours etc.

I fudged a python script together that takes the contour value, separates the fraction from the whole number, evaluates the the fraction and then populates the Layer field.

My question is:
Is this the cleanest way around this problem? Or is there some other python function I should use?

This is my code....
fc = r"D:/LIDAR/Lidar.gdb/Contour_pt25m"

# Creates the cursor
rows = gp.UpdateCursor(fc)
row = rows.Next()

# takes each contour value, separates the decimal from the whole number...
# evaluates it and then assigns the index type to the LAYER field

while row:
ConTxt = row.CONTOUR
TxtSplt = math.modf(ConTxt)
if TxtSplt[0]==0.5:
row.Layer = "0.5m Contour"
elif TxtSplt[0]==0.25:
row.Layer = "0.25m Contour"
elif TxtSplt[0]==0.75:
row.Layer = "0.75m Contour"
elif TxtSplt[0]==0.0:
Txt2 = float(ConTxt)/5
IntTxt = math.modf(Txt2)
if IntTxt[0]==0:
row.Layer = "5m Contour"
row.Layer = "1m Contour"
row = rows.Next()

# Clean up cursors
del rows
del row

Thanks in advance


PS: Not sure why code indentation is getting messed up when I paste it here...