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– juturna2015年05月19日 15:13:44 +00:00Commented May 19, 2015 at 15:13
-
@recurvata What is the data type for the Acres field?papadoo– papadoo2015年05月19日 15:42:19 +00:00Commented May 19, 2015 at 15:42
-
Do you have any Null values in the Acres field?juturna– juturna2015年05月19日 15:48:47 +00:00Commented May 19, 2015 at 15:48
2 Answers 2
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– Chris W2015年05月19日 20:46:10 +00:00Commented May 19, 2015 at 20:46
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– recurvata2015年05月19日 18:40:10 +00:00Commented May 19, 2015 at 18:40
-
Ya I was stumped as welllandocalrissian– landocalrissian2015年05月19日 18:49:46 +00:00Commented May 19, 2015 at 18:49
Explore related questions
See similar questions with these tags.