File: PolyPanel.cs

package info (click to toggle)
geographiclib 1.37-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,688 kB
  • ctags: 4,871
  • sloc: cpp: 31,440; sh: 11,632; cs: 9,411; ansic: 1,428; java: 1,333; python: 1,131; makefile: 758; xml: 381; pascal: 30
file content (139 lines) | stat: -rw-r--r-- 5,560 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
 * \file NETGeographicLib\PolyPanel.cs
 * \brief NETGeographicLib.PolygonArea example
 *
 * NETGeographicLib is copyright (c) Scott Heiman (2013)
 * GeographicLib is Copyright (c) Charles Karney (2010-2012)
 * <charles@karney.com> and licensed under the MIT/X11 License.
 * For more information, see
 * http://geographiclib.sourceforge.net/
 **********************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NETGeographicLib;

namespace Projections
{
    public partial class PolyPanel : UserControl
    {
        PolygonArea m_poly = null;
        public PolyPanel()
        {
            InitializeComponent();
            m_poly = new PolygonArea(false);
            m_majorRadiusTextBox.Text = m_poly.MajorRadius.ToString();
            m_flatteningTextBox.Text = m_poly.Flattening.ToString();
            m_lengthTextBox.Text = m_areaTextBox.Text = m_numPointsTextBox.Text = "0";
            m_currLatTextBox.Text = m_currLonTextBox.Text = "";
        }

        private void OnSet(object sender, EventArgs e)
        {
            try
            {
                double a = Double.Parse(m_majorRadiusTextBox.Text);
                double f = Double.Parse(m_flatteningTextBox.Text);
                m_poly = new PolygonArea(new Geodesic(a, f), m_polylineCheckBox.Checked);
                m_lengthTextBox.Text = m_areaTextBox.Text = m_numPointsTextBox.Text = "0";
                m_currLatTextBox.Text = m_currLonTextBox.Text = "";
                m_edgeButton.Enabled = false;
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OnAddPoint(object sender, EventArgs e)
        {
            try
            {
                double lat = Double.Parse(m_latitudeTextBox.Text);
                double lon = Double.Parse(m_longitudeTextBox.Text);
                double length, area;

                m_poly.AddPoint(lat, lon);
                m_edgeButton.Enabled = true;
                m_currLatTextBox.Text = m_latitudeTextBox.Text;
                m_currLonTextBox.Text = m_longitudeTextBox.Text;
                m_numPointsTextBox.Text = m_poly.Compute(false, false, out length, out area).ToString();
                m_lengthTextBox.Text = length.ToString();
                if ( !m_polylineCheckBox.Checked )
                    m_areaTextBox.Text = area.ToString();
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OnAddEdge(object sender, EventArgs e)
        {
            try
            {
                double azi = Double.Parse(m_azimuthTextBox.Text);
                double dist = Double.Parse(m_distanceTextBox.Text);

                m_poly.AddEdge(azi, dist);
                double lat, lon, length, area;
                m_poly.CurrentPoint(out lat, out lon);
                m_currLatTextBox.Text = lat.ToString();
                m_currLonTextBox.Text = lon.ToString();
                m_numPointsTextBox.Text = m_poly.Compute(false, false, out length, out area).ToString();
                m_lengthTextBox.Text = length.ToString();
                if (!m_polylineCheckBox.Checked)
                    m_areaTextBox.Text = area.ToString();
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OnClear(object sender, EventArgs e)
        {
            m_poly.Clear();
            m_edgeButton.Enabled = false;
            m_lengthTextBox.Text = m_areaTextBox.Text = m_numPointsTextBox.Text = "0";
            m_currLatTextBox.Text = m_currLonTextBox.Text = "";
        }

        private void OnValidate(object sender, EventArgs e)
        {
            try
            {
                double lat, lon, perim, area;
                PolygonArea pa = new PolygonArea(new Geodesic(50000.0, 0.001), true);
                pa = new PolygonArea(false);
                pa.AddPoint(32.0, -86.0);
                pa.AddEdge(20.0, 10000.0);
                pa.AddEdge(-45.0, 10000.0);
                pa.CurrentPoint(out lat, out lon);
                pa.Compute(false, false, out perim, out area);
                pa.TestEdge(-70.0, 5000.0, false, false, out perim, out area);
                pa.TestPoint(31.0, -86.5, false, false, out perim, out area);

                PolygonAreaExact p2 = new PolygonAreaExact(new GeodesicExact(), false);
                p2.AddPoint(32.0, -86.0);
                p2.AddEdge(20.0, 10000.0);
                p2.AddEdge(-45.0, 10000.0);
                p2.CurrentPoint(out lat, out lon);
                p2.Compute(false, false, out perim, out area);
                p2.TestEdge(-70.0, 5000.0, false, false, out perim, out area);
                p2.TestPoint(31.0, -86.5, false, false, out perim, out area);

                MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}