/// <summary>
        /// Geographic to geographic transformation
        /// </summary>
        /// <remarks>Adds a datum shift if necessary</remarks>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        private static ICoordinateTransformation CreateGeog2Geog(GeographicCoordinateSystem source, GeographicCoordinateSystem target)
        {
            if (source.HorizontalDatum.EqualParams(target.HorizontalDatum))
            {
                //No datum shift needed
                return(new CoordinateTransformation(source,
                                                    target, TransformType.Conversion, new GeographicTransform(source, target),
                                                    string.Empty, string.Empty, -1, string.Empty, string.Empty));
            }

            //Create datum shift
            //Convert to geocentric, perform shift and return to geographic
            var ctFac         = new CoordinateTransformationFactory();
            var cFac          = new CoordinateSystemFactory();
            var sourceCentric = cFac.CreateGeocentricCoordinateSystem(source.HorizontalDatum.Name + " Geocentric",
                                                                      source.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian);
            var targetCentric = cFac.CreateGeocentricCoordinateSystem(target.HorizontalDatum.Name + " Geocentric",
                                                                      target.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian);
            var ct = new ConcatenatedTransform();

            AddIfNotNull(ct, ctFac.CreateFromCoordinateSystems(source, sourceCentric));
            AddIfNotNull(ct, ctFac.CreateFromCoordinateSystems(sourceCentric, targetCentric));
            AddIfNotNull(ct, ctFac.CreateFromCoordinateSystems(targetCentric, target));


            return(new CoordinateTransformation(source,
                                                target, TransformType.Transformation, ct,
                                                string.Empty, string.Empty, -1, string.Empty, string.Empty));
        }
 /// <summary>
 /// Geographic to geographic transformation
 /// </summary>
 /// <remarks>Adds a datum shift if nessesary</remarks>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <returns></returns>
 private ICoordinateTransformation CreateGeog2Geog(IGeographicCoordinateSystem source, IGeographicCoordinateSystem target)
 {
     if (source.HorizontalDatum.EqualParams(target.HorizontalDatum))
     {
         //No datum shift needed
         return(new CoordinateTransformation(source,
                                             target, TransformType.Conversion, new GeographicTransform(source, target),
                                             String.Empty, String.Empty, -1, String.Empty, String.Empty));
     }
     else
     {
         //Create datum shift
         //Convert to geocentric, perform shift and return to geographic
         CoordinateTransformationFactory ctFac         = new CoordinateTransformationFactory();
         CoordinateSystemFactory         cFac          = new CoordinateSystemFactory();
         IGeocentricCoordinateSystem     sourceCentric = cFac.CreateGeocentricCoordinateSystem(source.HorizontalDatum.Name + " Geocentric",
                                                                                               source.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian);
         IGeocentricCoordinateSystem targetCentric = cFac.CreateGeocentricCoordinateSystem(target.HorizontalDatum.Name + " Geocentric",
                                                                                           target.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian);
         ConcatenatedTransform ct = new ConcatenatedTransform();
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, sourceCentric));
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(sourceCentric, targetCentric));
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(targetCentric, target));
         return(new CoordinateTransformation(source,
                                             target, TransformType.Transformation, ct,
                                             String.Empty, String.Empty, -1, String.Empty, String.Empty));
     }
 }
    private void TestGeocentric()
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("WGS84", AngularUnit.Degrees,
                                                                                HorizontalDatum.WGS84,
                                                                                PrimeMeridian.Greenwich,
                                                                                new AxisInfo("Lon",
                                                                                             AxisOrientationEnum.East),
                                                                                new AxisInfo("Lat",
                                                                                             AxisOrientationEnum.North));
        IGeocentricCoordinateSystem geoccs = cFac.CreateGeocentricCoordinateSystem("WGS84 geocentric",
                                                                                   gcs.HorizontalDatum, LinearUnit.Metre,
                                                                                   PrimeMeridian.Greenwich);

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, geoccs);

        var pGeo = new Coordinate(2.12955, 53.80939444, 73);
        var pGc  = Transform(trans.MathTransform, pGeo);

        trans.MathTransform.Invert();
        var pGeo2 = Transform(trans.MathTransform, pGc);

        trans.MathTransform.Invert();

        result.Text += PrintResultTable(gcs, geoccs, pGeo, pGc, new Coordinate(3771793.97, 140253.34, 5124304.35), pGeo2,
                                        "Geocentric test");

        return;
    }
        /// <summary>
        /// Geographic to geographic transformation
        /// </summary>
        /// <remarks>Adds a datum shift if nessesary</remarks>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        private ICoordinateTransformation CreateGeog2Geog(IGeographicCoordinateSystem source, IGeographicCoordinateSystem target)
        {
            if (source.HorizontalDatum.EqualParams(target.HorizontalDatum))
            {
                return(new CoordinateTransformation(source, target, TransformType.Conversion, new Topology.CoordinateSystems.Transformations.GeographicTransform(source, target), string.Empty, string.Empty, -1L, string.Empty, string.Empty));
            }
            CoordinateTransformationFactory factory       = new CoordinateTransformationFactory();
            CoordinateSystemFactory         factory2      = new CoordinateSystemFactory();
            IGeocentricCoordinateSystem     targetCS      = factory2.CreateGeocentricCoordinateSystem(source.HorizontalDatum.Name + " Geocentric", source.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian);
            IGeocentricCoordinateSystem     system2       = factory2.CreateGeocentricCoordinateSystem(target.HorizontalDatum.Name + " Geocentric", target.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian);
            ConcatenatedTransform           mathTransform = new ConcatenatedTransform();

            mathTransform.CoordinateTransformationList.Add(factory.CreateFromCoordinateSystems(source, targetCS));
            mathTransform.CoordinateTransformationList.Add(factory.CreateFromCoordinateSystems(targetCS, system2));
            mathTransform.CoordinateTransformationList.Add(factory.CreateFromCoordinateSystems(system2, target));
            return(new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform, string.Empty, string.Empty, -1L, string.Empty, string.Empty));
        }
