/// <summary> /// Creates geocentric to geocentric transformation. /// </summary> /// <remarks>Adds a datum shift if nessesary</remarks> /// <param name="source">Source coordinate system</param> /// <param name="target">TargetCoordinate system</param> /// <returns>The requested transformation</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, "", ""); }
private static ICoordinateTransformation Proj2Geog(IProjectedCoordinateSystem source, IGeographicCoordinateSystem target) { if (source.GeographicCoordinateSystem.EqualParams(target)) { IMathTransform mathTransform = CreateCoordinateOperation(source.Projection, source.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid, source.LinearUnit).Inverse(); return new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform, String.Empty, String.Empty, -1, String.Empty, String.Empty); } else { // Geographic coordinatesystems differ - Create concatenated transform ConcatenatedTransform ct = new ConcatenatedTransform(); CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, source.GeographicCoordinateSystem)); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.GeographicCoordinateSystem, target)); return new CoordinateTransformation(source, target, TransformType.Transformation, ct, String.Empty, String.Empty, -1, String.Empty, String.Empty); } }
/// <summary> /// Creates geographic to geographic transformation. /// </summary> /// <remarks>Adds a datum shift if nessesary</remarks> /// <param name="source">Source coordinate system</param> /// <param name="target">TargetCoordinate system</param> /// <returns>The requested transformation</returns> private ICoordinateTransformation CreateGeog2Geog(IGeographicCoordinateSystem source, IGeographicCoordinateSystem target) { if (source.HorizontalDatum.EqualParams(target.HorizontalDatum)) { //datum shift is not needed return new CoordinateTransformation(source, target, TransformType.Conversion, new GeographicTransform(source, target), String.Empty, String.Empty, -1, String.Empty, String.Empty); } else { //datum shift // transformation into a geocentric system, datum shift and return to the system of geographical 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); }