Trouble Applying Transformation to Projection

Apr 6, 2016 at 10:27 PM
We are trying to go from NAD83 to Web Mercator (4269 to 3857) while applying a specific data transformation (NAD_1983_To_GS_1984_5)

I'm using the following code:
        public async Task<IMapPoint> HandleAsync(ProjectPointToWebMercator query)
        {
            var gga = query.GGAData;

            double[] values = new double[] { gga.Longitude, gga.Latitude, gga.Altitude };

            double[] transformedValues = Wgs84LatLonToMercator(values);

            var mapService = await _mediator.RequestAsync(new GetMapService());
            var latLong = await _mediator.RequestAsync(new NewMapPoint(transformedValues[0], transformedValues[1], transformedValues[2], mapService.SpatialReference));

            return latLong;
        }

        private const string sridx = "GEOGCS";
        private const string srid6318 = "GEOGCS[\"GCS_NAD_1983_2011\",DATUM[\"D_NAD_1983_2011\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]";
        private const string srid4269 = "GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6269\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4269\"]]";
        private const string Srid4326 = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]";

        public double[] MercatorToWgs84LatLon(double[] values)
        {
            var mercator = GetMercatorProjection();
            var latlon = (IGeographicCoordinateSystem)CoordinateSystemWktReader.Parse(srid4269);
            var ctfac = new CoordinateTransformationFactory();
            var transformation = ctfac.CreateFromCoordinateSystems(mercator, latlon);
            var transform = transformation;
            var converted = transform.MathTransform.Transform(values);
            return converted;
        }

        public double[] Wgs84LatLonToMercator(double[] values)
        {
            try
            {
                var mercator = GetMercatorProjection();
                var latlon = (IGeographicCoordinateSystem)CreateNAD83CoordinateSystem();
                var ctfac = new CoordinateTransformationFactory();
                var transformation = ctfac.CreateFromCoordinateSystems(latlon, mercator);
                var transform = transformation;
                var converted = transform.MathTransform.Transform(values);
                return converted;
            }
            catch(Exception e)
            {
                int i = 0;
                i++;
                return values;
            }
        }

        private static IGeographicCoordinateSystem CreateNAD83CoordinateSystem()
        {
            CoordinateSystemFactory cFac = new CoordinateSystemFactory();

            //Create Bessel 1840 geographic coordinate system
            IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("GCS_NAD_1983_2011", 6378137.0, 298.257222101, LinearUnit.Metre);

            //Information for transformation - scale factor is zero.
            Wgs84ConversionInfo info = new Wgs84ConversionInfo();
            info.Dx = -0.991;
            info.Dy = 1.907200;
            info.Dz = 0.512900;
            info.Ex = -0.025790;
            info.Ey = -0.009650;
            info.Ez = -0.011660;
            info.Ppm = 0.0;

            IHorizontalDatum datum = cFac.CreateHorizontalDatum("D_NAD_1983_2011", DatumType.HD_Geocentric, ellipsoid, info);
            IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("GCS_NAD_1983_2011", AngularUnit.Degrees, datum,
                PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                new AxisInfo("Lat", AxisOrientationEnum.North));

            return gcs;
        }

        private static ICoordinateSystem GetMercatorProjection()
        {
            var factory = new CoordinateSystemFactory();

            var wgs84 = factory.CreateGeographicCoordinateSystem("WGS 84",
                AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich,
                new AxisInfo("north", AxisOrientationEnum.North), new
                AxisInfo("east", AxisOrientationEnum.East));

            var parameters = new List<ProjectionParameter>
            {
                new ProjectionParameter("semi_major", 6378137),
                new ProjectionParameter("semi_minor", 6378137),
                new ProjectionParameter("latitude_of_origin", 0.0),
                new ProjectionParameter("central_meridian", 0.0),
                new ProjectionParameter("scale_factor", 1.0),
                new ProjectionParameter("false_easting", 0.0),
                new ProjectionParameter("false_northing", 0.0)
            };

            var projection = factory.CreateProjection("Mercator", "mercator_1sp", parameters);

            var mercator = factory.CreateProjectedCoordinateSystem("Mercator",
                wgs84, projection, LinearUnit.Metre,
                new AxisInfo("East", AxisOrientationEnum.East),
                new AxisInfo("North", AxisOrientationEnum.North));
            return mercator;
        }
    }
I am 5.91 feet off when applying the transformation and 3.01 feet off when not applying the transformation. The values for dx, dy, dz, Ex, ey, eZ are coming from the transformation in arcmap. They are reported as dx, dy, dz, rx, ry, rz.

What is wrong here? I can't find a lot of examples on how to apply a specific transformation to when projecting from one projection to another.