Greetings All

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"

else:

row.Layer = "1m Contour"

rows.UpdateRow(row)

row = rows.Next()

# Clean up cursors

del rows

del row

Thanks in advance

Dustin

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

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"

else:

row.Layer = "1m Contour"

rows.UpdateRow(row)

row = rows.Next()

# Clean up cursors

del rows

del row

Thanks in advance

Dustin

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

If you enclose your code in code tags the indentation will be preserved. To get code tags, just press the "#"-button when you write your message.

Now to your problem:

I would start by splitting up the logic in two parts: The looping, and the categorizing of the contour lines, with a function for the latter:

The looping needs some improvement too:

There are other ways to do it too. Can't tell you which way is "THE cleanest". There certainly isn't a core python function for classifying elevation values in your way, so some coding is necessary, no matter what.