/// <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 static 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); 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)); } }
private static void AddIfNotNull(ConcatenatedTransform concatTrans, ICoordinateTransformation trans) { if (trans != null) { concatTrans.CoordinateTransformationList.Add(trans); } }
private static void SimplifyTrans(ConcatenatedTransform mtrans, ref List<ICoordinateTransformation> MTs) { foreach(ICoordinateTransformation t in mtrans.CoordinateTransformationList) { if(t is ConcatenatedTransform) SimplifyTrans(t as ConcatenatedTransform, ref MTs); else MTs.Add(t); } }
private static void SimplifyTrans(ConcatenatedTransform mtrans, ref List <ICoordinateTransformation> MTs) { foreach (ICoordinateTransformation t in mtrans.CoordinateTransformationList) { if (t is ConcatenatedTransform) { SimplifyTrans(t as ConcatenatedTransform, ref MTs); } else { MTs.Add(t); } } }
private static CoordinateTransformation Geoc2Geog(GeocentricCoordinateSystem source, GeographicCoordinateSystem target) { var geocMathTransform = CreateCoordinateOperation(source).Inverse(); if (source.PrimeMeridian.EqualParams(target.PrimeMeridian)) { return(new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, string.Empty, string.Empty, -1, string.Empty, string.Empty)); } var ct = new ConcatenatedTransform(); ct.CoordinateTransformationList.Add(new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, string.Empty, string.Empty, -1, string.Empty, string.Empty)); ct.CoordinateTransformationList.Add(new CoordinateTransformation(source, target, TransformType.Transformation, new PrimeMeridianTransform(source.PrimeMeridian, target.PrimeMeridian), string.Empty, string.Empty, -1, string.Empty, string.Empty)); return(new CoordinateTransformation(source, target, TransformType.Conversion, 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)); }
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)); } }
private static CoordinateTransformation Geog2Proj(GeographicCoordinateSystem source, ProjectedCoordinateSystem target) { if (source.EqualParams(target.GeographicCoordinateSystem)) { var mathTransform = CreateCoordinateOperation(target.Projection, target.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid, target.LinearUnit); return(new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform, string.Empty, string.Empty, -1, string.Empty, string.Empty)); } // Geographic coordinatesystems differ - Create concatenated transform var ct = new ConcatenatedTransform(); var ctFac = new CoordinateTransformationFactory(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, target.GeographicCoordinateSystem)); 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) { var 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 we don't have a transformation in this list, return null if (ct.CoordinateTransformationList.Count == 0) { return(null); } //If we only have one shift, lets just return the datumshift from/to wgs84 if (ct.CoordinateTransformationList.Count == 1) { return(new CoordinateTransformation(source, target, TransformType.ConversionAndTransformation, ct.CoordinateTransformationList[0].MathTransform, "", "", -1, "", "")); } return(new CoordinateTransformation(source, target, TransformType.ConversionAndTransformation, ct, "", "", -1, "", "")); }
private static CoordinateTransformation Proj2Proj(ProjectedCoordinateSystem source, ProjectedCoordinateSystem target) { var ct = new ConcatenatedTransform(); var ctFac = new CoordinateTransformationFactory(); //First transform from projection to geographic ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, source.GeographicCoordinateSystem)); //Transform geographic to geographic: var geogToGeog = ctFac.CreateFromCoordinateSystems(source.GeographicCoordinateSystem, target.GeographicCoordinateSystem); if (geogToGeog != null) { ct.CoordinateTransformationList.Add(geogToGeog); } //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> /// Creates transformation from source coordinate system to specified target system which is the fitted one /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static ICoordinateTransformation Any2Fitt(ICoordinateSystem source, IFittedCoordinateSystem target) { //Transform form base system of fitted to target coordinate system - use invered math transform IMathTransform invMt = CreateFittedTransform(target).Inverse(); //case when source system is equal to base system of the fitted if (target.BaseCoordinateSystem.EqualParams(source)) { //Transform form base system of fitted to target coordinate system return(CreateTransform(source, target, TransformType.Transformation, invMt)); } ConcatenatedTransform ct = new ConcatenatedTransform(); //First transform from source to base system of fitted CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, target.BaseCoordinateSystem)); //Transform form base system of fitted to target coordinate system - use invered math transform ct.CoordinateTransformationList.Add(CreateTransform(target.BaseCoordinateSystem, target, TransformType.Transformation, invMt)); return(CreateTransform(source, target, TransformType.Transformation, ct)); }
/// <summary> /// Creates transformation from fitted coordinate system to the target one /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static ICoordinateTransformation Fitt2Any(IFittedCoordinateSystem source, ICoordinateSystem target) { //transform from fitted to base system of fitted (which is equal to target) IMathTransform mt = CreateFittedTransform(source); //case when target system is equal to base system of the fitted if (source.BaseCoordinateSystem.EqualParams(target)) { //Transform form base system of fitted to target coordinate system return(CreateTransform(source, target, TransformType.Transformation, mt)); } //Transform form base system of fitted to target coordinate system ConcatenatedTransform ct = new ConcatenatedTransform(); ct.CoordinateTransformationList.Add(CreateTransform(source, source.BaseCoordinateSystem, TransformType.Transformation, mt)); //Transform form base system of fitted to target coordinate system CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.BaseCoordinateSystem, target)); return(CreateTransform(source, target, TransformType.Transformation, ct)); }
/// <summary> /// 地理坐标转换为投影坐标 /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static ICoordinateTransformation Geog2Proj(IGeographicCoordinateSystem source, IProjectedCoordinateSystem target) { //目标的地理坐标系和源的地理坐标系相同,则直接采用投影变换 if (source.EqualParams(target.GeographicCoordinateSystem)) { IMathTransform mathTransform = CreateCoordinateOperation(target.Projection, target.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid, target.LinearUnit); 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, target.GeographicCoordinateSystem)); //创建从目标地理坐标系到目标投影坐标系的转换 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> /// 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); }
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> /// 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, "", ""); }
/// <summary> /// Creates transformation from fitted coordinate system to the target one /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static ICoordinateTransformation Fitt2Any (IFittedCoordinateSystem source, ICoordinateSystem target) { //transform from fitted to base system of fitted (which is equal to target) IMathTransform mt = CreateFittedTransform (source); //case when target system is equal to base system of the fitted if (source.BaseCoordinateSystem.EqualParams (target)) { //Transform form base system of fitted to target coordinate system return CreateTransform (source, target, TransformType.Transformation, mt); } //Transform form base system of fitted to target coordinate system ConcatenatedTransform ct = new ConcatenatedTransform (); ct.CoordinateTransformationList.Add (CreateTransform (source, source.BaseCoordinateSystem, TransformType.Transformation, mt)); //Transform form base system of fitted to target coordinate system CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory (); ct.CoordinateTransformationList.Add (ctFac.CreateFromCoordinateSystems (source.BaseCoordinateSystem, target)); return CreateTransform (source, target, TransformType.Transformation, ct); }
/// <summary> /// Creates transformation from source coordinate system to specified target system which is the fitted one /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static ICoordinateTransformation Any2Fitt (ICoordinateSystem source, IFittedCoordinateSystem target) { //Transform form base system of fitted to target coordinate system - use invered math transform IMathTransform invMt = CreateFittedTransform (target).Inverse (); //case when source system is equal to base system of the fitted if (target.BaseCoordinateSystem.EqualParams (source)) { //Transform form base system of fitted to target coordinate system return CreateTransform (source, target, TransformType.Transformation, invMt); } ConcatenatedTransform ct = new ConcatenatedTransform (); //First transform from source to base system of fitted CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory (); ct.CoordinateTransformationList.Add (ctFac.CreateFromCoordinateSystems (source, target.BaseCoordinateSystem)); //Transform form base system of fitted to target coordinate system - use invered math transform ct.CoordinateTransformationList.Add (CreateTransform (target.BaseCoordinateSystem, target, TransformType.Transformation, invMt)); return CreateTransform (source, target, TransformType.Transformation, ct); }
private static ICoordinateTransformation Geog2Geoc(IGeographicCoordinateSystem source, IGeocentricCoordinateSystem target) { IMathTransform geocMathTransform = CreateCoordinateOperation(target); if (source.PrimeMeridian.EqualParams(target.PrimeMeridian)) { return new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, String.Empty, String.Empty, -1, String.Empty, String.Empty); } else { var ct = new ConcatenatedTransform(); ct.CoordinateTransformationList.Add(new CoordinateTransformation(source, target, TransformType.Transformation, new PrimeMeridianTransform(source.PrimeMeridian, target.PrimeMeridian), String.Empty, String.Empty, -1, String.Empty, String.Empty)); ct.CoordinateTransformationList.Add(new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, String.Empty, String.Empty, -1, String.Empty, String.Empty)); return new CoordinateTransformation(source, target, TransformType.Conversion, ct, String.Empty, String.Empty, -1, String.Empty, String.Empty); } }
private static void AddIfNotNull(ConcatenatedTransform concatTrans, ICoordinateTransformation trans) { if (trans != null) concatTrans.CoordinateTransformationList.Add(trans); }