ThinkGeo.com    |     Documentation    |     Premium Support

Draw curve line issue

Hi,



    I want to draw curve line. I have from -to point, radius in Nautical mile, center point. I have tried with draw arc sample but it did not work for me. Please suggest how to draw curve line using all these parameters.



Thanks,

Goral

    

Hi Goral, 
  
 I think that’s a little complex.  
  
 1. The hard part is, you should want to calculate a circle based on your parameters. 
  
 2. Then you need to know the start point of the curve and the end point of it. 
  
 3. Loop the outer ring (it’s a line end to end), find your start point and end point, then you can get all vertexes for your curve. Or you can try our GetLineOnALine function on the LineShape class. 
  
 Wish that’s helpful. 
  
 Regards, 
  
 Don

Hi,



   Thanks for reply. Can you please explain GetLineOnLine function in detail or provide some example?



Thanks & Regards,

Goral

Hi Goral,



I think you can create a custom CurvedLineShape which can save to/load from a WKT. Here is a simple example how to do it by creating a new shape from BaseShape. It should work for you.





    // The CurvedLineShape Class
    class CurvedLineShape : BaseShape
    {
        private PointShape centerPoint;
        private PointShape startPoint;
        private double angle;



        public CurvedLineShape()
            : this(new PointShape(0, 0), new PointShape(0, 0), 0)
        { }



        public CurvedLineShape(PointShape centerPoint, PointShape startPoint, int angle)
        {
            this.centerPoint = centerPoint;
            this.startPoint = startPoint;
            this.angle = angle;
        }



        public CurvedLineShape(string wellKnownText)
        {
            if (wellKnownText == null || !wellKnownText.StartsWith(“CurvedLineShape”))
            {
                throw new ArgumentException(“The wellKnownText is not supported”);
            }



            LoadFromCustomWellKnownData(wellKnownText);
        }



        protected override string GetWellKnownTextCore()
        {
            LineShape line = new LineShape();
            line.Vertices.Add(new Vertex(startPoint));



            double radius = Math.Sqrt(Math.Pow(startPoint.X - centerPoint.X, 2) + Math.Pow(startPoint.Y - centerPoint.Y, 2));
            double startAngle = Math.Asin(startPoint.Y / radius);



            for (int i = 1; i <= angle; i++)
            {
                double x = Math.Cos(Math.PI / 180 * i + startAngle) * radius + centerPoint.X;
                double y = Math.Sin(Math.PI / 180 * i + startAngle) * radius + centerPoint.Y;



                line.Vertices.Add(new Vertex(x, y));
            }



            return line.GetWellKnownText();
        }



        public string GetCustomWellKnownText()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(“CurvedLineShape(”);
            sb.Append(centerPoint.X + " " + centerPoint.Y);
            sb.Append(",");
            sb.Append(startPoint.X + " " + startPoint.Y);
            sb.Append(",");
            sb.Append(angle);
            sb.Append(")");



            return sb.ToString();
        }



        public void LoadFromCustomWellKnownData(string wellKnownText)
        {
            string wkt = wellKnownText.Replace(“CurvedLineShape(”, “”);
            wkt = wkt.Remove(wkt.Length - 1);
            string[] wkts = wkt.Split(’,’);



            string[] data = wkts[0].Split(’ ‘);
            this.centerPoint = new PointShape(Double.Parse(data[0]), Double.Parse(data[1]));



            data = wkts[1].Split(’ ');
            this.startPoint = new PointShape(Double.Parse(data[0]), Double.Parse(data[1]));



            this.angle = Double.Parse(wkts[2]);
        }



        protected override void LoadFromWellKnownDataCore(string wellKnownText)
        {
        }
    }



        // The references. 
        private void WpfMap_Loaded(object sender, RoutedEventArgs e)
        {
            InMemoryFeatureLayer inm = new InMemoryFeatureLayer();
            inm.InternalFeatures.Add(new CurvedLineShape(“CurvedLineShape(0 0,10 10, 90)”).GetFeature());
            inm.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Canal1;
            inm.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;



            LayerOverlay overlay = new LayerOverlay();
            overlay.Layers.Add(inm);
            Map1.MapUnit = GeographyUnit.DecimalDegree;
            Map1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9);
            Map1.Overlays.Add(overlay);
            Map1.Refresh();
        }


Here is what looks like:







Thanks,

Johnny

Hi,

  

    Given curveline shape example throw below error.



     Error : ‘test.CurvedLineShape’ does not implement inherited abstract member 'ThinkGeo.MapSuite.Core.BaseShape.GetWellKnownTextCore(ThinkGeo.MapSuite.Core.RingOrder)



 

   Please throw light on problem.





Thanks,

Goral




Hi Goral,



Please change the method in attached code shown as following:



  protected override string GetWellKnownTextCore()



to 

 protected abstract string GetWellKnownTextCore(RingOrder outerRingOrder)



instead, because the code I pasted before is based on the old version.



Thanks,

Johnny


Hi,



     Thanks for reply. I have tried to change accordingly but it is throwing some other errors. Is it issue of version? 



Thanks,

Goral

Hi Goral, 
  
 This code as below should works for the latest version. 
  
  

// The CurvedLineShape Class
        class CurvedLineShape : BaseShape
        {
            private PointShape centerPoint;
            private PointShape startPoint;
            private double angle;

            public CurvedLineShape()
                : this(new PointShape(0, 0), new PointShape(0, 0), 0)
            { }

            public CurvedLineShape(PointShape centerPoint, PointShape startPoint, int angle)
            {
                this.centerPoint = centerPoint;
                this.startPoint = startPoint;
                this.angle = angle;
            }

            public CurvedLineShape(string wellKnownText)
            {
                if (wellKnownText == null || !wellKnownText.StartsWith(“CurvedLineShape”))
                {
                    throw new ArgumentException(“The wellKnownText is not supported”);
                }

                LoadFromCustomWellKnownData(wellKnownText);
            }

            protected override string GetWellKnownTextCore(RingOrder outerRingOrder)
            {
                LineShape line = new LineShape();
                line.Vertices.Add(new Vertex(startPoint));

                double radius = Math.Sqrt(Math.Pow(startPoint.X - centerPoint.X, 2) + Math.Pow(startPoint.Y - centerPoint.Y, 2));
                double startAngle = Math.Asin(startPoint.Y / radius);

                for (int i = 1; i <= angle; i++)
                {
                    double x = Math.Cos(Math.PI / 180 * i + startAngle) * radius + centerPoint.X;
                    double y = Math.Sin(Math.PI / 180 * i + startAngle) * radius + centerPoint.Y;

                    line.Vertices.Add(new Vertex(x, y));
                }

                return line.GetWellKnownText();
            }

            public string GetCustomWellKnownText()
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(“CurvedLineShape(”);
                sb.Append(centerPoint.X + " " + centerPoint.Y);
                sb.Append(",");
                sb.Append(startPoint.X + " " + startPoint.Y);
                sb.Append(",");
                sb.Append(angle);
                sb.Append(")");

                return sb.ToString();
            }

            public void LoadFromCustomWellKnownData(string wellKnownText)
            {
                string wkt = wellKnownText.Replace(“CurvedLineShape(”, “”);
                wkt = wkt.Remove(wkt.Length - 1);
                string[] wkts = wkt.Split(’,’);

                string[] data = wkts[0].Split(’ ‘);
                this.centerPoint = new PointShape(Double.Parse(data[0]), Double.Parse(data[1]));

                data = wkts[1].Split(’ ');
                this.startPoint = new PointShape(Double.Parse(data[0]), Double.Parse(data[1]));

                this.angle = Double.Parse(wkts[2]);
            }

            protected override void LoadFromWellKnownDataCore(string wellKnownText)
            {

            }
        }

        private void DisplayMap_Load(object sender, EventArgs e)
        {
            InMemoryFeatureLayer inm = new InMemoryFeatureLayer();

            CurvedLineShape lineShape = new CurvedLineShape(“CurvedLineShape(0 0,10 10, 90)”);
            string wktString = lineShape.GetWellKnownText();

            BaseShape tmpBaseShape = BaseShape.CreateShapeFromWellKnownData(wktString);
            Feature f = new Feature(tmpBaseShape);
            inm.InternalFeatures.Add(f);
            inm.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Canal1;
            inm.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            LayerOverlay overlay = new LayerOverlay();
            overlay.Layers.Add(inm);
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9);
            winformsMap1.Overlays.Add(overlay);
            winformsMap1.Refresh();
        }
 
  
 Regards, 
  
 Don

Hi,



   Thanks for reply. I have implemented new code suggested in previous reply. It is also giving below error.



   Error ‘test.CurvedLineShape’ does not implement inherited abstract member ‘ThinkGeo.MapSuite.Core.BaseShape.GetWellKnownTextCore()’



Thanks,

Goral




Hi Goral, 
  
 What’s the version you are using? 
  
 I am test with the latest version and it works well. 
  
 Could you please download the latest version for test? 
  
 Regards, 
  
 Don

Hi,



   Thanks for reply. Ya given code is  working with version 8. If as per my requirement I am changing angle and latlon point for some angle and some point its not working. I think need to change some logic in the code.



Thanks,

Goral

Hi Goral, 
  
 Do you meant when you set different centerPoint, startPoint and angle this code cannot draw correct new curve or you think the three parameters is not so well for your requirement? 
  
 Regards, 
  
 Don 
  


HI,



  Thanks for reply. Ya I am finding workaround for my requirement. For that I have tried to input different lat long point with different angles. In that it draws for some combination. When I debug and checked I found for some combination function is not able to find startangle and its returning Nan is vertices.



Thanks,

Goral

Hi Goral, 
  
 The mainly logic is in the function GetWellKnownTextCore as below: 
  
 double radius = Math.Sqrt(Math.Pow(startPoint.X - centerPoint.X, 2) + Math.Pow(startPoint.Y - centerPoint.Y, 2)); 
 double startAngle = Math.Asin(startPoint.Y / radius); 
  
 So I think if you met some special scenario cannot be handled correct, you can add new logic here for handle them. 
  
 Regards, 
  
 Don

Hi,



   Thanks for reply. Ok it will helpful.



Thanks,

Goral

Hi Goral, 
  
 I am glad to hear that’s helpful for you. 
  
 Regards, 
  
 Don