Convert Labels/Annotation to Points using Python 9.3, get centroids

3277
2
05-09-2011 02:29 PM
DonovanCameron
Deactivated User
I have a problem where I need to generate a point for every label but would like to do it with python  using the shape geometry and have came up with the following results...

[ATTACH]6443[/ATTACH]

The red '0' is the actual label from the feature class, it is being drawn dynamically (not stored as annotation)

When using Calculate Geometry and
!shape.Centroid.*!
they share the same location, like a weighted/centre of gravity point.

The
!shape.Centroid.*!
and
!shape.LabelPoint.*!
return the same point, and neither is actually on the label point...


A workaround, is to convert the labels to annotation (in a gdb), then add two new x/y fields and calculate the geometry of those, then create an XY theme from those two fields. Note that the x/y given will be a bounding box of the annotation, so multi-line labels can affect this. I generate x/y on a label with a single character.


But like I mentioned, a python solution would be nice. The shape.LabelPoint sounded so promising!
Tags (2)
0 Kudos
2 Replies
BradPosthumus
Frequent Contributor
We had to do something similar so we could use ArcMap's label engine to determine the label placement for MapServer WMS's. The process is similar to your workaround:

1. Turn on labels for an ArcMap layer.
2. Convert to an annotation feature class, saved in a file gdb.
3. Re-position the annotation features if necessary.
4. Use the Feature-to-point tool (Data Management->Features) to convert the annotation to a point feature class, using the CENTROID as the point placement option.

Unfortunately there is bunch of manual work involved (steps 1-3). Step 4 we use in a Python script since we perform a number of other processes on the output point file.

Your problem with "LabelPoint" sounds familiar. I vaguely recall testing it and getting the same results as you, and then abandoning it. Maybe it works better in 10?
0 Kudos
DonovanCameron
Deactivated User

4. Use the Feature-to-point tool (Data Management->Features) to convert the annotation to a point feature class, using the CENTROID as the point placement option.


Nice suggestion, it gets rid of the step to create and populate two x,y fields.


I tried the shape.LabelPoint in v10 SP1 and found the same results as before.
0 Kudos