Circular arc

Topics: Algorithms, CompactFramework, Data Access, Español, General Topics, Italiano, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, Web Controls, WinForms Controls
Aug 8, 2012 at 10:09 AM

Hi

i am new to sharpmap.I want to draw circular arc on a map file..how to do it?

pleae help me...

Aug 14, 2012 at 8:40 PM

Howdy,

SharpMap does not do arcs. You must approximate with line segments.

1) capture the startpoint and mouse point/position in the mousedown event

2) in the paint event do something like this:

   // Draw the current ellipse
            System.Drawing.Point pos = mapBox1.PointToClient(Control.MousePosition);
            using (Pen pen = new Pen(Brushes.Red, 2.0f))
            {
                Rectangle r =  GenerateDrawingRectangle(new System.Drawing.Point(SelectionGeometry_Startlocation.X,SelectionGeometry_Startlocation.Y)
                                                        ,new System.Drawing.Point(pos.X, pos.Y));
                pen.DashStyle = DashStyle.Dot;
                //Color c = Color.FromArgb(50, 254, 0, 0);
                //Brush b = new SolidBrush(c);
                //pen.Brush = b;
                e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                e.Graphics.DrawEllipse(pen, r);
            }
3) in the mouseup event something like this:
           SharpMap.Geometries.Point end_point = sender as SharpMap.Geometries.Point;
            if (end_point != null)
            {
                SelectionGeometry_Endpoint = end_point;
                SelectionGeometry_Endlocation = e.Location;
            }
            mapBox1.MouseDown -= new SharpMap.Forms.MapBox.MouseEventHandler(CMFormCircle_MouseDown);
            mapBox1.MouseUp -= new SharpMap.Forms.MapBox.MouseEventHandler(CMFormCircle_MouseUp);
            mapBox1.Paint -= new System.Windows.Forms.PaintEventHandler(CMFormCircle_Paint);
            SharpMap.Geometries.Point center = new SharpMap.Geometries.Point((SelectionGeometry_Startpoint.X + SelectionGeometry_Endpoint.X) / 2,
                                     (SelectionGeometry_Startpoint.Y + SelectionGeometry_Endpoint.Y) / 2);
            double width = Math.Abs((SelectionGeometry_Endpoint.X - SelectionGeometry_Startpoint.X) /2.0D);
            double height = Math.Abs((SelectionGeometry_Endpoint.Y - SelectionGeometry_Startpoint.Y) /2.0D);
            double radius = Math.Min(width, height);
            
            List<SharpMap.Geometries.Point> pl = new List<SharpMap.Geometries.Point>();
            SharpMap.Geometries.LinearRing lr = new SharpMap.Geometries.LinearRing();
            for (double angle = 0; angle < 360; angle += 10.0)
            {
                double radians = Math.PI * angle / 180;
                double x = center.X + radius * Math.Cos(radians);
                double y = center.Y + radius * Math.Sin(radians);
                SharpMap.Geometries.Point p = new SharpMap.Geometries.Point(x, y);
                pl.Add(p);
            }
            if (pl[0] != pl[pl.Count - 1])
                pl.Add(pl[0]);
            lr.Vertices = pl;
            SharpMap.Geometries.Polygon polyC = new SharpMap.Geometries.Polygon(lr);
This is what I do...it is NOT the best solution but it works for me at this point.
Yes, the ellipse approach is really kinda rude but it got me closer than where I was. Also this is for v4.0.30319 of SharpMap.
NOGO using the current release.
r,
dennis