Labeling

4680
11
Jump to solution
06-04-2015 02:20 PM
Labels (1)
LizHousworth
New Contributor

I'm new at this, so please bare with me.  I was recently asked if I could create a map showing tax parcel color coded in to code classes (ie - > 50,000, 50,000-100,000, etc) and then have the assessment value labeled on each parcel as well.  Our assessment values are in represented into the 100 place (ie - ($)120,200, ($)15,800, ($)267,800, etc.), however they have asked if I can that the labels be 120K, 16K, 268K and so forth.  (essentially rounding the numbers to the nears 1000.  I have found where I can pick how many significant digits should appear, but anything less than 100,000 rounds to the 100 not to the nearest 1000.  (ie - $15,800 remains this as opposed to being rounded to 16,000).

Is this something that is possible to achieve with labeling or is it possible by using the field calculator?  Thanks your any help you can provide me.

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

Dynamic labeling using Python should do it for you. Set the label parser to Python and use an expression like this:

"{}K".format(int(round([VALFIELD] / 1000.0)))

You can test this kind of thing at the Python prompt:

>>> "{}K".format(int(round(120800 / 1000.0)))
'121K'

View solution in original post

11 Replies
JeffWard
Occasional Contributor III

You can do it both ways.  Dynamic labeling with scripts usually comes with a performance hit since it has to do the job with every feature with every pan, zoom etc.  If you create a field and calculate it, you would only run the script once and label on that field.

Jeff Ward
Summit County, Utah
JeffWard
Occasional Contributor III

Are your values text entries or numbers?

Jeff Ward
Summit County, Utah
0 Kudos
LizHousworth
New Contributor

They are number values

Liz Housworth

GIS/LIS Technician

Land Information Office

220 E State St, Rm 110

Mauston, WI 53948

(608) 847-9457

liojuneau@co.juneau.wi.us<mailto:liojuneau@co.juneau.wi.us>

0 Kudos
JeffWard
Occasional Contributor III

If they are integers you can use this to calculate the new text field using the python parser

str(value / 1000) + 'K'

If they are floats

str(int(value) / 1000) + 'K'

Replace 'value' in the above script with '!your_field_name!

Jeff Ward
Summit County, Utah
JeffWard
Occasional Contributor III

Keep in mind this doesn't round, it truncates.  So 259,900 would show up as 259K instead of 260K.

Jeff Ward
Summit County, Utah
0 Kudos
OwenEarley
Occasional Contributor III

In the field calculator change the parser to python and use the following formula:

int(round( !A_Value! , -3)) / 1000

This will give you the rounded value in thousands.

Edit - you will need to replace the !A_Value! with your own field name.

curtvprice
MVP Esteemed Contributor

Dynamic labeling using Python should do it for you. Set the label parser to Python and use an expression like this:

"{}K".format(int(round([VALFIELD] / 1000.0)))

You can test this kind of thing at the Python prompt:

>>> "{}K".format(int(round(120800 / 1000.0)))
'121K'
JeffWard
Occasional Contributor III

That's much better than mine.

Jeff Ward
Summit County, Utah
0 Kudos
OwenEarley
Occasional Contributor III

Note that the first formula has an extra closing parenthesis after the field placeholder [VALFIELD] that will result in an error:

"{}K".format(int(round([VALFIELD]) / 1000.0)))
Parsing error SyntaxError: invalid syntax (line 1)

Remove the extra closing parenthesis and it works great.

As long as you are not labelling a crazy number of features I would go for the dynamic labelling as you don't need to update calculated fields as your data changes.

0 Kudos