example-Georef.cs 1.35 KB
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
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
using System;
using NETGeographicLib;

namespace example_Georef
{
  class Program
  {
    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));
      }
    }
  }
}