Пример #1
0
        internal void AlignSigFigs(GridReference source)
        {
            int SigFigsSrc;
            int SigFigsDest;


            SigFigsSrc  = Converter.GetSigFigs(source.Easting);
            SigFigsDest = Converter.GetSigFigs(this.Easting);

            this.Easting = (int)Converter.SetSigFigs(
                (double)this.Easting,
                SigFigsDest < SigFigsSrc ? SigFigsDest : SigFigsSrc);

            source.Easting = (int)Converter.SetSigFigs(
                (double)source.Easting,
                SigFigsDest < SigFigsSrc ? SigFigsDest : SigFigsSrc);

            SigFigsSrc  = Converter.GetSigFigs(source.Northing);
            SigFigsDest = Converter.GetSigFigs(this.Northing);

            this.Northing = (int)Converter.SetSigFigs(
                (double)this.Northing,
                SigFigsDest < SigFigsSrc ? SigFigsDest : SigFigsSrc);

            source.Northing = (int)Converter.SetSigFigs(
                (double)source.Northing,
                SigFigsDest < SigFigsSrc ? SigFigsDest : SigFigsSrc);
        }
Пример #2
0
        internal void AlignSigFigs(GridReference source)
        {
            int SigFigsSrc;
            int SigFigsDest;

            SigFigsSrc = Converter.GetSigFigs(source.Easting);
            SigFigsDest = Converter.GetSigFigs(this.Easting);

            this.Easting = (int)Converter.SetSigFigs(
                 (double)this.Easting,
                 SigFigsDest < SigFigsSrc ? SigFigsDest : SigFigsSrc);

            source.Easting = (int)Converter.SetSigFigs(
                  (double)source.Easting,
                 SigFigsDest < SigFigsSrc ? SigFigsDest : SigFigsSrc);

            SigFigsSrc = Converter.GetSigFigs(source.Northing);
            SigFigsDest = Converter.GetSigFigs(this.Northing);

            this.Northing = (int)Converter.SetSigFigs(
                  (double)this.Northing,
                 SigFigsDest < SigFigsSrc ? SigFigsDest : SigFigsSrc);

            source.Northing = (int)Converter.SetSigFigs(
                  (double)source.Northing,
                 SigFigsDest < SigFigsSrc ? SigFigsDest : SigFigsSrc);
        }
 /// <summary>
 /// Converts northing and easting coordinates into Longitude/Latitude coordinates in the WGS84 coordinate system.
 /// </summary>
 /// <param name="northing">northing coordinate</param>
 /// <param name="easting">easting coordinate</param>
 /// <returns>converted coordinates</returns>
 protected PolarGeoCoordinate ConvertToLonLat(double northing, double easting)
 {
     // Use GeoCoordConversion DLL to convert the Eastings & Northings to Lon/Lat
     // coordinates in the WGS84 system. The DLL was pulled from: http://code.google.com/p/geocoordconversion/
     // and is available under the GNU General Public License v3: http://www.gnu.org/licenses/gpl.html
     GridReference gridRef = new GridReference((long)easting, (long)northing);
     PolarGeoCoordinate polarCoord = GridReference.ChangeToPolarGeo(gridRef);
     return PolarGeoCoordinate.ChangeCoordinateSystem(polarCoord, CoordinateSystems.WGS84);
 }
