Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Let's say, a road has the name "William-Bill-Gates-Road".

If the road is too short, the label can only be abbreviated by using a dictionary in Maplex. Is it possible to make Maplex try several label fields, if one is not fitting?

Structure:

name | name_1 | name_2 | ... William-Bill-Gates-Road | William-Bill-Gates-Rd. | W.-Bill-Gates-Rd. | W.-B.-Gates-Rd.

share|improve this question
add comment

1 Answer

The short answer is yes.
here is some code that should work in 10.0 and previous.
Grant it doesn't exactly use an alternate field but shortens the word.
I figure you might be able to recreate it with the loop you need.

Function FindLabel ( [Name] )

Dim strArray
Dim outStr
Dim x
Dim maxWordLength
Dim minLengthLength
Dim everyother
Dim isFirst
Dim lastWordLong
lastWordLong = false

maxWordLength = 10
minWordLength = 3
everyother = False
isFirst = True
strArray = Split( [Name], " ")

For x = 0 To UBound(strArray)

    If ((Not isFirst) And (Len(strArray(x)) <= minWordLength)) Then
        'keep short word on existing line
        outStr = outStr & " " & strArray(x)
        everyother = False
    ElseIf (everyother) Then
        'word x is slated to be second word on line
        If (Len(strArray(x)) > maxWordLength) Then
            outStr = outStr & vbNewLine & strArray(x)
            everyother = False
        Else
            outStr = outStr & " " & strArray(x)
            everyother = False
        End If
    Else
        'word x is slated to be first word on line
        If (isFirst) Then
            outStr = strArray(x)
            everyother = True
            isFirst = False
        Else
            If (Len(strArray(x)) > maxWordLength) Then
                lastWordLong = True
                everyother = False
            Else
                lastWordLong = False
                everyother = True
            End If

            outStr = outStr & vbNewLine & strArray(x)

        End If
    End If
Next

FindLabel = outStr

End Function

I didn't write it but inherited a map with that vbscript in it.

share|improve this answer
    
Thanks for the code, but the problem is, the function will run even if there's enough space on the geometry to label the full name. By using "keywords" in the dictionary of Maplex, it tries the normal name first and then looks for a fitting abbreviation. –  GIS Student Sep 29 '12 at 13:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.