Exemplo n.º 1
0
 private void OnValidate(object sender, EventArgs e)
 {
     try
     {
         double             lat, lon, x, y, x1, y1, gamma, k;
         PolarStereographic p = new PolarStereographic(m_polar.EquatorialRadius, m_polar.Flattening, m_polar.CentralScale);
         p.SetScale(60.0, 1.0);
         p = new PolarStereographic();
         p.Forward(true, 32.0, -86.0, out x, out y, out gamma, out k);
         p.Forward(true, 32.0, -86.0, out x1, out y1);
         if (x != x1 || y != y1)
         {
             throw new Exception("Error in Forward");
         }
         p.Reverse(true, x, y, out lat, out lon, out gamma, out k);
         p.Reverse(true, x, y, out x1, out y1);
         if (lat != x1 || lon != y1)
         {
             throw new Exception("Error in Reverse");
         }
     }
     catch (Exception xcpt)
     {
         MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     MessageBox.Show("No errors detected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Exemplo n.º 2
0
        public void Test(string geoResourceName, string prjResourceName, double projectDelta, double unprojectDelta)
        {
            var latLonData = GoldData.GetReadyReader(geoResourceName);
            var prjData    = GoldData.GetReadyReader(prjResourceName);

            var spheroid = GoldData.GenerateSpheroid(prjData["DATUM"]);
            PolarStereographic projection;

            if (null != prjData["SCALE FACTOR"])
            {
                projection = new PolarStereographic(
                    new GeographicCoordinate(
                        Math.PI / 2.0,
                        Double.Parse(prjData["LONGITUDE DOWN FROM POLE"]) * Math.PI / 180.0
                        ),
                    Double.Parse(prjData["SCALE FACTOR"]),
                    new Vector2(
                        Double.Parse(prjData["FALSE EASTING"]),
                        Double.Parse(prjData["FALSE NORTHING"])
                        ),
                    spheroid
                    );
            }
            else
            {
                var latSp     = Double.Parse(prjData["LATITUDE OF TRUE SCALE"]) * Math.PI / 180.0;
                var originLat = latSp < 0 ? -Math.PI / 2.0 : Math.PI / 2.0;
                projection = PolarStereographic.CreateFromStandardParallel(
                    new GeographicCoordinate(
                        originLat,
                        Double.Parse(prjData["LONGITUDE DOWN FROM POLE"]) * Math.PI / 180.0
                        ),
                    latSp,
                    new Vector2(
                        Double.Parse(prjData["FALSE EASTING"]),
                        Double.Parse(prjData["FALSE NORTHING"])
                        ),
                    spheroid
                    );
            }

            var inverse = projection.GetInverse();

            while (latLonData.Read() && prjData.Read())
            {
                var coord     = latLonData.CurrentLatLon();
                var coordRads = latLonData.CurrentLatLonRadians();
                var expected  = prjData.CurrentPoint2D();

                var projected = projection.TransformValue(coordRads);
                Assert.AreEqual(expected.X, projected.X, projectDelta);
                Assert.AreEqual(expected.Y, projected.Y, projectDelta);

                var unProjected = inverse.TransformValue(expected);
                unProjected = new GeographicCoordinate(unProjected.Latitude * 180.0 / Math.PI, unProjected.Longitude * 180.0 / Math.PI);
                Assert.AreEqual(coord.Latitude, unProjected.Latitude, unprojectDelta);
                Assert.AreEqual(coord.Longitude, unProjected.Longitude, unprojectDelta);
            }
        }
Exemplo n.º 3
0
        public void Test(string geoResourceName, string prjResourceName, double projectDelta, double unprojectDelta)
        {
            var latLonData = GoldData.GetReadyReader(geoResourceName);
            var prjData = GoldData.GetReadyReader(prjResourceName);

            var spheroid = GoldData.GenerateSpheroid(prjData["DATUM"]);
            PolarStereographic projection;
            if (null != prjData["SCALE FACTOR"]) {
                projection = new PolarStereographic(
                    new GeographicCoordinate(
                        Math.PI / 2.0,
                        Double.Parse(prjData["LONGITUDE DOWN FROM POLE"]) * Math.PI / 180.0
                    ),
                    Double.Parse(prjData["SCALE FACTOR"]),
                    new Vector2(
                        Double.Parse(prjData["FALSE EASTING"]),
                        Double.Parse(prjData["FALSE NORTHING"])
                    ),
                    spheroid
                );
            }
            else {
                var latSp = Double.Parse(prjData["LATITUDE OF TRUE SCALE"]) * Math.PI / 180.0;
                var originLat = latSp < 0 ? -Math.PI / 2.0 : Math.PI / 2.0;
                projection = PolarStereographic.CreateFromStandardParallel(
                    new GeographicCoordinate(
                        originLat,
                        Double.Parse(prjData["LONGITUDE DOWN FROM POLE"]) * Math.PI / 180.0
                    ),
                    latSp,
                    new Vector2(
                        Double.Parse(prjData["FALSE EASTING"]),
                        Double.Parse(prjData["FALSE NORTHING"])
                    ),
                    spheroid
                );
            }

            var inverse = projection.GetInverse();

            while (latLonData.Read() && prjData.Read()) {
                var coord = latLonData.CurrentLatLon();
                var coordRads = latLonData.CurrentLatLonRadians();
                var expected = prjData.CurrentPoint2D();

                var projected = projection.TransformValue(coordRads);
                Assert.AreEqual(expected.X, projected.X, projectDelta);
                Assert.AreEqual(expected.Y, projected.Y, projectDelta);

                var unProjected = inverse.TransformValue(expected);
                unProjected = new GeographicCoordinate(unProjected.Latitude * 180.0 / Math.PI, unProjected.Longitude * 180.0 / Math.PI);
                Assert.AreEqual(coord.Latitude, unProjected.Latitude, unprojectDelta);
                Assert.AreEqual(coord.Longitude, unProjected.Longitude, unprojectDelta);
            }
        }
Exemplo n.º 4
0
 private void OnSet(object sender, EventArgs e)
 {
     try
     {
         double a = Double.Parse(m_majorRadiusTextBox.Text);
         double f = Double.Parse(m_flatteningTextBox.Text);
         double k = Double.Parse(m_scaleTextBox.Text);
         m_polar = new PolarStereographic(a, f, k);
     }
     catch (Exception xcpt)
     {
         MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 5
0
        public void EpsgExample_1_3_7_2_A_Inverse()
        {
            var projection = new PolarStereographic(
                new GeographicCoordinate(1.570796327, 0),
                0.994,
                new Vector2(2000000.00, 2000000.00),
                new SpheroidEquatorialInvF(6378137, 298.2572236)
            );
            var expected = new GeographicCoordinate(1.274090354, 0.767944871);
            var input = new Point2(3320416.75, 632668.43);

            var result = projection.GetInverse().TransformValue(input);

            Assert.AreEqual(expected.Latitude, result.Latitude, 0.0000000005);
            Assert.AreEqual(expected.Longitude, result.Longitude, 0.000000001);
        }
Exemplo n.º 6
0
 public PolarStereoPanel()
 {
     InitializeComponent();
     try
     {
         m_polar = new PolarStereographic();
     }
     catch (Exception xcpt)
     {
         MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     m_majorRadiusTextBox.Text        = m_polar.EquatorialRadius.ToString();
     m_flatteningTextBox.Text         = m_polar.Flattening.ToString();
     m_scaleTextBox.Text              = m_polar.CentralScale.ToString();
     m_functionComboBox.SelectedIndex = 0;
 }
Exemplo n.º 7
0
 public PolarStereoPanel()
 {
     InitializeComponent();
     try
     {
         m_polar = new PolarStereographic();
     }
     catch (Exception xcpt)
     {
         MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     m_majorRadiusTextBox.Text = m_polar.MajorRadius.ToString();
     m_flatteningTextBox.Text = m_polar.Flattening.ToString();
     m_scaleTextBox.Text = m_polar.CentralScale.ToString();
     m_functionComboBox.SelectedIndex = 0;
 }
Exemplo n.º 8
0
        public void EpsgExample_1_3_7_2_B()
        {
            var projection = PolarStereographic.CreateFromStandardParallel(
                1.221730476,
                -1.239183769,
                new Vector2(6000000.00, 6000000.00),
                new SpheroidEquatorialInvF(6378137, 298.2572236)
                );
            var input    = new GeographicCoordinate(-1.308996939, 2.094395102);
            var expected = new Point2(7255380.79, 7053389.56);

            var result = projection.TransformValue(input);

            Assert.AreEqual(expected.X, result.X, 0.004);
            Assert.AreEqual(expected.Y, result.Y, 0.001);
        }
Exemplo n.º 9
0
        public void EpsgExample_1_3_7_2_A_Inverse()
        {
            var projection = new PolarStereographic(
                new GeographicCoordinate(1.570796327, 0),
                0.994,
                new Vector2(2000000.00, 2000000.00),
                new SpheroidEquatorialInvF(6378137, 298.2572236)
                );
            var expected = new GeographicCoordinate(1.274090354, 0.767944871);
            var input    = new Point2(3320416.75, 632668.43);

            var result = projection.GetInverse().TransformValue(input);

            Assert.AreEqual(expected.Latitude, result.Latitude, 0.0000000005);
            Assert.AreEqual(expected.Longitude, result.Longitude, 0.000000001);
        }
Exemplo n.º 10
0
        public void EpsgExample_1_3_7_2_C_Inverse()
        {
            var projection = PolarStereographic.CreateFromStandardParallelAndFalseOffsetAtOrigin(
                2.443460953,
                -1.169370599,
                new Vector2(300000.00, 200000.00),
                new SpheroidEquatorialInvF(6378388, 297)
                );
            var expected = new GeographicCoordinate(-1.162480524, 2.444707118);
            var input    = new Point2(303169.52, 244055.72);

            var result = projection.GetInverse().TransformValue(input);

            Assert.AreEqual(expected.Latitude, result.Latitude, 0.000000000002);
            Assert.AreEqual(expected.Longitude, result.Longitude, 0.0000000007);
        }
Exemplo n.º 11
0
 static void Main(string[] args)
 {
     try {
         PolarStereographic proj = new PolarStereographic(); // WGS84
         bool northp             = true;
         {
             // Sample forward calculation
             double lat = 61.2, lon = -149.9; // Anchorage
             double x, y;
             proj.Forward(northp, lat, lon, out x, out y);
             Console.WriteLine(String.Format("{0} {1}", x, y));
         }
         {
             // Sample reverse calculation
             double x = -1637e3, y = 2824e3;
             double lat, lon;
             proj.Reverse(northp, x, y, out lat, out lon);
             Console.WriteLine(String.Format("{0} {1}", lat, lon));
         }
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
Exemplo n.º 12
0
 static void Main(string[] args)
 {
     try {
         PolarStereographic proj = new PolarStereographic(); // WGS84
         bool northp = true;
         {
             // Sample forward calculation
             double lat = 61.2, lon = -149.9; // Anchorage
             double x, y;
             proj.Forward(northp, lat, lon, out x, out y);
             Console.WriteLine(String.Format("{0} {1}", x, y));
         }
         {
             // Sample reverse calculation
             double x = -1637e3, y = 2824e3;
             double lat, lon;
             proj.Reverse(northp, x, y, out lat, out lon);
             Console.WriteLine(String.Format("{0} {1}", lat, lon));
         }
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
Exemplo n.º 13
0
 private void OnValidate(object sender, EventArgs e)
 {
     try
     {
         double lat, lon, x, y, x1, y1, gamma, k;
         PolarStereographic p = new PolarStereographic(m_polar.MajorRadius, m_polar.Flattening, m_polar.CentralScale);
         p.SetScale(60.0, 1.0);
         p = new PolarStereographic();
         p.Forward(true, 32.0, -86.0, out x, out y, out gamma, out k);
         p.Forward(true, 32.0, -86.0, out x1, out y1);
         if (x != x1 || y != y1)
             throw new Exception("Error in Forward");
         p.Reverse(true, x, y, out lat, out lon, out gamma, out k);
         p.Reverse(true, x, y, out x1, out y1);
         if ( lat != x1 || lon != y1 )
             throw new Exception("Error in Reverse");
     }
     catch (Exception xcpt)
     {
         MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     MessageBox.Show("No errors detected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Exemplo n.º 14
0
 private void OnSet(object sender, EventArgs e)
 {
     try
     {
         double a = Double.Parse(m_majorRadiusTextBox.Text);
         double f = Double.Parse(m_flatteningTextBox.Text);
         double k = Double.Parse(m_scaleTextBox.Text);
         m_polar = new PolarStereographic(a, f, k);
     }
     catch (Exception xcpt)
     {
         MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }