Exemple #1
0
        private void btnTest_Click(object sender, RoutedEventArgs e)
        {
            Reframe objReframe = new Reframe();

            double east   = Double.Parse(txtE.Text);
            double north  = Double.Parse(txtN.Text);
            double height = Double.Parse(txtH.Text);

            try
            {
                bool outsideChenyx06 = !objReframe.ComputeReframe(ref east, ref north, ref height,
                                                                  Reframe.PlanimetricFrame.LV03_Military, Reframe.PlanimetricFrame.LV95, Reframe.AltimetricFrame.LN02, Reframe.AltimetricFrame.LHN95);

                txtEOut.Text = east.ToString("0.000");
                txtNOut.Text = north.ToString("0.000");
                txtHOut.Text = height.ToString("0.000");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                // Input cooridnates are outsie HTRANS/CHGEO2004 perimeter (Swiss TLM) and the height transformation cannot be computed!
                MessageBox.Show("REFRAME error: " + ex.Message);
            }
            catch (Exception)
            {
                // Other error e.g. transformation's dataset file not found (swisstopo.data.dll)
                MessageBox.Show("REFRAME internal error, please reinstall application.");
            }
        }
        public static SwissGridLocation ToSwissGrid(this Wgs84Location wgs84)
        {
            Reframe reframe = new Reframe();

            double height    = 555;
            double longitude = wgs84.Longitude;
            double latitude  = wgs84.Latitude;

            try
            {
                reframe.ComputeGpsref(ref longitude, ref latitude, ref height, Reframe.ProjectionChange.ETRF93GeographicToLV95);
                bool outsideSwitzerland = reframe.ComputeReframe(ref longitude, ref latitude, ref height, Reframe.PlanimetricFrame.LV95, Reframe.PlanimetricFrame.LV03_Military, Reframe.AltimetricFrame.Ellipsoid, Reframe.AltimetricFrame.LN02);
                return(new SwissGridLocation((int)Math.Round(longitude), (int)Math.Round(latitude)));
            }
            catch (Exception ex)
            {
                return(new SwissGridLocation());
            }
        }
        public static Wgs84Location ToWgs84(this SwissGridLocation sg)
        {
            Reframe reframe = new Reframe();

            double height = 555;
            double x      = sg.X;
            double y      = sg.Y;

            try
            {
                bool outsideSwitzerland = reframe.ComputeReframe(ref x, ref y, ref height, Reframe.PlanimetricFrame.LV03_Military, Reframe.PlanimetricFrame.LV95, Reframe.AltimetricFrame.LN02, Reframe.AltimetricFrame.Ellipsoid);
                reframe.ComputeGpsref(ref x, ref y, ref height, Reframe.ProjectionChange.LV95ToETRF93Geographic);
            }
            catch (Exception ex)
            {
                return(new Wgs84Location());
            }
            return(new Wgs84Location(y, x));
        }
Exemple #4
0
        static void Main(string[] args)
        {
            // Instantiate Reframe object
            Reframe reframeObj = new Reframe();

            // Input point (LV03)
            // Write your code here, e.g. to read a file
            double east = 600100.000, north = 200100.000, height = 500.000;

            try
            {
                // Log
                Console.WriteLine("REFRAME input: E: " + east.ToString("0.000") + " m / N: " + north.ToString("0.000") + " m / H: " + height.ToString("0.000") + " m");

                // Compute Reframe transfromation LV03 (MI)=>LV95 and LN02=>LHN95
                bool outsideChenyx06 = !reframeObj.ComputeReframe(ref east, ref north, ref height,
                                                                  Reframe.PlanimetricFrame.LV03_Military, Reframe.PlanimetricFrame.LV95,
                                                                  Reframe.AltimetricFrame.LN02, Reframe.AltimetricFrame.LHN95);

                if (outsideChenyx06)
                {
                    Console.WriteLine("This point is outside official Swiss TLM perimeter. A translation +2'000'000.0/+1'000'000.0 was applied.");
                }

                // Show message
                Console.WriteLine("REFRAME transformation terminated: E: " + east.ToString("0.000") + " m / N: " + north.ToString("0.000") + " m / H: " + height.ToString("0.000") + " m");
            }
            catch (ArgumentOutOfRangeException e)
            {
                // Input cooridnates are outsie HTRANS/CHGEO2004 perimeter (Swiss TLM) and the height transformation cannot be computed!
                Console.WriteLine("REFRAME error: " + e.Message);
            }
            catch (Exception)
            {
                // Other error e.g. transformation's dataset file not found (swisstopo.data.dll)
                Console.WriteLine("REFRAME internal error, please reinstall application.");
            }

            // Let time to read screen messages
            System.Threading.Thread.Sleep(5000);
        }