Quantcast
Channel: Question and Answer » arcmap
Viewing all articles
Browse latest Browse all 248

Python Labeling using dictionary not printing all values

$
0
0

I am labeling manhole inverts using python and ArcMap 10.3. When I use a dictionary to control the label order some manholes don’t print all of the inverts while other manholes do. I can post field information/attribute table info if needed. I suspect its an error on my part using an empty/none field in the dictionary and underlying hash table but I really don’t know enough to say that with confidence.

How can I get all the inverts to display? – do a check on every argument for none or “” before inserting into the dictionary?

Working Label Expression:

I think here dict is set to a list with grouped values (key,value),(key,value),etc and everything is working correctly:

import json
def FindLabel ( [Elevation] , [Out_Elev] , [Out_Loc] , [In1_Elev] , [In1_Loc] , [In2_Elev] , [In2_Loc] , [In3_Elev] , [In3_Loc]  ):
  dict = ([Out_Elev],[Out_Loc]),([In1_Elev],[In1_Loc]),([In2_Elev],[In2_Loc]),([In3_Elev],[In3_Loc])
  x = json.dumps(dict, sort_keys=True)
  return x

Inverts Showing

Not-Working Label Expressions:

The next two pictures show where I try to use a dictionary. This first one is changing dict from a list to a dictionary using dict = OrderedDict(dict) and the second one is setting straight to a dictionary using dict = {key:value,key:value,etc}. I don’t understand why all 3 inverts display for the manhole at the top of the picture but not for the one on bottom left.

Using dict = OrderedDict(dict)

Inverts not showing

from collections import OrderedDict
import json
def FindLabel ( [Elevation] , [Out_Elev] , [Out_Loc] , [In1_Elev] , [In1_Loc] , [In2_Elev] , [In2_Loc] , [In3_Elev] , [In3_Loc]  ):
  dict = ([Out_Elev],[Out_Loc]),([In1_Elev],[In1_Loc]),([In2_Elev],[In2_Loc]),([In3_Elev],[In3_Loc])
  dict = OrderedDict(dict)
  x = json.dumps(dict, sort_keys=True)
  return x

Another code variant where inverts are not showing using dict = {key:value,key:value,etc}

Inverts not showing 2

import json
def FindLabel ( [Elevation] , [Out_Elev] , [Out_Loc] , [In1_Elev] , [In1_Loc] , [In2_Elev] , [In2_Loc] , [In3_Elev] , [In3_Loc]  ):
  dict = {[Out_Elev]:[Out_Loc],[In1_Elev]:[In1_Loc],[In2_Elev]:[In2_Loc],[In3_Elev]:[In3_Loc],}
  x = json.dumps(dict, sort_keys=True)
  return x

Viewing all articles
Browse latest Browse all 248

Trending Articles