Select to view content in your preferred language

Conditioning labels

5404
12
Jump to solution
02-10-2015 10:56 AM
Ulises
by
Frequent Contributor

Hi everyone,

I'm trying to define an expression for labeling parcel polygons in ArcMap.  The feature class has 3 attributes of interest: CATEGORIA, NUM_CATASTRO, and PARCEL_SP.  If CATEGORIA (integer field with subtypes defined) is not 0 (N/A), then label the polygon with the value in PARCEL_SP, otherwise label with NUM_CATASTRO.  I'm not a programmer and I'm just starting with Python so I'm not sure what is missing.  So far I have...

def FindLabel (  [CATEGORIA],[NUM_CATASTRO], [PARCEL_SP] ):
  if [CATEGORIA] ==0:
    return [PARCEL_SP]
  else:
    return  [NUM_CATASTRO]

The issue is that I can see labels for NUM_CATASTRO where they should, but none for PARCEL_SP. 

If I reverse the values...

def FindLabel (  [CATEGORIA],[NUM_CATASTRO], [PARCEL_SP] ):
  if [CATEGORIA] ==0:
    return  [NUM_CATASTRO]
  else:
    return [PARCEL_SP]

it labels the PARCEL_SP where is supposed to but not the NUM_CATASTRO.

Same thing using the following statement...

def FindLabel (  [CATEGORIA],[NUM_CATASTRO], [PARCEL_SP] ):
  if [CATEGORIA] !=0:
    return   [PARCEL_SP]
  else:
    return  [NUM_CATASTRO]

Any help will be appreciated...

Thanks

Ulises Feliciano Troche
0 Kudos
12 Replies
Ulises
by
Frequent Contributor

I tried with VBScript and it worked.  After banging my head for a while against the monitor I decided to try one last thing before a break...RESTART ArcMap.

Then get back to Python and tried again...IT WORKED!!!

Don't really know what happened, but Tom's suggestion make me try using the string value for the subtype instead of the number and it worked.  The final code is like this...

def FindLabel (  [CATEGORIA],[NUM_CATASTRO], [PARCEL_SP] ):
  if [CATEGORIA] =='N/A':
    return  [NUM_CATASTRO]
  else:
    return "<CLR red='255'><FNT size = '10'>" +  [CATEGORIA] + "</FNT></CLR> <CLR blue='255'> \n" + [PARCEL_SP] + "</CLR>"

Find it weird that I needed to use the description instead of the integer value for the subtype field.

Thanks again for the help and suggestions.

Ulises Feliciano Troche
0 Kudos
TomSellsted
MVP Regular Contributor

Ulises,

Perfect!  Glad that worked for you!  Please mark the answer as correct too!

Regards,

Tom

Zeke
by
Honored Contributor

Maybe post a screenshot of part of your attribute table.

0 Kudos