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> /// 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); } }