Пример #4
0
        internal static PolarGeoCoordinate GridReferenceToGeodesic(GridReference g)
        {
            double lat = _NatGridTrueOrigin.Lat;
            double M   = 0;

            do
            {
                lat = (g.Northing - _NatNETrueOrigin.Northing - M) / (_Airy1830.SemimajorAxis * _NatGridScaleFactor)
                      + lat;

                double Ma = (1 + _n + (5d / 4d) * _n2 + (5d / 4d) * _n3) * (lat - _NatGridTrueOrigin.Lat);
                double Mb = (3 * _n + 3 * _n * _n + (21d / 8d) * _n3) * Math.Sin(lat - _NatGridTrueOrigin.Lat)
                            * Math.Cos(lat + _NatGridTrueOrigin.Lat);
                double Mc = ((15d / 8d) * _n2 + (15d / 8d) * _n3) * Math.Sin(2 * (lat - _NatGridTrueOrigin.Lat))
                            * Math.Cos(2 * (lat + _NatGridTrueOrigin.Lat));
                double Md = (35d / 24d) * _n3 * Math.Sin(3 * (lat - _NatGridTrueOrigin.Lat))
                            * Math.Cos(3 * (lat + _NatGridTrueOrigin.Lat));
                M = _Airy1830.SemiMinorAxis * _NatGridScaleFactor * (Ma - Mb + Mc - Md); // meridional arc
            }while (g.Northing - _NatNETrueOrigin.Northing - M >= 0.00001);              // ie until < 0.01mm

            double cosLat = Math.Cos(lat), sinLat = Math.Sin(lat);
            double nu = _Airy1830.SemimajorAxis * _NatGridScaleFactor / Math.Sqrt(1 - _e2 * sinLat * sinLat);

            // transverse radius of curvature
            double rho = _Airy1830.SemimajorAxis * _NatGridScaleFactor * (1 - _e2)
                         / Math.Pow(1 - _e2 * sinLat * sinLat, 1.5); // meridional radius of curvature
            double eta2 = nu / rho - 1;

            double tanLat = Math.Tan(lat);
            double tan2lat = tanLat * tanLat, tan4lat = tan2lat * tan2lat, tan6lat = tan4lat * tan2lat;
            double secLat = 1 / cosLat;
            double nu3 = nu * nu * nu, nu5 = nu3 * nu * nu, nu7 = nu5 * nu * nu;
            double VII  = tanLat / (2 * rho * nu);
            double VIII = tanLat / (24 * rho * nu3) * (5 + 3 * tan2lat + eta2 - 9 * tan2lat * eta2);
            double IX   = tanLat / (720 * rho * nu5) * (61 + 90 * tan2lat + 45 * tan4lat);
            double X    = secLat / nu;
            double XI   = secLat / (6 * nu3) * (nu / rho + 2 * tan2lat);
            double XII  = secLat / (120 * nu5) * (5 + 28 * tan2lat + 24 * tan4lat);
            double XIIA = secLat / (5040 * nu7) * (61 + 662 * tan2lat + 1320 * tan4lat + 720 * tan6lat);

            double dE  = g.Easting - _NatNETrueOrigin.Easting;
            double dE2 = dE * dE;
            double dE3 = dE2 * dE;
            double dE4 = dE2 * dE2;
            double dE5 = dE3 * dE2;
            double dE6 = dE4 * dE2;
            double dE7 = dE5 * dE2;

            lat = lat - VII * dE2 + VIII * dE4 - IX * dE6;
            double lon = _NatGridTrueOrigin.Lon + X * dE - XI * dE3 + XII * dE5 - XIIA * dE7;

            var retVal = new PolarGeoCoordinate(lat, lon, 0, AngleUnit.Radians, CoordinateSystems.OSGB36);

            retVal = PolarGeoCoordinate.ChangeUnits(retVal, AngleUnit.Degrees);
            retVal.SetSigFigs(7);
            return(retVal);
        }
Пример #5
0
 public bool IsTheSameAs(GridReference compareTo)
 {
     if (
         compareTo.Northing != this.Northing
         || compareTo.Easting != this.Easting
         )
         return false;
     else
         return true;
 }
Пример #6
0
        internal static GridReference ReduceSigFigsBy1(GridReference original)
        {
            double Northing = Converter.SetSigFigs(
                original.Northing,
                Converter.GetSigFigs(original.Northing) - 1);

            double Easting = Converter.SetSigFigs(
                original.Easting,
                Converter.GetSigFigs(original.Easting) - 1);

            return(new GridReference((int)Easting, (int)Northing));
        }
Пример #7
0
        internal static GridReference ReduceSigFigsBy1(GridReference original)
        {
            double Northing = Converter.SetSigFigs(
                 original.Northing,
                 Converter.GetSigFigs(original.Northing) - 1);

            double Easting = Converter.SetSigFigs(
                 original.Easting,
                 Converter.GetSigFigs(original.Easting) - 1);

            return new GridReference((int)Easting, (int)Northing);
        }
Пример #8
0
        //overload of IsTheSameAs to ignore rounding errors on final digit
        public bool IsTheSameAs(GridReference compareTo, bool ignoreFinalDigit)
        {
            if (ignoreFinalDigit)
            {
                AlignSigFigs(compareTo);
                GridReference compareToReduced = ReduceSigFigsBy1(compareTo);
                GridReference comparer = ReduceSigFigsBy1(this);

                return comparer.IsTheSameAs(compareToReduced);
            }

            return IsTheSameAs(compareTo);
        }
Пример #9
0
        //overload of IsTheSameAs to ignore rounding errors on final digit
        public bool IsTheSameAs(GridReference compareTo, bool ignoreFinalDigit)
        {
            if (ignoreFinalDigit)
            {
                AlignSigFigs(compareTo);
                GridReference compareToReduced = ReduceSigFigsBy1(compareTo);
                GridReference comparer         = ReduceSigFigsBy1(this);

                return(comparer.IsTheSameAs(compareToReduced));
            }

            return(IsTheSameAs(compareTo));
        }
