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…
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):
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.
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:
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!).
June 25, 2012 at 10:47 pm
A better solution is to return a valid text height or zero, and use the expression in the label text height field. If it is zero, the text is not displayed, otherwise the label is displayed. There are countries where a negative contourline is a possibility.
June 27, 2012 at 5:52 am
In areas where you might have negative elevations, that will work. The problem I’ve run into using that method is if you have the background mask turned on you’ll end up with dots on the contours where the non-existent labels are.
June 26, 2012 at 12:06 am
Your post was very timely! I have just been doing some training with a client and they asked if this could be done. I said ‘yes’ but ‘very complicated’. I was looking at doing it by setting a strange Major and Minor contour interval but this is a lot easier.
Well done and thanks you
October 23, 2012 at 10:00 am
regarding item #7 – where is this labelcontrol dialog box and what is the command name? thanks a bunch!
October 24, 2012 at 7:20 pm
I’m not sure what you are referring to when you are asking about the labelcontrol dialog box. Which dialog box are you wanting?
October 25, 2012 at 9:00 am
Brian,
I cannot find the page now. it’s not the one referenced in the email. There were several dialog boxes on the page, this one was labeled #7 and in the top-left, the description said “Label Control”. In the dialog box there were main objects listed and to the right there were check boxes. Sorry I can’t find the page again.
Thanks,
Phil