private void OnConvertGeohash(object sender, EventArgs e) { try { double lat = 0.0, lon = 0.0; int len; switch (m_comboBox.SelectedIndex) { case 0: // Geohash Geohash.Reverse(m_geohashTextBox.Text, out lat, out lon, out len, true); break; case 1: // GARS GARS.Reverse(m_geohashTextBox.Text, out lat, out lon, out len, true); break; case 2: // Georef Georef.Reverse(m_geohashTextBox.Text, out lat, out lon, out len, true); break; } 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 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 = ""; switch (m_comboBox.SelectedIndex) { case 0: // Geohash Geohash.Forward(lat, lon, 12, out tmp); break; case 1: // GARS GARS.Forward(lat, lon, 2, out tmp); break; case 2: // Georef Georef.Forward(lat, lon, 2, out tmp); break; } m_geohashTextBox.Text = tmp; } 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("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); } }
public static PointLatLng ParsePointFromString(string pos) { PointLatLng point = new PointLatLng(0, 0); Coordinate c; double lat, lon; int prec; if (Coordinate.TryParse(pos, out c)) { point.Lat = c.Latitude.ToDouble(); point.Lng = c.Longitude.ToDouble(); } else { string[] arr = pos.Split(','); try { Georef.Reverse(pos, out lat, out lon, out prec, true); point.Lat = lat; point.Lng = lon; } catch { point.Lat = Convert.ToDouble(arr[0]); point.Lng = Convert.ToDouble(arr[1]); } } return(point); }
static void Main(string[] args) { try { { // Sample forward calculation double lat = 57.64911, lon = 10.40744; // Jutland string georef; for (int prec = -1; prec <= 11; ++prec) { Georef.Forward(lat, lon, prec, out georef); Console.WriteLine(String.Format("Precision: {0} Georef: {1}", prec, georef)); } } { // Sample reverse calculation string georef = "NKLN2444638946"; double lat, lon; int prec; Georef.Reverse(georef.Substring(0, 2), out lat, out lon, out prec, true); Console.WriteLine(String.Format("Precision: {0} Latitude: {1} Longitude: {2}", prec, lat, lon)); Georef.Reverse(georef.Substring(0, 4), out lat, out lon, out prec, true); Console.WriteLine(String.Format("Precision: {0} Latitude: {1} Longitude: {2}", prec, lat, lon)); Georef.Reverse(georef, out lat, out lon, out prec, true); Console.WriteLine(String.Format("Precision: {0} Latitude: {1} Longitude: {2}", prec, lat, lon)); } } catch (GeographicErr e) { Console.WriteLine(String.Format("Caught Exception {0}", e.Message)); } }
public static string ParsePointToString(PointLatLng point, string scale) { Coordinate c = new Coordinate(point.Lat, point.Lng); if (scale == "Signed Degree") { return(point.Lat.ToString(".000000") + ", " + point.Lng.ToString(".000000")); } else if (scale == "Decimal Degree" || scale == "Lat/Lon d°") { c.FormatOptions.Format = CoordinateFormatType.Decimal_Degree; c.FormatOptions.Display_Leading_Zeros = true; c.FormatOptions.Round = 3; return(c.ToString()); } else if (scale == "Degree Decimal Minute") { c.FormatOptions.Format = CoordinateFormatType.Degree_Decimal_Minutes; c.FormatOptions.Display_Leading_Zeros = true; c.FormatOptions.Round = 3; return(c.ToString()); } else if (scale == "Degree Minute Seconds" || scale == "Lat/Lon dms") { c.FormatOptions.Format = CoordinateFormatType.Degree_Minutes_Seconds; c.FormatOptions.Display_Leading_Zeros = true; c.FormatOptions.Round = 3; return(c.ToString()); } else if (scale == "UTM") { return(c.UTM.ToString()); } else if (scale == "MGRS") { return(c.MGRS.ToString()); } else if (scale == "Cartesian") { return(c.Cartesian.ToString()); } else if (scale == "ECEF") { return(c.ECEF.ToString()); } else if (scale == "GEOREF") { for (int prec = -1; prec <= 5; ++prec) { Georef.Forward(point.Lat, point.Lng, prec, out georef); Console.WriteLine(string.Format("Precision: {0} Georef: {1}", prec, georef)); } //GeoCoordinate s = new GeoCoordinate(point.Lat,point.Lng); return(georef);//s.ToString(); } return(null); }