Exemple #5
0
        public void TestGeocentric()
        {
            var gcs = CoordinateSystemFactory.CreateGeographicCoordinateSystem("ETRF89 Geographic", AngularUnit.Degrees, HorizontalDatum.ETRF89, PrimeMeridian.Greenwich,
                                                                               new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));
            var gcenCs      = CoordinateSystemFactory.CreateGeocentricCoordinateSystem("ETRF89 Geocentric", HorizontalDatum.ETRF89, LinearUnit.Metre, PrimeMeridian.Greenwich);
            var ct          = CoordinateTransformationFactory.CreateFromCoordinateSystems(gcs, gcenCs);
            var pExpected   = new[] { 2 + 7.0 / 60 + 46.38 / 3600, 53 + 48.0 / 60 + 33.82 / 3600 };         // Point.FromDMS(2, 7, 46.38, 53, 48, 33.82);
            var pExpected3D = new[] { pExpected[0], pExpected[1], 73.0 };
            var p0          = new[] { 3771793.97, 140253.34, 5124304.35 };
            var p1          = ct.MathTransform.Transform(pExpected3D);
            var p2          = ct.MathTransform.Inverse().Transform(p1);

            Assert.IsTrue(ToleranceLessThan(p1, p0, 0.01));
            Assert.IsTrue(ToleranceLessThan(p2, pExpected, 0.00001));
        }
        public void TestGeocentric()
        {
            CoordinateSystemFactory     cFac = new CoordinateSystemFactory();
            IGeographicCoordinateSystem gcs  =
                cFac.CreateGeographicCoordinateSystem("ETRF89 Geographic", AngularUnit.Degrees, HorizontalDatum.ETRF89,
                                                      PrimeMeridian.Greenwich,
                                                      new AxisInfo("East", AxisOrientation.East),
                                                      new AxisInfo("North", AxisOrientation.North));
            IGeocentricCoordinateSystem gcenCs =
                cFac.CreateGeocentricCoordinateSystem("ETRF89 Geocentric", HorizontalDatum.ETRF89, LinearUnit.Metre,
                                                      PrimeMeridian.Greenwich);
            CoordinateTransformationFactory gtFac = new CoordinateTransformationFactory();
            ICoordinateTransformation       ct    = gtFac.CreateFromCoordinateSystems(gcs, gcenCs);
            Point   pExpected   = Point.FromDMS(2, 7, 46.38, 53, 48, 33.82);
            Point3D pExpected3D = new Point3D(pExpected.X, pExpected.Y, 73.0);
            Point3D p0          = new Point3D(3771793.97, 140253.34, 5124304.35);
            Point3D p1          = ct.MathTransform.Transform(pExpected3D) as Point3D;
            Point3D p2          = ct.MathTransform.Inverse().Transform(p1) as Point3D;

            Assert.IsTrue(toleranceLessThan(p1, p0, 0.01));
            Assert.IsTrue(toleranceLessThan(p2, pExpected, 0.00001));
        }
        public void TestDatumTransform()
        {
            CoordinateSystemFactory cFac = new CoordinateSystemFactory();
            //Define datums
            HorizontalDatum wgs72 = HorizontalDatum.WGS72;
            HorizontalDatum ed50  = HorizontalDatum.ED50;

            //Define geographic coordinate systems
            IGeographicCoordinateSystem gcsWGS72 = cFac.CreateGeographicCoordinateSystem("WGS72 Geographic", AngularUnit.Degrees, wgs72, PrimeMeridian.Greenwich,
                                                                                         new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            IGeographicCoordinateSystem gcsWGS84 = cFac.CreateGeographicCoordinateSystem("WGS84 Geographic", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich,
                                                                                         new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            IGeographicCoordinateSystem gcsED50 = cFac.CreateGeographicCoordinateSystem("ED50 Geographic", AngularUnit.Degrees, ed50, PrimeMeridian.Greenwich,
                                                                                        new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            //Define geocentric coordinate systems
            IGeocentricCoordinateSystem gcenCsWGS72 = cFac.CreateGeocentricCoordinateSystem("WGS72 Geocentric", wgs72, LinearUnit.Metre, PrimeMeridian.Greenwich);
            IGeocentricCoordinateSystem gcenCsWGS84 = cFac.CreateGeocentricCoordinateSystem("WGS84 Geocentric", HorizontalDatum.WGS84, LinearUnit.Metre, PrimeMeridian.Greenwich);
            IGeocentricCoordinateSystem gcenCsED50  = cFac.CreateGeocentricCoordinateSystem("ED50 Geocentric", ed50, LinearUnit.Metre, PrimeMeridian.Greenwich);

            //Define projections
            List <ProjectionParameter> parameters = new List <ProjectionParameter>(5);

            parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
            parameters.Add(new ProjectionParameter("central_meridian", 9));
            parameters.Add(new ProjectionParameter("scale_factor", 0.9996));
            parameters.Add(new ProjectionParameter("false_easting", 500000));
            parameters.Add(new ProjectionParameter("false_northing", 0));
            IProjection projection              = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters);
            IProjectedCoordinateSystem utmED50  = cFac.CreateProjectedCoordinateSystem("ED50 UTM Zone 32N", gcsED50, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));
            IProjectedCoordinateSystem utmWGS84 = cFac.CreateProjectedCoordinateSystem("WGS84 UTM Zone 32N", gcsWGS84, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            //Set TOWGS84 parameters
            wgs72.Wgs84Parameters = new Wgs84ConversionInfo(0, 0, 4.5, 0, 0, 0.554, 0.219);
            ed50.Wgs84Parameters  = new Wgs84ConversionInfo(-81.0703, -89.3603, -115.7526,
                                                            -0.48488, -0.02436, -0.41321,
                                                            -0.540645);                                                        //Parameters for Denmark

            //Set up coordinate transformations
            CoordinateTransformationFactory ctFac            = new CoordinateTransformationFactory();
            ICoordinateTransformation       ctForw           = ctFac.CreateFromCoordinateSystems(gcsWGS72, gcenCsWGS72); //Geographic->Geocentric (WGS72)
            ICoordinateTransformation       ctWGS84_Gcen2Geo = ctFac.CreateFromCoordinateSystems(gcenCsWGS84, gcsWGS84); //Geocentric->Geographic (WGS84)
            ICoordinateTransformation       ctWGS84_Geo2UTM  = ctFac.CreateFromCoordinateSystems(gcsWGS84, utmWGS84);    //UTM ->Geographic (WGS84)
            ICoordinateTransformation       ctED50_UTM2Geo   = ctFac.CreateFromCoordinateSystems(utmED50, gcsED50);      //UTM ->Geographic (ED50)
            ICoordinateTransformation       ctED50_Geo2Gcen  = ctFac.CreateFromCoordinateSystems(gcsED50, gcenCsED50);   //Geographic->Geocentric (ED50)

            //Test datum-shift from WGS72 to WGS84
            //Point3D pGeoCenWGS72 = ctForw.MathTransform.Transform(pLongLatWGS72) as Point3D;
            double[] pGeoCenWGS72 = new double[] { 3657660.66, 255768.55, 5201382.11 };
            ICoordinateTransformation geocen_ed50_2_Wgs84 = ctFac.CreateFromCoordinateSystems(gcenCsWGS72, gcenCsWGS84);

            double[] pGeoCenWGS84 = geocen_ed50_2_Wgs84.MathTransform.Transform(pGeoCenWGS72);
            //Point3D pGeoCenWGS84 = wgs72.Wgs84Parameters.Apply(pGeoCenWGS72);

            Assert.IsTrue(ToleranceLessThan(new double[] { 3657660.78, 255778.43, 5201387.75 }, pGeoCenWGS84, 0.01));

            ICoordinateTransformation utm_ed50_2_Wgs84 = ctFac.CreateFromCoordinateSystems(utmED50, utmWGS84);

            double[] pUTMED50  = new double[] { 600000, 6100000 };
            double[] pUTMWGS84 = utm_ed50_2_Wgs84.MathTransform.Transform(pUTMED50);
            Assert.IsTrue(ToleranceLessThan(new double[] { 599928.6, 6099790.2 }, pUTMWGS84, 0.1));
            //Perform reverse
            ICoordinateTransformation utm_Wgs84_2_Ed50 = ctFac.CreateFromCoordinateSystems(utmWGS84, utmED50);

            pUTMED50 = utm_Wgs84_2_Ed50.MathTransform.Transform(pUTMWGS84);
            Assert.IsTrue(ToleranceLessThan(new double[] { 600000, 6100000 }, pUTMED50, 0.1));
            //Assert.IsTrue(Math.Abs((pUTMWGS84 as Point3D).Z - 36.35) < 0.5);
            //Point pExpected = Point.FromDMS(2, 7, 46.38, 53, 48, 33.82);
            //ED50_to_WGS84_Denmark: datum.Wgs84Parameters = new Wgs84ConversionInfo(-89.5, -93.8, 127.6, 0, 0, 4.5, 1.2);
        }
 /// <summary>
 /// Geographic to geographic transformation
 /// </summary>
 /// <remarks>Adds a datum shift if nessesary</remarks>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <returns></returns>
 private ICoordinateTransformation CreateGeog2Geog(IGeographicCoordinateSystem source, IGeographicCoordinateSystem target)
 {
     if (source.HorizontalDatum.EqualParams(target.HorizontalDatum))
     {
         //No datum shift needed
         return new CoordinateTransformation(source,
             target, TransformType.Conversion, new GeographicTransform(source, target),
             String.Empty, String.Empty, -1, String.Empty, String.Empty);
     }
     else
     {
         //Create datum shift
         //Convert to geocentric, perform shift and return to geographic
         CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
         CoordinateSystemFactory cFac = new CoordinateSystemFactory();
         IGeocentricCoordinateSystem sourceCentric = cFac.CreateGeocentricCoordinateSystem(source.HorizontalDatum.Name + " Geocentric",
             source.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian);
         IGeocentricCoordinateSystem targetCentric = cFac.CreateGeocentricCoordinateSystem(target.HorizontalDatum.Name + " Geocentric",
             target.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian);
         ConcatenatedTransform ct = new ConcatenatedTransform();
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, sourceCentric));
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(sourceCentric, targetCentric));
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(targetCentric, target));
         return new CoordinateTransformation(source,
             target, TransformType.Transformation, ct,
             String.Empty, String.Empty, -1, String.Empty, String.Empty);
     }
 }
    private void TestGeocentric()
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("WGS84", AngularUnit.Degrees,
                                                                                HorizontalDatum.WGS84,
                                                                                PrimeMeridian.Greenwich,
                                                                                new AxisInfo("Lon",
                                                                                             AxisOrientationEnum.East),
                                                                                new AxisInfo("Lat",
                                                                                             AxisOrientationEnum.North));
        IGeocentricCoordinateSystem geoccs = cFac.CreateGeocentricCoordinateSystem("WGS84 geocentric",
                                                                                   gcs.HorizontalDatum, LinearUnit.Metre,
                                                                                   PrimeMeridian.Greenwich);

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, geoccs);

        var pGeo = new Coordinate(2.12955, 53.80939444, 73);
        var pGc = Transform(trans.MathTransform, pGeo);
        trans.MathTransform.Invert();
        var pGeo2 = Transform(trans.MathTransform, pGc);
        trans.MathTransform.Invert();

        result.Text += PrintResultTable(gcs, geoccs, pGeo, pGc, new Coordinate(3771793.97, 140253.34, 5124304.35), pGeo2,
                                        "Geocentric test");

        return;
    }
 public void TestGeocentric()
 {
     CoordinateSystemFactory cFac = new CoordinateSystemFactory();
     IGeographicCoordinateSystem gcs =
         cFac.CreateGeographicCoordinateSystem("ETRF89 Geographic", AngularUnit.Degrees, HorizontalDatum.ETRF89,
                                               PrimeMeridian.Greenwich,
                                               new AxisInfo("East", AxisOrientation.East),
                                               new AxisInfo("North", AxisOrientation.North));
     IGeocentricCoordinateSystem gcenCs =
         cFac.CreateGeocentricCoordinateSystem("ETRF89 Geocentric", HorizontalDatum.ETRF89, LinearUnit.Metre,
                                               PrimeMeridian.Greenwich);
     CoordinateTransformationFactory gtFac = new CoordinateTransformationFactory();
     ICoordinateTransformation ct = gtFac.CreateFromCoordinateSystems(gcs, gcenCs);
     Point pExpected = Point.FromDMS(2, 7, 46.38, 53, 48, 33.82);
     Point3D pExpected3D = new Point3D(pExpected.X, pExpected.Y, 73.0);
     Point3D p0 = new Point3D(3771793.97, 140253.34, 5124304.35);
     Point3D p1 = ct.MathTransform.Transform(pExpected3D) as Point3D;
     Point3D p2 = ct.MathTransform.Inverse().Transform(p1) as Point3D;
     Assert.IsTrue(toleranceLessThan(p1, p0, 0.01));
     Assert.IsTrue(toleranceLessThan(p2, pExpected, 0.00001));
 }