I need place labels regardless of collisions with other layers. I use ArcPy and CIM. I need to place the label in the center of the polygon. At the same time, I need it not to change its position or disappear if it collides with another labels or feature. I try this code, but some labels are placed outside the polygons.
show_labels = m.listLayers("polygon23*") show_labels.showLabels = True for lyr in m.listLayers("polygon23*"): if lyr.supports("SHOWLABELS"): if lyr.showLabels: for lblClass in lyr.listLabelClasses(): lblClass.expression = ''' "<FNT size='6'>" + $feature.label + "</FNT>"''' label_show = m.listLayers('polygon23*') l_cim = label_show.getDefinition('V2') lc = l_cim.labelClasses lc.maplexLabelPlacementProperties.polygonPlacementMethod = 'StraightInPolygon' lc.maplexLabelPlacementProperties.placeOnlyInsidePolygon = True lc.CIMStandardLabelPlacementProperties = 'allowOverlappingLabels'
One thing to watch out for: the default value for canOverrunFeature tends to be 80 points, which can allow labels to be placed outside of the polygon, even when you've turned on the setting that would apparently disallow this.
I would also suggest setting enablePolygonFixedPosition to "True", then set the internal zone priorities such that center is the only non-zero option, thus forcing your labels to render at the center of the polygon, no matter what.