Quantcast
Channel: DotSpatial
Viewing all articles
Browse latest Browse all 3973

New Post: Draw Circle on a Map.Drawing layer

$
0
0
I actually found out that the best way to do it is to calculate the circle circumference coordinates (for a given circle center and radius) and then feed them to MapPolygonLayer.

The circle points can be calculated by a step of a circle segment angle. The smaller the angle the smoother the circle. I think for most cases 60 segments will do.
I used the following two functions:
 protected void RecalculatePoints() {
            List<Coordinate> circlePoints = new List<Coordinate>();
            double arcSegment = 360.0/m_segments;

            for (int i = 0; i < m_segments; i++) {
                PointD c = CirclePoint(arcSegment*i);
                circlePoints.Add(new Coordinate(c.X, c.Y));
            }

            LinearRing lr = new LinearRing(circlePoints);
            Polygon obj = new Polygon(lr);
            IFeature f = ShapeFeatureSet.AddFeature(obj);
            ...
            ...
            ...

        }

        private PointD CirclePoint(double segAngle) {  
             // a little tip the m_radius should be in Radians
            double x = m_radius * Math.Cos(segAngle* Math.PI / 180.0) + Center.X;
            double y = m_radius * Math.Sin(segAngle* Math.PI / 180.0) + Center.Y;

            return new PointD(x, y);
        }

Viewing all articles
Browse latest Browse all 3973


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>