Looking for unplaced label information using ArcPy - in the CIM somewhere?

603
1
Jump to solution
05-24-2021 08:16 AM
TobiSellekaerts
New Contributor III

I am working on some code for automated map generation, migrating an old script from arcpy.mapping to Python 3 and arcpy.mp.  The script creates a map showing 1-n points, each individually labeled.  My overall approach is to try to label each point individually and if there are no unplaced labels, then the script will be done.  If there are unplaced labels, it will then additional strategies such as key numbering, aggregating labels, etc., checking after each to see if there are no more unplaced labels (or until it reaches the end and tells the user to fix it manually.)

Here's where I'm having trouble: I can't find where to access some kind of indicator (a boolean? a list of unplaced labels?) to tell the script if there are any unplaced labels.  I'm trying to avoid a human having to look at the map to provide feedback to the script that there are still unplaced labels (at which point our computer overlords will have won....) Simply forcing it to draw all the labels even when there are conflicts isn't really a solution I can use either.  I could dump out a raster then try some kind of cludgy OCR to look for red but there might be other red things on the map, and let's call that an option of last resort.  

I'm hoping it's in the CIM somwehere - this seems like something that should be in the CIM - and I just haven't found it yet; I've been looking here:

https://github.com/Esri/cim-spec/blob/master/docs/v2/CIMLabelPlacement.md

Tags (4)
0 Kudos
1 Solution

Accepted Solutions
TobiSellekaerts
New Contributor III

I've come up with a workaround, in case anyone else has this requirement in the future.

  1. Set up your labeling
  2. use arcpy.cartography.ConvertLabelsToAnnotation() to create an annotation table
  3. use a cursor on the output table to find any entries where STATUS=1 (which means, unplaced label)
  4. If there aren't any records where STATUS=1, you're done.  Otherwise:
    1. Remove the annotation layer from the map
    2. Turn back on labeling for all your labeled layers
    3. Go back to #1

View solution in original post

0 Kudos
1 Reply
TobiSellekaerts
New Contributor III

I've come up with a workaround, in case anyone else has this requirement in the future.

  1. Set up your labeling
  2. use arcpy.cartography.ConvertLabelsToAnnotation() to create an annotation table
  3. use a cursor on the output table to find any entries where STATUS=1 (which means, unplaced label)
  4. If there aren't any records where STATUS=1, you're done.  Otherwise:
    1. Remove the annotation layer from the map
    2. Turn back on labeling for all your labeled layers
    3. Go back to #1
0 Kudos