Пример #10
0
 public bool IsTheSameAs(GridReference compareTo)
 {
     if (
         compareTo.Northing != this.Northing ||
         compareTo.Easting != this.Easting
         )
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Пример #11
0
 public static PolarGeoCoordinate ChangeToPolarGeo(GridReference original)
 {
     return Converter.GridReferenceToGeodesic(original);
 }
Пример #12
0
        internal static PolarGeoCoordinate GridReferenceToGeodesic(GridReference g)
        {
            double lat = _NatGridTrueOrigin.Lat;
            double M = 0;
            do
            {
                lat = (g.Northing - _NatNETrueOrigin.Northing - M) / (_Airy1830.SemimajorAxis * _NatGridScaleFactor)
                      + lat;

                double Ma = (1 + _n + (5d / 4d) * _n2 + (5d / 4d) * _n3) * (lat - _NatGridTrueOrigin.Lat);
                double Mb = (3 * _n + 3 * _n * _n + (21d / 8d) * _n3) * Math.Sin(lat - _NatGridTrueOrigin.Lat)
                            * Math.Cos(lat + _NatGridTrueOrigin.Lat);
                double Mc = ((15d / 8d) * _n2 + (15d / 8d) * _n3) * Math.Sin(2 * (lat - _NatGridTrueOrigin.Lat))
                            * Math.Cos(2 * (lat + _NatGridTrueOrigin.Lat));
                double Md = (35d / 24d) * _n3 * Math.Sin(3 * (lat - _NatGridTrueOrigin.Lat))
                            * Math.Cos(3 * (lat + _NatGridTrueOrigin.Lat));
                M = _Airy1830.SemiMinorAxis * _NatGridScaleFactor * (Ma - Mb + Mc - Md); // meridional arc
            }
            while (g.Northing - _NatNETrueOrigin.Northing - M >= 0.00001); // ie until < 0.01mm

            double cosLat = Math.Cos(lat), sinLat = Math.Sin(lat);
            double nu = _Airy1830.SemimajorAxis * _NatGridScaleFactor / Math.Sqrt(1 - _e2 * sinLat * sinLat);

            // transverse radius of curvature
            double rho = _Airy1830.SemimajorAxis * _NatGridScaleFactor * (1 - _e2)
                         / Math.Pow(1 - _e2 * sinLat * sinLat, 1.5); // meridional radius of curvature
            double eta2 = nu / rho - 1;

            double tanLat = Math.Tan(lat);
            double tan2lat = tanLat * tanLat, tan4lat = tan2lat * tan2lat, tan6lat = tan4lat * tan2lat;
            double secLat = 1 / cosLat;
            double nu3 = nu * nu * nu, nu5 = nu3 * nu * nu, nu7 = nu5 * nu * nu;
            double VII = tanLat / (2 * rho * nu);
            double VIII = tanLat / (24 * rho * nu3) * (5 + 3 * tan2lat + eta2 - 9 * tan2lat * eta2);
            double IX = tanLat / (720 * rho * nu5) * (61 + 90 * tan2lat + 45 * tan4lat);
            double X = secLat / nu;
            double XI = secLat / (6 * nu3) * (nu / rho + 2 * tan2lat);
            double XII = secLat / (120 * nu5) * (5 + 28 * tan2lat + 24 * tan4lat);
            double XIIA = secLat / (5040 * nu7) * (61 + 662 * tan2lat + 1320 * tan4lat + 720 * tan6lat);

            double dE = g.Easting - _NatNETrueOrigin.Easting;
            double dE2 = dE * dE;
            double dE3 = dE2 * dE;
            double dE4 = dE2 * dE2;
            double dE5 = dE3 * dE2;
            double dE6 = dE4 * dE2;
            double dE7 = dE5 * dE2;
            lat = lat - VII * dE2 + VIII * dE4 - IX * dE6;
            double lon = _NatGridTrueOrigin.Lon + X * dE - XI * dE3 + XII * dE5 - XIIA * dE7;

            var retVal = new PolarGeoCoordinate(lat, lon, 0, AngleUnit.Radians, CoordinateSystems.OSGB36);
            retVal = PolarGeoCoordinate.ChangeUnits(retVal, AngleUnit.Degrees);
            retVal.SetSigFigs(7);
            return retVal;
        }
Пример #13
0
 public static PolarGeoCoordinate ChangeToPolarGeo(GridReference original)
 {
     return(Converter.GridReferenceToGeodesic(original));
 }