MapwinGIS:SampleCode-C Sharp Net:SimpleSpatiallyReferencedCircles

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

Simpler Example of Spatially Referenced Circles

The previous example had some confusing extra stuff like converting from lat lon into miles or whatever. This, however, is a bare bones model that will work fine if you are in a local or state plane projection where the radius should be in the same units as the measurements without any transformations.

         MapWinGIS.tkCursor OldCursor;
         MapWinGIS.tkCursorMode OldCursorMode;
         bool AddingCircle;
         List<Circle> Circles;
         struct Circle
             public double X;
             public double Y;
             public double Rad;
         // During initialization this sets some basic default parameters
         public Form1()
             Circles = new List<Circle>();
             // Activate the Mouse Up event so that you can receive mouse messages
             axMap1.SendMouseUp = true;
             // Set up a drawing layer where our circles will end up.
             // obviously for circles it is only partially spatially referenced.
         // This command switches the cursor for a one time addition of a referenced circle
         private void addCircleToolStripMenuItem1_Click(object sender, EventArgs e)
             // axMap1 is the activeX map object for the project
             OldCursor = axMap1.MapCursor;
             OldCursorMode = axMap1.CursorMode;
             axMap1.CursorMode = MapWinGIS.tkCursorMode.cmNone;
             axMap1.MapCursor = MapWinGIS.tkCursor.crsrCross;
             AddingCircle = true;
         // Add a new circle to the list
         void axMap1_MouseUpEvent(object sender, AxMapWinGIS._DMapEvents_MouseUpEvent e)
             // Convert screen click coordinates to map coordinates
             if (AddingCircle == false) return;
             AddingCircle = false;
             axMap1.CursorMode = OldCursorMode;
             axMap1.MapCursor = OldCursor;
             double X = 0;
             double Y = 0;
             axMap1.PixelToProj(e.x, e.y, ref X, ref Y);
             Circle myCircle;
             myCircle.X = X;
             myCircle.Y = Y;
             // Read the radius from a textbox
             myCircle.Rad = double.Parse(tbRadius.Text);
             // For this example I will just update the whole list
         // Actually take the list of circles and draw them on the screen
         private void DrawCircles()
             double X = 0;
             double X2 = 0;
             double Y = 0;
             double ScreenRadius = 0;
             Circle myCircle;
             // Set the color based on RGB value
             int Red = 255;
             int Green = 0;
             int Blue = 0;
             uint Color = (uint)(Blue * 256 * 256 + Green * 256 + Red);
             // Erase the old circles
             // Add new circles that are in the correct locations
             for (int I = 0; I < Circles.Count; I++)
                 // Get a single instance from the list of circles
                 myCircle = Circles[I];
                 // Find the equivalent screen pixel value for the radius
                 axMap1.ProjToPixel(myCircle.X, myCircle.Y, ref X, ref Y);
                 axMap1.ProjToPixel(myCircle.X + myCircle.Rad, myCircle.Y, ref X2, ref Y);
                 ScreenRadius = Math.Abs(X2 - X);
                 // Actually draw the circle
                 axMap1.DrawCircle(myCircle.X, myCircle.Y, ScreenRadius, Color, false);
         // When the extents change, we need different circles
         void axMap1_ExtentsChanged(object sender, System.EventArgs e)

Posted by Shade1974 5/9/2007

Retrieved from ""

This page has been accessed 2,426 times. This page was last modified on 9 May 2007, at 17:50.