Exemplo n.º 1
0
 static void Main(string[] args)
 {
     try {
         {
             // Sample forward calculation from
             // A guide to coordinate systems in Great Britain
             double
                 lat = DMS.Decode(52, 39, 27.2531),
                 lon = DMS.Decode(1, 43, 4.5177);
             double x, y;
             OSGB.Forward(lat, lon, out x, out y);
             string gridref;
             OSGB.GridReference(x, y, 2, out gridref);
             Console.WriteLine(String.Format("{0} {1} {2}", x, y, gridref));
         }
         {
             // Sample reverse calculation
             string gridref = "TG5113";
             double x, y;
             int    prec;
             OSGB.GridReference(gridref, out x, out y, out prec, true);
             double lat, lon;
             OSGB.Reverse(x, y, out lat, out lon);
             Console.WriteLine(String.Format("{0} {1} {2}", prec, lat, lon));
         }
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
Exemplo n.º 2
0
 private void OnValidate(object sender, EventArgs e)
 {
     try
     {
         double   lat, lon, d, m, s;
         DMS.Flag ind;
         int      len;
         string   tmp;
         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);
         GARS.Forward(32.0, -86.0, 2, out tmp);
         GARS.Reverse("189LE37", out lat, out lon, out len, true);
         Georef.Forward(32.0, -86.0, 2, out tmp);
         Georef.Reverse("GJEC0000", 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);
     }
 }
Exemplo n.º 3
0
        public void TestDecode(double lat, double lon, string dms)
        {
            var components = dms.Split(' ');

            var(latVal, lonVal) = DMS.Decode(components[0], components[1]);
            Assert.AreEqual(lat, latVal, 0.001);
            Assert.AreEqual(lon, lonVal, 0.001);
        }
Exemplo n.º 4
0
 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);
     }
 }
Exemplo n.º 5
0
 static void Main(string[] args)
 {
     try {
         {
             string   dms = "30d14'45.6\"S";
             DMS.Flag type;
             double   ang = DMS.Decode(dms, out type);
             Console.WriteLine(String.Format("Type: {0} String: {1}", type, ang));
         }
         {
             double ang = -30.245715;
             string dms = DMS.Encode(ang, 6, DMS.Flag.LATITUDE, 0);
             Console.WriteLine(String.Format("Latitude: {0}", dms));
         }
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }