public void gigs_sample_test() { var projection = new AlbersEqualArea( new GeographicCoordinate(0, 132 * Math.PI / 180.0), -18 * Math.PI / 180.0, -36 * Math.PI / 180.0, new Vector2(0, 0), new SpheroidEquatorialInvF(6378.137 * 1000, 298.2572221)); Assert.That(projection.HasInverse); var inverse = projection.GetInverse(); var expectedGeographic = new GeographicCoordinate(-40 * Math.PI / 180.0, 140 * Math.PI / 180.0); var expectedProjected = new Point2(693250.21, -4395794.49); var actualProjected = projection.TransformValue(expectedGeographic); Assert.AreEqual(expectedProjected.X, actualProjected.X, 0.0008); Assert.AreEqual(expectedProjected.Y, actualProjected.Y, 0.006); var actualGeographic = inverse.TransformValue(expectedProjected); Assert.AreEqual(expectedGeographic.Latitude, actualGeographic.Latitude, 0.000000001); Assert.AreEqual(expectedGeographic.Longitude, actualGeographic.Longitude, 0.0000000003); }
static void Main(string[] args) { try { const double lat1 = 40 + 58 / 60.0, lat2 = 39 + 56 / 60.0, // standard parallels k1 = 1, // scale lon0 = -77 - 45 / 60.0; // Central meridan // Set up basic projection AlbersEqualArea albers = new AlbersEqualArea(Constants.WGS84.MajorRadius, Constants.WGS84.Flattening, lat1, lat2, k1); { // Sample conversion from geodetic to Albers Equal Area double lat = 39.95, lon = -75.17; // Philadelphia double x, y; albers.Forward(lon0, lat, lon, out x, out y); Console.WriteLine(String.Format("X: {0} Y: {1}", x, y)); } { // Sample conversion from Albers Equal Area grid to geodetic double x = 220e3, y = -53e3; double lat, lon; albers.Reverse(lon0, x, y, out lat, out lon); Console.WriteLine(String.Format("Latitude: {0} Longitude: {1}", lat, lon)); } } catch (GeographicErr e) { Console.WriteLine(String.Format("Caught exception: {0}", e.Message)); } }
static void Main(string[] args) { try { const double lat1 = 40 + 58/60.0, lat2 = 39 + 56/60.0, // standard parallels k1 = 1, // scale lon0 = -77 - 45/60.0; // Central meridan // Set up basic projection AlbersEqualArea albers = new AlbersEqualArea( Constants.WGS84.MajorRadius, Constants.WGS84.Flattening, lat1, lat2, k1); { // Sample conversion from geodetic to Albers Equal Area double lat = 39.95, lon = -75.17; // Philadelphia double x, y; albers.Forward(lon0, lat, lon, out x, out y); Console.WriteLine( String.Format("X: {0} Y: {1}", x, y ) ); } { // Sample conversion from Albers Equal Area grid to geodetic double x = 220e3, y = -53e3; double lat, lon; albers.Reverse(lon0, x, y, out lat, out lon); Console.WriteLine( String.Format("Latitude: {0} Longitude: {1}", lat, lon ) ); } } catch (GeographicErr e) { Console.WriteLine( String.Format( "Caught exception: {0}", e.Message ) ); } }
private void SetAlbers() { double s2, s3, s4; double a = Double.Parse(m_majorRadiusTextBox.Text); double f = Double.Parse(m_flatteningTextBox.Text); double k = Double.Parse(m_KTextBox.Text); double s1 = Double.Parse(m_stdLat1TextBox.Text); switch (m_constructorComboBox.SelectedIndex) { case 0: m_albers = new AlbersEqualArea(a, f, s1, k); break; case 1: s2 = Double.Parse(m_stdLat2TextBox.Text); m_albers = new AlbersEqualArea(a, f, s1, s2, k); break; case 2: s2 = Double.Parse(m_stdLat2TextBox.Text); s3 = Double.Parse(m_sinLat2TextBox.Text); s4 = Double.Parse(m_cosLat2TextBox.Text); m_albers = new AlbersEqualArea(a, f, s1, s2, s3, s4, k); break; default: break; } m_centralScaleTextBox.Text = m_albers.CentralScale.ToString(); m_originLatitudeTextBox.Text = m_albers.OriginLatitude.ToString(); }
private void AlbersConstructorChanged() { switch (m_constructorComboBox.SelectedIndex) { case 3: m_albers = new AlbersEqualArea(AlbersEqualArea.StandardTypes.CylindricalEqualArea); break; case 4: m_albers = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaNorth); break; case 5: m_albers = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaSouth); break; default: break; } if (m_constructorComboBox.SelectedIndex > 2) { m_majorRadiusTextBox.Text = m_albers.EquatorialRadius.ToString(); m_flatteningTextBox.Text = m_albers.Flattening.ToString(); m_centralScaleTextBox.Text = m_albers.CentralScale.ToString(); m_originLatitudeTextBox.Text = m_albers.OriginLatitude.ToString(); } }
private void AlbersConstructorChanged() { switch (m_constructorComboBox.SelectedIndex) { case 3: m_albers = new AlbersEqualArea(AlbersEqualArea.StandardTypes.CylindricalEqualArea); break; case 4: m_albers = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaNorth); break; case 5: m_albers = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaSouth); break; default: break; } if (m_constructorComboBox.SelectedIndex > 2) { m_majorRadiusTextBox.Text = m_albers.MajorRadius.ToString(); m_flatteningTextBox.Text = m_albers.Flattening.ToString(); m_centralScaleTextBox.Text = m_albers.CentralScale.ToString(); m_originLatitudeTextBox.Text = m_albers.OriginLatitude.ToString(); } }
public void ConicProj1_CheckFixForAlbersEqualAreaProlateBug() { var aea = new AlbersEqualArea(6.4e6, -0.5, 0, 0, 1); var(lat, _) = aea.Reverse(0, 0, 8605508); Assert.AreEqual(85.00, lat, 0.01); }
public void ConicProj9_CheckFixToInfiniteLoopInAlbersEqualAreaWith_e2_LessThan_MinusOne() { var lcc = new AlbersEqualArea(6.4e6, -0.5, -10, 40, 1); var(x, y) = lcc.Forward(0, 85, 10); Assert.AreEqual(609861, x, 1); Assert.AreEqual(7566522, y, 1); }
public void ConicProj0_CheckFixForAlbersEqualArea_ReverseBug() { var aea = new AlbersEqualArea(Ellipsoid.WGS84, DMS.DecodeAzimuth("40d58"), DMS.DecodeAzimuth("39d56"), 1); var(lat, lon) = aea.Reverse(DMS.DecodeAzimuth("77d45W"), 220e3, -52e3, out var gamma, out var k); Assert.AreEqual(39.95, lat, 0.01); Assert.AreEqual(-75.17, lon, 0.01); Assert.AreEqual(1.67, gamma, 0.01); Assert.AreEqual(0.99, k, 0.01); }
/// <summary> /// Constructor for a ellipsoid with equatorial radius and flattening. /// </summary> /// <param name="a">Equatorial radius (meters).</param> /// <param name="f">Flattening of ellipsoid. Setting <i>f</i> = 0 gives a sphere.</param> public Ellipsoid(double a, double f) { stol_ = 0.01 * Sqrt(DBL_EPSILON); _a = a; _f = f; _f1 = 1 - _f; _f12 = Sq(_f1); _e2 = _f * (2 - _f); _es = (_f < 0 ? -1 : 1) * Sqrt(Abs(_e2)); _e12 = _e2 / (1 - _e2); _n = _f / (2 - _f); _b = _a * _f1; _tm = new TransverseMercator(_a, _f, 1d); _ell = new EllipticFunction(-_e12); _au = new AlbersEqualArea(_a, _f, 0d, 1d, 0d, 1d, 1d); }
public void gigs_sample_test() { var projection = new AlbersEqualArea( new GeographicCoordinate(0, 132 * Math.PI / 180.0), -18 * Math.PI / 180.0, -36 * Math.PI / 180.0, new Vector2(0,0), new SpheroidEquatorialInvF(6378.137 * 1000, 298.2572221)); Assert.That(projection.HasInverse); var inverse = projection.GetInverse(); var expectedGeographic = new GeographicCoordinate(-40 * Math.PI / 180.0, 140 * Math.PI / 180.0); var expectedProjected = new Point2(693250.21, -4395794.49); var actualProjected = projection.TransformValue(expectedGeographic); Assert.AreEqual(expectedProjected.X, actualProjected.X, 0.0008); Assert.AreEqual(expectedProjected.Y, actualProjected.Y, 0.006); var actualGeographic = inverse.TransformValue(expectedProjected); Assert.AreEqual(expectedGeographic.Latitude, actualGeographic.Latitude, 0.000000001); Assert.AreEqual(expectedGeographic.Longitude, actualGeographic.Longitude, 0.0000000003); }
private void OnValidate(object sender, EventArgs e) { try { const double DEG_TO_RAD = 3.1415926535897932384626433832795 / 180.0; AlbersEqualArea a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaNorth); a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaSouth); double radius = a.EquatorialRadius; double f = a.Flattening; a = new AlbersEqualArea(radius, f, 60.0, 1.0); a = new AlbersEqualArea(radius, f, 60.0, 70.0, 1.0); a = new AlbersEqualArea(radius, f, Math.Sin(88.0 * DEG_TO_RAD), Math.Cos(88.0 * DEG_TO_RAD), Math.Sin(89.0 * DEG_TO_RAD), Math.Cos(89.0 * DEG_TO_RAD), 1.0); a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.CylindricalEqualArea); double lon0 = 0.0, lat = 32.0, lon = -86.0, x, y, gamma, k, x1, y1; a.Forward(lon0, lat, lon, out x, out y, out gamma, out k); a.Forward(lon0, lat, lon, out x1, out y1); if (x != x1 || y != y1) { throw new Exception("Error in AlbersEqualArea.Forward"); } a.Reverse(lon0, x, y, out lat, out lon, out gamma, out k); a.Reverse(lon0, x, y, out x1, out y1); if (lat != x1 || lon != y1) { throw new Exception("Error in AlbersEqualArea.Reverse"); } LambertConformalConic b = new LambertConformalConic(radius, f, 60.0, 1.0); b = new LambertConformalConic(radius, f, 60.0, 65.0, 1.0); b = new LambertConformalConic(radius, f, Math.Sin(88.0 * DEG_TO_RAD), Math.Cos(88.0 * DEG_TO_RAD), Math.Sin(89.0 * DEG_TO_RAD), Math.Cos(89.0 * DEG_TO_RAD), 1.0); b = new LambertConformalConic(); b.SetScale(60.0, 1.0); b.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); b.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) { throw new Exception("Error in LambertConformalConic.Forward"); } b.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); b.Reverse(-87.0, x, y, out x1, out y1, out gamma, out k); if (lat != x1 || lon != y1) { throw new Exception("Error in LambertConformalConic.Reverse"); } TransverseMercator c = new TransverseMercator(radius, f, 1.0); c = new TransverseMercator(); c.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); c.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) { throw new Exception("Error in TransverseMercator.Forward"); } c.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); c.Reverse(-87.0, x, y, out x1, out y1); if (lat != x1 || lon != y1) { throw new Exception("Error in TransverseMercator.Reverse"); } TransverseMercatorExact d = new TransverseMercatorExact(radius, f, 1.0, false); d = new TransverseMercatorExact(); d.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); d.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) { throw new Exception("Error in TransverseMercatorExact.Forward"); } d.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); d.Reverse(-87.0, x, y, out x1, out y1); if (lat != x1 || lon != y1) { throw new Exception("Error in TransverseMercatorExact.Reverse"); } } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void OnValidate(object sender, EventArgs e) { try { const double DEG_TO_RAD = 3.1415926535897932384626433832795 / 180.0; AlbersEqualArea a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaNorth); a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.AzimuthalEqualAreaSouth); double radius = a.MajorRadius; double f = a.Flattening; a = new AlbersEqualArea(radius, f, 60.0, 1.0); a = new AlbersEqualArea(radius, f, 60.0, 70.0, 1.0); a = new AlbersEqualArea(radius, f, Math.Sin(88.0 * DEG_TO_RAD), Math.Cos(88.0 * DEG_TO_RAD), Math.Sin(89.0*DEG_TO_RAD), Math.Cos(89.0*DEG_TO_RAD), 1.0); a = new AlbersEqualArea(AlbersEqualArea.StandardTypes.CylindricalEqualArea); double lon0 = 0.0, lat = 32.0, lon = -86.0, x, y, gamma, k, x1, y1; a.Forward(lon0, lat, lon, out x, out y, out gamma, out k); a.Forward(lon0, lat, lon, out x1, out y1); if (x != x1 || y != y1) throw new Exception("Error in AlbersEqualArea.Forward"); a.Reverse(lon0, x, y, out lat, out lon, out gamma, out k); a.Reverse(lon0, x, y, out x1, out y1); if (lat != x1 || lon != y1) throw new Exception("Error in AlbersEqualArea.Reverse"); LambertConformalConic b = new LambertConformalConic(radius, f, 60.0, 1.0); b = new LambertConformalConic(radius, f, 60.0, 65.0, 1.0); b = new LambertConformalConic(radius, f, Math.Sin(88.0 * DEG_TO_RAD), Math.Cos(88.0 * DEG_TO_RAD), Math.Sin(89.0 * DEG_TO_RAD), Math.Cos(89.0 * DEG_TO_RAD), 1.0); b = new LambertConformalConic(); b.SetScale(60.0, 1.0); b.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); b.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) throw new Exception("Error in LambertConformalConic.Forward"); b.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); b.Reverse(-87.0, x, y, out x1, out y1, out gamma, out k); if (lat != x1 || lon != y1) throw new Exception("Error in LambertConformalConic.Reverse"); TransverseMercator c = new TransverseMercator(radius, f, 1.0); c = new TransverseMercator(); c.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); c.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) throw new Exception("Error in TransverseMercator.Forward"); c.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); c.Reverse(-87.0, x, y, out x1, out y1); if (lat != x1 || lon != y1) throw new Exception("Error in TransverseMercator.Reverse"); TransverseMercatorExact d = new TransverseMercatorExact(radius, f, 1.0, false); d = new TransverseMercatorExact(); d.Forward(-87.0, 32.0, -86.0, out x, out y, out gamma, out k); d.Forward(-87.0, 32.0, -86.0, out x1, out y1); if (x != x1 || y != y1) throw new Exception("Error in TransverseMercatorExact.Forward"); d.Reverse(-87.0, x, y, out lat, out lon, out gamma, out k); d.Reverse(-87.0, x, y, out x1, out y1); if (lat != x1 || lon != y1) throw new Exception("Error in TransverseMercatorExact.Reverse"); } catch (Exception xcpt) { MessageBox.Show(xcpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("No errors detected", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); }