How can i get the rectangle boundary of an annotation object using ArcObjects?
Once we select an object on the map, there is a boundary as shown in the first picture.
Also is there an option to get the minimum rectangle that covers the text as shown in second picture?
enter image description here
I tried
IAnnotationFeature annoFeature;
annoFeature.Annotation.Geometry;
but this only gives me a polyline geometry which seems to be the baseline of text
2 Answers 2
For your first example, try IElement.QueryOutline
:
QueryOutline returns a polygon representing the outline of the element. A valid polygon object must be passed in to the method along with the current display. The method then updates the polygon object. The results for point and line elements will be similar to the minimum bounding envelope returned by QueryBounds, while the results for polygon elements while be the actual outline of the element (not the bounding envelope).
As for your second example, it's much more difficult, but should be possible by first converting the annotation to a multi-part polygon and then getting the minimum area bounding rectangle of that polygon.
The following two links should have enough code to get you there, or very close, but they are in VBA, not C#:
- How to convert annotation to polygon features (ArcGIS 10 VBA SDK Help)
- Here's a C# version of the above code someone made: Convert Annotation to Polygon Features sample fails on multi part annotation (IQueryGeometry.GetGeometry) (ESRI forums)
- Re: Simplify irregular shape building to rectangle (ESRI forums)
- If this doesn't produce the desired rectangle you could also try using the Minimum Boundary Geometry geoprocessing tool with the
RECTANGLE_BY_WIDTH
option.
- If this doesn't produce the desired rectangle you could also try using the Minimum Boundary Geometry geoprocessing tool with the
-
nice! this got me the outline as per the picture 1 in question..any tips on getting the second one? Is this text always going to be at a ratio to the polygon we obtained through QueryOutline?vinayan– vinayan2012年10月27日 10:50:58 +00:00Commented Oct 27, 2012 at 10:50
-
updated answer, might be possible but much more difficultblah238– blah2382012年10月28日 00:24:36 +00:00Commented Oct 28, 2012 at 0:24
-
I had seen that example..but i never thought of getting a minimum boundary from those :) .. for minimum boundary, i think ITopological.ConvexHull could be used..thanks for the answer..still would have loved a simpler method ;)vinayan– vinayan2012年10月28日 03:55:30 +00:00Commented Oct 28, 2012 at 3:55
The rectangle displayed in ArcMap is defined on the Feature itself and not on the Annotation.
To get this rectangle you cast your IAnnotationFeature
to IFeature
and then get the geometry using IFeature.Shape
or IFeature.ShapeCopy
.
IAnnotationFeature annoFeature;
var feature = (IFeature) annoFeature;
IGeometry annoGeometry = feature.Shape;
If you want to manipulate an annotation element or its symbol in code the rectangle will update when IFeature.Store()
is called.