In ArcMAP 10.2, I am trying to format the labels on my map.
If the label is
1402 Bowie Road
But I want only to display numbers:
What is the expression to create this?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
You can put this as the label expression for the feature:
def FindLabel(yourField): if yourField is not None: split_field = yourField.split(" ") return str(split_field) else: return None
Using Python as the parser and checking the Advanced box.
Replace yourField with whatever field you are using to label.
An alterntive to ian's suggestion, you can change your label expression to something like the following. By importing the regular expression module, you can create function to only display numbers at the beginning of a string.
def NumberLabel(addressField): import re return re.search('^\d*', addressField).group()
As per Ian's example, use python as the parser.
This will return the number at the beginning of a string.
1402 Bowie Road will return 1402 123 Main Street will return 123 123 Main Street Unit 4 will return 123 515 4th Avenue will return 515 613Main Street will return 613
Note that last example does not have a space after the number yet still returns the correct result.
Another alternative to both Ian and Fezter's answers is to use the INSTR and MID VB script functions (This particular expression does not require you to be in an Advanced Expression mode):
MID([Your_Field], 1, INSTR([Your_Field]," "))
INSTR function has the following parameters: InStr([start,]string1,string2[,compare])
MID function has the following parameters: Mid(string,start[,length])
Square brackets indicate optional parameters