Select to view content in your preferred language

Adding Circle to Map with radius in metres

2445
6
04-28-2010 03:05 AM
KobusPelser
New Contributor
I need to add a circle to the map with a radius in metres. How can I go about this?
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor
What is the spatial reference of your map?
0 Kudos
AlexAgranov
New Contributor
What is the spatial reference of your map?


Could you explain what you mean by that? I also need to draw a circle with a Graphic serving as the vertex.
0 Kudos
dotMorten_esri
Esri Notable Contributor
What does Map.SpatialReference.WKID return after the map has loaded?

This sample app has a radius measure tool that works if your map is in geographic coordinates:
http://resources.esri.com/arcgisserver/apis/silverlight/index.cfm?fa=codeGalleryDetails&scriptID=165...
0 Kudos
AlexAgranov
New Contributor
What does Map.SpatialReference.WKID return after the map has loaded?

This sample app has a radius measure tool that works if your map is in geographic coordinates:
http://resources.esri.com/arcgisserver/apis/silverlight/index.cfm?fa=codeGalleryDetails&scriptID=165...


Basically the Geodesic.GetPointFromHeading() calculates points that are based on the earths' curvature, so I end up with an ellipse. In close distances, like a mile I don't really care about that and just want points that give me a circle.
0 Kudos
dotMorten_esri
Esri Notable Contributor
All you have to do is simplify the code to not take the curvature into account. That's just a little simple Cosine/Sine calculation.
0 Kudos
wangzhifang
Occasional Contributor
/// <summary>
        /// create a new circle geometry, which is polygon, depending on the given center and radius
        /// @diligentpig
        /// @http://newnaw.com
        /// </summary>
        /// <param name="ptCenter">center of the newly created circle.</param>
        /// <param name="dRadius">radius of the newly created circle, in screen pixel.</param>
        /// <param name="n">precision, represents how many point does the return polygon have. These points are symmetrily located.
        /// if n=0, then transfer to default precision which n=32</param>
        /// <param name="map">the map control, used for converting mappoint to screenpoint and vice versa.</param>
        /// <returns>a polygon geometry simulate a circle</returns>
        public static Polygon createCirclePolygon(MapPoint ptCenter, double dRadius, int n,ESRI.ArcGIS.Client.Map map)
        {
            PointCollection pc = new PointCollection();
            System.Windows.Point ptCenterScreen = map.MapToScreen(ptCenter);
            n = n <= 0 ? 32 : n;
            for (int i = 0; i < n; i++)
            {
                //ecah point on the circle, counterclockwise
                double angle = (Math.PI * 2) / n * i;
                System.Windows.Point p = new System.Windows.Point()
                {
                    X = ptCenterScreen.X + dRadius * Math.Cos(angle),
                    Y = ptCenterScreen.Y + dRadius * Math.Sin(angle)
                };
                pc.Add(map.ScreenToMap(p));
            };
            //add the last, which is exact the first, point.
            pc.Add(map.ScreenToMap(new System.Windows.Point()
            {
                X=ptCenterScreen.X+dRadius,
                Y=ptCenterScreen.Y
            }));

            Polygon polyg = new Polygon()
            {
                SpatialReference=map.SpatialReference
            };
            polyg.Rings.Add(pc);

            return polyg;
        }
0 Kudos