/// <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 static ICoordinateTransformation Proj2Proj(IProjectedCoordinateSystem source, IProjectedCoordinateSystem target)
        {
            ConcatenatedTransform           ct    = new ConcatenatedTransform();
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

            //First transform from projection to geographic
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, source.GeographicCoordinateSystem));
            //Transform geographic to geographic:
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.GeographicCoordinateSystem, target.GeographicCoordinateSystem));
            //Transform to new projection
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(target.GeographicCoordinateSystem, target));

            return(new CoordinateTransformation(source,
                                                target, TransformType.Transformation, ct,
                                                String.Empty, String.Empty, -1, String.Empty, String.Empty));
        }
        /// <summary>
        /// Geocentric to Geocentric transformation
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        private static ICoordinateTransformation CreateGeoc2Geoc(IGeocentricCoordinateSystem source, IGeocentricCoordinateSystem target)
        {
            ConcatenatedTransform ct = new ConcatenatedTransform();

            //Does source has a datum different from WGS84 and is there a shift specified?
            if (source.HorizontalDatum.Wgs84Parameters != null && !source.HorizontalDatum.Wgs84Parameters.HasZeroValuesOnly)
            {
                ct.CoordinateTransformationList.Add(
                    new CoordinateTransformation(
                        ((target.HorizontalDatum.Wgs84Parameters == null || target.HorizontalDatum.Wgs84Parameters.HasZeroValuesOnly) ? target : GeocentricCoordinateSystem.WGS84),
                        source, TransformType.Transformation,
                        new DatumTransform(source.HorizontalDatum.Wgs84Parameters)
                        , "", "", -1, "", ""));
            }

            //Does target has a datum different from WGS84 and is there a shift specified?
            if (target.HorizontalDatum.Wgs84Parameters != null && !target.HorizontalDatum.Wgs84Parameters.HasZeroValuesOnly)
            {
                ct.CoordinateTransformationList.Add(
                    new CoordinateTransformation(
                        ((source.HorizontalDatum.Wgs84Parameters == null || source.HorizontalDatum.Wgs84Parameters.HasZeroValuesOnly) ? source : GeocentricCoordinateSystem.WGS84),
                        target,
                        TransformType.Transformation,
                        new DatumTransform(target.HorizontalDatum.Wgs84Parameters).Inverse()
                        , "", "", -1, "", ""));
            }

            if (ct.CoordinateTransformationList.Count == 1)             //Since we only have one shift, lets just return the datumshift from/to wgs84
            {
                return(new CoordinateTransformation(source, target, TransformType.ConversionAndTransformation, ct.CoordinateTransformationList[0].MathTransform, "", "", -1, "", ""));
            }
            else
            {
                return(new CoordinateTransformation(source, target, TransformType.ConversionAndTransformation, ct, "", "", -1, "", ""));
            }
        }