Select to view content in your preferred language

Draw a circle with width in meter

3484
2
Jump to solution
04-03-2014 12:25 AM
Labels (1)
NicolasVIOT
Deactivated User
Hi everyone,

I would like to draw a circle on a point with width in meter.

To do that, I've tried to use the scale of the map.
Assuming that scale = ft / pixel (i'm not sure that this formula is correct)
And ft = m * 3.2808

sizeInPixel = sizeInMeter / MyMap.Scale * 3.2808;

To draw the circle I use a class inheriting from polygon :
    public class Circle : Polygon     {         private double radius = double.NaN;         private MapPoint center = null;         private int pointCount = 360;          public double Radius         {             get { return radius; }             set { radius = value; CreateRing(); }         }          [System.ComponentModel.TypeConverter(typeof(MapPointConverter))]         public MapPoint Center         {             get { return center; }             set { center = value; CreateRing(); }         }          public int PointCount         {             get { return pointCount; }             set { pointCount = value; CreateRing(); }         }          private void CreateRing()         {             this.Rings.Clear();             if (!double.IsNaN(Radius) && Radius > 0 && Center != null && PointCount > 2)             {                 PointCollection pnts = new PointCollection();                 for (int i = 0; i <= PointCount; i++)                 {                     double rad = 2 * Math.PI / PointCount * i;                     double x = Math.Cos(rad) * radius + Center.X;                     double y = Math.Sin(rad) * radius + Center.Y;                     pnts.Add(new MapPoint(x, y));                 }                 this.Rings.Add(pnts);             }         }     }


And to define the width of my crircle :
            var buffer = new _2gDataRoomViewer.MyGeoms.Circle();             buffer.Center = new MapPoint(lon, lat);             buffer.Radius = bufferSize / (MyMap.Scale * 3.2808);//bufferSize is the width in meter              GraphicsLayer bufferPuitsLayer = MyMap.Layers["BufferPuitsLayer"] as GraphicsLayer;              var symbol = new SimpleFillSymbol();             symbol.BorderThickness = 3;             SolidColorBrush color = new SolidColorBrush(Colors.Violet);             symbol.Fill = color;             symbol.Fill.Opacity = 0.3;             symbol.BorderBrush = color;              Graphic graphic = new Graphic()             {                 Geometry = mercator.FromGeographic(buffer),                 Symbol = symbol             };             bufferPuitsLayer.Graphics.Add(graphic);


But it doesn't works And the size change when I try to recalculate it on a zoom/dezoom
When I zoom in :
[ATTACH=CONFIG]32760[/ATTACH]
When I zoom out :
[ATTACH=CONFIG]32761[/ATTACH]

Thanks
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: nviot64

I've resolved my problem.

The mather was that I tried to define a distance in meter in a WGS84 spatial reference.

Assuming that 1km is aproximatively equals to 0.00901 "degré décimal" (in french) I've done this formula :
buffer.Radius = (bufferSize / 1000) * 0.00901;

And it works !

View solution in original post

0 Kudos
2 Replies
BKuiper
Frequent Contributor
The better approach would be to take the center of your point, apply a buffer on this (in meters) and draw this graphic. You shouldn't be concerned with pixel size, etc.

Open the ArcGIS Runtime Samples application. There is an example called "Buffer" that does exactly what you want.
0 Kudos
by Anonymous User
Not applicable
Original User: nviot64

I've resolved my problem.

The mather was that I tried to define a distance in meter in a WGS84 spatial reference.

Assuming that 1km is aproximatively equals to 0.00901 "degré décimal" (in french) I've done this formula :
buffer.Radius = (bufferSize / 1000) * 0.00901;

And it works !
0 Kudos