File: MiscPanel.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 (118 lines) | stat: -rw-r--r-- 4,521 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
/**
 * \file NETGeographicLib\MiscPanel.cs
 * \brief NETGeographicLib.DMS and NETGeographicLib.Geohash 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 MiscPanel : UserControl
    {
        public MiscPanel()
        {
            InitializeComponent();
        }

        private void OnConvertDMS(object sender, EventArgs e)
        {
            try
            {
                DMS.Flag ind;
                double lon = DMS.Decode(m_longitudeDMSTextBox.Text, out ind);
                m_LongitudeTextBox.Text = lon.ToString();
                double lat = DMS.Decode(m_latitudeDMSTextBox.Text, out ind);
                m_latitudeTextBox.Text = lat.ToString();
                string tmp = "";
                Geohash.Forward(lat, lon, 12, out tmp);
                m_geohashTextBox.Text = tmp;
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OnConvert(object sender, EventArgs e)
        {
            try
            {
                double lon = Double.Parse(m_LongitudeTextBox.Text);
                double lat = Double.Parse(m_latitudeTextBox.Text);
                m_longitudeDMSTextBox.Text = DMS.Encode(lon, 5, DMS.Flag.LONGITUDE, 0);
                m_latitudeDMSTextBox.Text = DMS.Encode(lat, 5, DMS.Flag.LATITUDE, 0);
                string tmp = "";
                Geohash.Forward(lat, lon, 12, out tmp);
                m_geohashTextBox.Text = tmp;
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OnConvertGeohash(object sender, EventArgs e)
        {
            try
            {
                double lat, lon;
                int len;
                Geohash.Reverse(m_geohashTextBox.Text, out lat, out lon, out len, true);
                m_LongitudeTextBox.Text = lon.ToString();
                m_latitudeTextBox.Text = lat.ToString();
                m_longitudeDMSTextBox.Text = DMS.Encode(lon, 5, DMS.Flag.LONGITUDE, 0);
                m_latitudeDMSTextBox.Text = DMS.Encode(lat, 5, DMS.Flag.LATITUDE, 0);
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OnValidate(object sender, EventArgs e)
        {
            try
            {
                double lat, lon, d, m, s;
                DMS.Flag ind;
                int len;
                string tmp;
                DMS.Decode("34.245");
                DMS.Decode("34d22\'34.567\"", out ind);
                DMS.Decode(-86.0, 32.0, 34.214);
                DMS.DecodeAngle("-67.4532");
                DMS.DecodeAzimuth("85.3245W");
                DMS.DecodeLatLon("86d34\'24.5621\"", "21d56\'32.1234\"", out lat, out lon, false);
                DMS.Encode(-86.453214, out d, out m);
                DMS.Encode(-86.453214, out d, out m, out s);
                DMS.Encode(-86.453214, DMS.Component.SECOND, 12, DMS.Flag.LONGITUDE, 0);
                DMS.Encode(-86.453214, 12, DMS.Flag.LONGITUDE, 0);
                Geohash.DecimalPrecision(12);
                Geohash.Forward(31.23456, -86.43678, 12, out tmp);
                Geohash.GeohashLength(0.001);
                Geohash.GeohashLength(0.002, 0.003);
                Geohash.LatitudeResolution(12);
                Geohash.LongitudeResolution(12);
                Geohash.Reverse("djds54mrfc0g", out lat, out lon, out len, true);
                MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception xcpt)
            {
                MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}