Select to view content in your preferred language

Trying to rotate icon differently for each unique value in UniqueValueRenderer

1046
2
09-18-2018 07:41 AM
ZacharyKlaas
Emerging Contributor

Hi, why does this code rotate every item's icon instead of each icon separately?  I cannot get the necessary information from documentation available.  I want each unique value to have a differently rotated symbol:

l = m.listLayers("xylayer")[0]

sym = l.symbology

symList = sym.renderer.symbol.listSymbolsFromGallery("ShipAIS")

current = None

for symbol in symList:
  current = symbol

sym.updateRenderer("UniqueValueRenderer")
sym.renderer.fields = ["Combined_True_Heading"]

for grp in sym.renderer.groups:
  for itm in grp.items:
    itm.symbol = current
    if(itm.values[0][0] != "<Null>"):
      itm.symbol.angle = 360 - float(itm.values[0][0])
    else:
      continue

l.symbology = sym

0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus
if itm.values[0][0] is not None:

<null> is how it shows in the geodatabase table, None is python.  Assuming it is not an empty string then you have to check a bit more

if itm.values[0][0] not in ("", None):
ZacharyKlaas
Emerging Contributor

Thanks, Dan.


I made the change and it ended up not catching the cases that are null, probably because the data table this is being run on is the result of a join and what is in those cells are Strings (that is, the String "<Null>").

So presently I've changed this to "if itm.values[0][0] not in ("<Null>", None):" and it is still catching the instances where it says "<Null>", while also catching any other potential instances of no value for a particular cell, so it's an improvement in the code to be sure.

It's still not solving the issue with the icons rotating as a group rather than allowing me to rotate each individually, though.  Is there another way I can get at that?

0 Kudos