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:]
  • Are you getting any errors when you verify the expression? – juturna May 19 '15 at 15:13
  • @recurvata What is the data type for the Acres field? – papadoo May 19 '15 at 15:42
  • Do you have any Null values in the Acres field? – juturna May 19 '15 at 15:48
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

  • 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. – recurvata May 19 '15 at 18:40
  • Ya I was stumped as well – landocalrissian May 19 '15 at 18:49
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:]
  • 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." – Chris W May 19 '15 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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