public void TestLccToGeographicIterative() { double phi1 = 33.0; double phi2 = 45.0; double phi0 = 23.0; double lambda0 = -96.0; double x = 1894410.9; double y = 1564649.5; double expectedPhi = 35.0; double expectedLambda = -75.0; var projection = new LambertConformalConic( IRI.Ham.CoordinateSystem.Ellipsoids.Clarke1866, phi1, phi2, lambda0, phi0); var result = projection.LCCToGeodeticIterative(new Point(x, y)); Assert.AreEqual(result.X, expectedLambda, .00001); Assert.AreEqual(result.Y, expectedPhi, .00001); }
private void SetLambert() { 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_lambert = new LambertConformalConic(a, f, s1, k); break; case 1: s2 = Double.Parse(m_stdLat2TextBox.Text); m_lambert = new LambertConformalConic(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_lambert = new LambertConformalConic(a, f, s1, s2, s3, s4, k); break; default: break; } m_centralScaleTextBox.Text = m_lambert.CentralScale.ToString(); m_originLatitudeTextBox.Text = m_lambert.OriginLatitude.ToString(); }
public void ConicProj7() { var lcc = new LambertConformalConic(Ellipsoid.WGS84, 90, 90, 1); var(lat, lon) = lcc.Reverse(0, 0, -1e150); Assert.AreEqual(-90.0, lat, 0.01); Assert.AreEqual(0.00, Math.Abs(lon), 0.001); }
public void ConicProj6() { var lcc = new LambertConformalConic(Ellipsoid.WGS84, 45, 45, 1); var(lat, lon) = lcc.Reverse(0, 0, double.NegativeInfinity); Assert.AreEqual(-90.0, lat, 0.01); Assert.AreEqual(0.00, Math.Abs(lon), 0.001); }
public void ConicProj4() { var lcc = new LambertConformalConic(Ellipsoid.WGS84, 0, 0, 1); var(lat, lon) = lcc.Reverse(0, 1113195, double.PositiveInfinity); Assert.AreEqual(90.0, lat, 0.01); Assert.AreEqual(10.00, lon, 0.001); }
public void ConicProj3_CheckFixForLambertConformalConic_ReverseOverflowBugs() { var lcc = new LambertConformalConic(Ellipsoid.WGS84, 0, 0, 1); var(lat, lon) = lcc.Reverse(0, 1113195, -1e10); Assert.AreEqual(-90.0, lat, 0.01); Assert.AreEqual(10.00, lon, 0.001); }
public void TestGeographicToLcc() { var result = new LambertConformalConic(Ellipsoids.Clarke1866, 33.0, 45.0, -96.0, 23.0).FromGeodetic(new Point(-75.0, 35.0)); Assert.AreEqual(result.X, 1894410.9, .1); Assert.AreEqual(result.Y, 1564649.5, .1); var ellipse = IRI.Ham.CoordinateSystem.Ellipsoids.GRS80; double phi0 = 52; double phi1 = 35; double phi2 = 65; double lambda0 = 10; var projection = new LambertConformalConic(ellipse, phi1, phi2, lambda0, phi0); //Iran double lambda = 53; double phi = 33; result = projection.FromGeodetic(new Point(lambda, phi)); Assert.AreEqual(result.X + 4000000, 7830046.77, .01); Assert.AreEqual(result.Y + 2800000, 1879902.99, .01); //Canada lambda = -105; phi = 54; result = projection.FromGeodetic(new Point(lambda, phi)); Assert.AreEqual(result.X + 4000000, -685838.46, .01); Assert.AreEqual(result.Y + 2800000, 7633442.68, .01); //Brazil lambda = -53; phi = -12; result = projection.FromGeodetic(new Point(lambda, phi)); Assert.AreEqual(result.X + 4000000, -5883916.57, .01); Assert.AreEqual(result.Y + 2800000, -936363.79, .01); //Autralia lambda = 134; phi = -23; result = projection.FromGeodetic(new Point(lambda, phi)); Assert.AreEqual(result.X + 4000000, 19245528.93, .01); Assert.AreEqual(result.Y + 2800000, 9343431.52, .01); }
public void ConicProj2_CheckFixForLambertConformalConic_ForwardBug() { var lcc = new LambertConformalConic(Ellipsoid.WGS84, -30, -30, 1); var(x, y) = lcc.Forward(0, -30, 0, out var gamma, out var k); Assert.AreEqual(0.0, Math.Abs(x), 0.01); Assert.AreEqual(0.0, Math.Abs(y), 0.01); Assert.AreEqual(0.0, Math.Abs(gamma), 0.01); Assert.AreEqual(1.0, k, 0.01); }
public void MainTest() { var clarke = IRI.Ham.CoordinateSystem.Ellipsoids.Clarke1880Rgs; double phi0 = 32.5; double phi1 = 29.65508274166; double phi2 = 35.31468809166; double lambda0 = 45.0; var niocLcc = new LambertConformalConic(clarke, phi1, phi2, lambda0, phi0, 1500000.0, 1166200.0, 0.9987864078); var xLccNioc = 2047473.33479; var yLccNioc = 912594.777238; var xWgs84 = 50.689721; var yWgs84 = 30.072906; var xWebMercator = 5642753.9243; var yWebMercator = 3512924.70491; var xClarke1880Rgs = 50.689721; var yClarke1880Rgs = 30.075637; var wgs84 = niocLcc.ToWgs84Geodetic(new Point(xLccNioc, yLccNioc)); Assert.AreEqual(xWgs84, wgs84.X, 1E-6); Assert.AreEqual(yWgs84, wgs84.Y, 1E-6); var clarke1880 = niocLcc.ToGeodetic(new Point(xLccNioc, yLccNioc)); Assert.AreEqual(xClarke1880Rgs, clarke1880.X, 1E-6); Assert.AreEqual(yClarke1880Rgs, clarke1880.Y, 1E-6); var webMercator = MapProjects.GeodeticWgs84ToWebMercator(wgs84); Assert.AreEqual(xWebMercator, webMercator.X, 0.05); Assert.AreEqual(yWebMercator, webMercator.Y, 0.05); var clarke1880_2 = Transformation.ChangeDatum(wgs84, Ellipsoids.WGS84, Ellipsoids.Clarke1880Rgs); Assert.AreEqual(xClarke1880Rgs, clarke1880_2.X, 1E-6); Assert.AreEqual(yClarke1880Rgs, clarke1880_2.Y, 1E-6); }
static void Main(string[] args) { try { // Define the Pennsylvania South state coordinate system EPSG:3364 // http://www.spatialreference.org/ref/epsg/3364/ const double lat1 = 40 + 58 / 60.0, lat2 = 39 + 56 / 60.0, // standard parallels k1 = 1, // scale lat0 = 39 + 20 / 60.0, lon0 = -77 - 45 / 60.0, // origin fe = 600000, fn = 0; // false easting and northing // Set up basic projection LambertConformalConic PASouth = new LambertConformalConic(Constants.WGS84.MajorRadius, Constants.WGS84.Flattening, lat1, lat2, k1); double x0, y0; // Transform origin point PASouth.Forward(lon0, lat0, lon0, out x0, out y0); x0 -= fe; y0 -= fn; { // Sample conversion from geodetic to PASouth grid double lat = 39.95, lon = -75.17; // Philadelphia double x, y; PASouth.Forward(lon0, lat, lon, out x, out y); x -= x0; y -= y0; Console.WriteLine(String.Format("{0} {1}", x, y)); } { // Sample conversion from PASouth grid to geodetic double x = 820e3, y = 72e3; double lat, lon; x += x0; y += y0; PASouth.Reverse(lon0, 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)); } }
static void Main(string[] args) { try { // Define the Pennsylvania South state coordinate system EPSG:3364 // http://www.spatialreference.org/ref/epsg/3364/ const double lat1 = 40 + 58/60.0, lat2 = 39 + 56/60.0, // standard parallels k1 = 1, // scale lat0 = 39 + 20/60.0, lon0 =-77 - 45/60.0, // origin fe = 600000, fn = 0; // false easting and northing // Set up basic projection LambertConformalConic PASouth = new LambertConformalConic( Constants.WGS84.MajorRadius, Constants.WGS84.Flattening, lat1, lat2, k1); double x0, y0; // Transform origin point PASouth.Forward(lon0, lat0, lon0, out x0, out y0); x0 -= fe; y0 -= fn; { // Sample conversion from geodetic to PASouth grid double lat = 39.95, lon = -75.17; // Philadelphia double x, y; PASouth.Forward(lon0, lat, lon, out x, out y); x -= x0; y -= y0; Console.WriteLine( String.Format("{0} {1}", x, y) ); } { // Sample conversion from PASouth grid to geodetic double x = 820e3, y = 72e3; double lat, lon; x += x0; y += y0; PASouth.Reverse(lon0, 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) ); } }
private static PrjFile AsEsriPrjFile(LambertConformalConic lcc) { PrjTree root = new PrjTree(); root.Name = PrjFile._projcs; root.Values = new List <string>() { string.IsNullOrWhiteSpace(lcc.Title) ? "LAMBERT CONFORMAL CONIC" : lcc.Title }; var geogcs = new PrjTree(lcc.Ellipsoid, lcc.DatumName); var projection = new PrjTree(PrjFile._projection, PrjFile._esriLambertConformalConic); var falseEasting = new PrjTree(PrjFile._parameter, PrjFile._falseEasting, lcc.FalseEasting.AsExactString()); var falseNorthing = new PrjTree(PrjFile._parameter, PrjFile._falseNorthing, lcc.FalseNorthing.AsExactString()); var centralMeridian = new PrjTree(PrjFile._parameter, PrjFile._centralMeridian, lcc.CentralMeridian.AsExactString()); var standardParallel1 = new PrjTree(PrjFile._parameter, PrjFile._standardParallel1, lcc.StandardParallel1.AsExactString()); var standardParallel2 = new PrjTree(PrjFile._parameter, PrjFile._standardParallel2, lcc.StandardParallel2.AsExactString()); var scaleFactor = new PrjTree(PrjFile._parameter, PrjFile._scaleFactor, lcc.StandardParallel2.AsExactString()); var latitudeOfOrigin = new PrjTree(PrjFile._parameter, PrjFile._latitudeOfOrigin, lcc.StandardParallel2.AsExactString()); var unit = PrjTree.MeterUnit; root.Children = new List <PrjTree>() { geogcs, projection, falseEasting, falseNorthing, centralMeridian, standardParallel1, standardParallel2, scaleFactor, latitudeOfOrigin, unit }; return(new PrjFile(root)); }
public void TestLccToGeographic() { double expectedPhi = 35.0; double expectedLambda = -75.0; var result = new LambertConformalConic( IRI.Ham.CoordinateSystem.Ellipsoids.Clarke1866, 33.0, 45.0, -96.0, 23.0).ToGeodetic(new Point(1894410.9, 1564649.5)); Assert.AreEqual(result.X, expectedLambda, .00001); Assert.AreEqual(result.Y, expectedPhi, .00001); var ellipse = IRI.Ham.CoordinateSystem.Ellipsoids.GRS80; double phi0 = 52; double phi1 = 35; double phi2 = 65; double lambda0 = 10; var projection = new LambertConformalConic(ellipse, phi1, phi2, lambda0, phi0); //China double x = 10000000 - 4000000; double y = 4000000 - 2800000; result = projection.ToGeodetic(new Point(x, y)); Assert.AreEqual(result.X, 85.22674468408002, 0.000001); Assert.AreEqual(result.Y, 32.27382257394294, 0.000001); //Canada x = -800000 - 4000000; y = 7000000 - 2800000; result = projection.ToGeodetic(new Point(x, y)); Assert.AreEqual(result.X, -95.34976832367953, 0.000001); Assert.AreEqual(result.Y, 52.469308415860205, 0.000001); //Brazil x = -5000000 - 4000000; y = -350000 - 2800000; result = projection.ToGeodetic(new Point(x, y)); Assert.AreEqual(result.X, -52.14245756518865, 0.000001); Assert.AreEqual(result.Y, -5.873476680963928, 0.000001); //Autralia x = 19000000 - 4000000; y = 9000000 - 2800000; result = projection.ToGeodetic(new Point(x, y)); Assert.AreEqual(result.X, 132.45309686067716, 0.000001); Assert.AreEqual(result.Y, -21.744457361769854, 0.000001); }
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); }