This is a migrated thread and some comments may be shown as answers.

How to get Points from RadDiagramShape

2 Answers 108 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Jeevan
Top achievements
Rank 1
Jeevan asked on 26 Feb 2014, 12:20 PM
Hi 

Is there some way by which we can get the points on a RadDiagramShape. 
Currently we see that the RadDiagramShape has Geometry property. Is there some way to get a PointCollection from the shape.
eg Is it possible to get the four points of a rectangle represented by  RadDiagramShape.

Regards
Jeevan

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 28 Feb 2014, 03:47 PM
Hello Jeevan,

Thank you for your question.

You cannot get a collection of Points from a RadDiagramShape out of the box. However, this can be achieved by using some custom logic. In order to do it you will need to get the flattened PathGeometry of the Shape with the GetFlattenedPathGeometry() method. Then you should get every Point of every PathSegment in the PathGeometry.

In the next few lines I will try to explain how exactly you can get those points. Let's begin with that e
very PathGeometry has a collection of PathFigures and every PathFigure in this collection has a PathSegments collection. When the collection is flattened the PathSegments collection contains only PolylineSegments and every one of those segments has a collection of Points which you may use to achieve your requirement. Here is an example in code:
private void GetGeometryPoints(IGeometryShape shape)
{
    PathGeometry pathGeometry = shape.Geometry.GetFlattenedPathGeometry();
 
    var pointCollection = new List<Point>();
 
    foreach (PathFigure figure in pathGeometry.Figures)
    {
        foreach (PathSegment segment in figure.Segments)
        {
            var polySegment = segment as PolyLineSegment;
            if (polySegment != null)
            {
                foreach (Point point in polySegment.Points)
                {
                    Point newPoint = new Point
                    {
                        X = point.X + this.Shape1.Position.X,
                        Y = point.Y + this.Shape1.Position.Y
                    };
                    pointCollection.Add(newPoint);
                }
            }
        }
    }
}

I also attached a sample project with the described approach. 

Regards,
Martin
Telerik
0
Jeevan
Top achievements
Rank 1
answered on 17 Mar 2014, 07:03 AM
Thanks Martin.
Tags
Diagram
Asked by
Jeevan
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Jeevan
Top achievements
Rank 1
Share this question
or