Checking comments on my blog this morning I ran into this question:

Thank you very much for nice post. I have one more query. I want to display elavations of contours for each contour line at some fixed interval. I don’t want to draw lable lines. Is there any way to do that. If u know it please help me

Most likely they want an automatic contour labeling routine but it got me thinking, what about labeling every third contour? Or every seventh? Or every whatever the heck you want contour! It’s pretty simple, you just need an expression that will check the interval and then control it’s display. Here’s how to do it.

For this example I am going to label every third contour line. First, create an expression. This expression will see if the contour is at the interval. If it is, then return the contour elevation. If it’s not, return a negative one. To create the expression, expand out Surface on the Settings tab of the prospector, then Label Styles, and finally Contour. Right click on Expressions and select New…

New Expression

In the new expression dialog box give the expression a name and a description. Have a little forethought on this as you can’t go back and rename or change the description of the expression. The actual expression itself will look something like this (remember I’m doing this for every third contour):

Expression Settings

So, what does this expression do? The test in the IF statement is “{Surface Elevation}/3=TRUNC({Surface Elevation}/3)”. This tests to see if the contour is the third contour or not. If this test is true (the contour IS divisible evenly by three) then it returns the contour elevation, if it’s not, it returns -1. This -1 is key to how this expression works in the label style.

And make sure to format it as an elevation.

Now that the expression is created use it in your label style. You can create a new style or copy an existing style. In the style composer, edit the style. On the Layout tab, edit the contents of the text component. Remove the current text from the right hand side and insert your new expression into the label. When you do this, the important part is to set the “Sign” value to “hide negative values”. This way if the expression returns -1 it will, basically, not display anything at all.

Applying the Expression

Once you have done this to all label styles involved in your labeling process (i.e. major, minor, user, etc.) your drawing will look something like this:

Expression Used in Labels

You want to change the interval? Modify the expression or create a new one for that interval. Want to adjust the base of the calculation? Simply add a number in the surface expression to adjust it. For example, I want to label contours 1, 4, 7, and 10. The expression would look like this: IF(({Surface Elevation}+1)/3=TRUNC(({Surface Elevation}+1)/3),{Surface Elevation},-1) – Notice that I added 1 to the first two {Surface Elevation} values to adjust the test (don’t add 1 to the last one!).

About these ads