3

I'm trying to label parcels from a shapefile in the Python expression below in ArcGIS 10.2. All parcels should be labeled with the last 8 characters of their [PARCEL_NUM], and parcels 10 acres or greater should also include their [PROP_ADDRE]. [Acres] is a Double field.

Instead, all parcels get labeled with [PARCEL_NUM] and [PROP_ADDRE]. Using Maplex, land parcel placement. Any ideas on what's going wrong?

In response to comments, no, no errors verifying the expression. Tried switching to checking for [ACRES] < 10.0 first, no difference. Also, as noted above, [ACRES] is a Double data type. No Null values in any of the three fields.

def FindLabel ( [PARCEL_NUM], [PROP_ADDRE], [Acres] ):
 if [Acres] >= 10.0:
 return [PARCEL_NUM][-8:] + '\n' + [PROP_ADDRE] 
 else:
 return [PARCEL_NUM][-8:]
Chris W
15.8k2 gold badges30 silver badges47 bronze badges
asked May 19, 2015 at 15:09
3
  • Are you getting any errors when you verify the expression? Commented May 19, 2015 at 15:13
  • @recurvata What is the data type for the Acres field? Commented May 19, 2015 at 15:42
  • Do you have any Null values in the Acres field? Commented May 19, 2015 at 15:48

2 Answers 2

6

This is definitely possible. I just did a test, and I was able to get it to work by using float() around the Acres variable.

So, this worked fine for me:

def FindLabel([PARCEL_NUM], [PROP_ADDRE], [Acres]):
 if float([Acres]) >= 10.0:
 return [PARCEL_NUM][-8:] + '\n' + [PROP_ADDRE] 
 else:
 return [PARCEL_NUM][-8:]
answered May 19, 2015 at 19:05
1
  • 5
    @recurvata This is the correct solution. Per the help file on label expressions, "Field values are automatically cast to text strings. Therefore, if you wish to use a numeric value in an arithmetic operation, or when making a comparison, you will need to cast it back to a numeric data type." Commented May 19, 2015 at 20:46
3

Took me a few tries and some digging to realize but, as per the ArcGIS Help:

Note: To label a subset of features based on a field value, create the SQL query in the label class instead of through the label expression.

So try creating a label class for those features greater than or equal to 10 acres(SQL) then use the expression to format the label. enter image description here

answered May 19, 2015 at 18:15
2
  • That worked, but still not sure why it wouldn't work as straight python. What's the point of having advanced label expressions otherwise? Oh well, thanks. Commented May 19, 2015 at 18:40
  • Ya I was stumped as well Commented May 19, 2015 at 18:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.