Пример #1
0
        private bool ComputationallyEqual(IDatumGeodetic a, IDatumGeodetic b)
        {
            if (a == b)
            {
                return(true);
            }
            if (a == null || b == null)
            {
                return(false);
            }

            if (!ComputationallyEqual(a.Spheroid, b.Spheroid))
            {
                return(false);
            }

            if (!ComputationallyEqual(a.PrimeMeridian, b.PrimeMeridian))
            {
                return(false);
            }

            if (a.IsTransformableToWgs84)
            {
                return(b.IsTransformableToWgs84 &&
                       ComputationallyEqual(a.BasicWgs84Transformation, b.BasicWgs84Transformation));
            }
            else
            {
                return(b.IsTransformableToWgs84 == false);
            }
        }
Пример #2
0
        public static Datum Create(IDatumGeodetic datum)
        {
            if (datum == null)
            {
                throw new ArgumentNullException("datum");
            }
            Contract.Ensures(Contract.Result <Datum>() != null);

            var result = new Datum {
                Name = datum.Name
            };

            result.Spheroid = Proj4SpheroidWrapper.Create(datum.Spheroid);

            if (datum.IsTransformableToWgs84)
            {
                var helmert = datum.BasicWgs84Transformation;
                if (helmert.ScaleDeltaPartsPerMillion == 0 && Vector3.Zero.Equals(helmert.RotationArcSeconds))
                {
                    if (Vector3.Zero.Equals(helmert.Delta))
                    {
                        if (result.Spheroid.Name == "WE")
                        {
                            result.Proj4DatumName = "wgs84";
                        }
                        else
                        {
                            result.DatumType = DatumType.WGS84;
                        }
                    }
                    else
                    {
                        result.ToWGS84 = new[] {
                            helmert.Delta.X, helmert.Delta.Y, helmert.Delta.Z
                        };
                        result.DatumType = DatumType.Param3;
                    }
                }
                else
                {
                    result.ToWGS84 = new[] {
                        helmert.Delta.X, helmert.Delta.Y, helmert.Delta.Z,
                        helmert.RotationArcSeconds.X, helmert.RotationArcSeconds.Y, helmert.RotationArcSeconds.Z,
                        helmert.ScaleDeltaPartsPerMillion
                    };
                    result.DatumType = DatumType.Param7;
                }
            }
            else
            {
                result.DatumType = DatumType.Unknown;
            }

            return(result);
        }
Пример #3
0
 /// <summary>
 /// Constructs a new geocentric CRS.
 /// </summary>
 /// <param name="name">The name of the CRS.</param>
 /// <param name="datum">The datum the CRS is based on.</param>
 /// <param name="linearUnit">The linear UoM to use for the CRS.</param>
 /// <param name="axes">The axes which define the space.</param>
 /// <param name="authority">The authority.</param>
 public OgcCrsGeocentric(
     string name,
     IDatumGeodetic datum,
     IUnit linearUnit,
     IEnumerable<IAxis> axes,
     IAuthorityTag authority
     )
     : base(name, authority)
 {
     if (null == datum) throw new ArgumentNullException("datum");
     if (null == linearUnit) throw new ArgumentNullException("linearUnit");
     Contract.Requires(name != null);
     Datum = datum;
     Unit = linearUnit;
     Axes = Array.AsReadOnly(null == axes ? new IAxis[0] : axes.ToArray());
 }
Пример #4
0
 /// <summary>
 /// Constructs a new geographic CRS.
 /// </summary>
 /// <param name="name">The name of the CRS.</param>
 /// <param name="datum">The datum the CRS is based on.</param>
 /// <param name="angularUnit">The angular unit of measure for the CRS.</param>
 /// <param name="axes">The axes defining the space.</param>
 /// <param name="authority">The authority.</param>
 public OgcCrsGeographic(
     string name,
     IDatumGeodetic datum,
     IUnit angularUnit,
     IEnumerable <IAxis> axes,
     IAuthorityTag authority = null
     )
     : base(name, authority)
 {
     if (null == datum)
     {
         throw new ArgumentNullException("datum");
     }
     if (null == angularUnit)
     {
         throw new ArgumentNullException("angularUnit");
     }
     Contract.Requires(name != null);
     Datum = datum;
     Unit  = angularUnit;
     Axes  = Array.AsReadOnly(null == axes ? new IAxis[0] : axes.ToArray());
 }
Пример #5
0
        private ICrsGeographic ReadGeographicCsFromParams()
        {
            Contract.Ensures(Contract.Result <ICrsGeographic>() != null);
            IAuthorityTag      authority     = null;
            var                name          = String.Empty;
            IDatumGeodetic     datum         = null;
            IPrimeMeridianInfo primeMeridian = null;
            IUnit              unit          = OgcAngularUnit.DefaultDegrees;
            var                axes          = new List <IAxis>();

            foreach (var parameter in ReadParams())
            {
                if (parameter is string)
                {
                    name = (string)parameter;
                }
                else if (parameter is IAuthorityTag)
                {
                    authority = (IAuthorityTag)parameter;
                }
                else if (parameter is IDatumGeodetic)
                {
                    datum = (IDatumGeodetic)parameter;
                }
                else if (parameter is IPrimeMeridianInfo)
                {
                    primeMeridian = (IPrimeMeridianInfo)parameter;
                }
                else if (parameter is IUnit)
                {
                    unit = (IUnit)parameter;
                }
                else if (parameter is IAxis)
                {
                    axes.Add((IAxis)parameter);
                }
            }

            if (null != authority)
            {
                var crs = Options.GetCrs(authority) as ICrsGeographic;
                if (null != crs)
                {
                    return(crs);
                }
            }

            if (null != datum && datum.PrimeMeridian == null && null != primeMeridian)
            {
                // in this case the datum must have NOT been created from an authority source so we should remake it with a prime meridian
                datum = new OgcDatumHorizontal(
                    datum.Name,
                    datum.Spheroid,
                    primeMeridian,
                    datum.BasicWgs84Transformation,
                    datum.Authority
                    );
            }

            if (datum == null)
            {
                if (Options.ThrowOnError)
                {
                    throw new WktParseExceptioncs("Geographic CRS", "No datum.");
                }
                datum = OgcDatumHorizontal.DefaultWgs84;
            }

            return(new OgcCrsGeographic(
                       name,
                       datum,
                       unit,
                       axes,
                       authority
                       ));
        }
Пример #6
0
        public static Datum Create(IDatumGeodetic datum)
        {
            if(datum == null) throw new ArgumentNullException("datum");
            Contract.Ensures(Contract.Result<Datum>() != null);

            var result = new Datum {
                Name = datum.Name
            };

            result.Spheroid = Proj4SpheroidWrapper.Create(datum.Spheroid);

            if (datum.IsTransformableToWgs84) {
                var helmert = datum.BasicWgs84Transformation;
                if (helmert.ScaleDeltaPartsPerMillion == 0 && Vector3.Zero.Equals(helmert.RotationArcSeconds)) {
                    if (Vector3.Zero.Equals(helmert.Delta)) {
                        if (result.Spheroid.Name == "WE")
                            result.Proj4DatumName = "wgs84";
                        else
                            result.DatumType = DatumType.WGS84;
                    }
                    else{
                        result.ToWGS84 = new[] {
                            helmert.Delta.X, helmert.Delta.Y, helmert.Delta.Z
                        };
                        result.DatumType = DatumType.Param3;
                    }
                }
                else {
                    result.ToWGS84 = new[] {
                        helmert.Delta.X, helmert.Delta.Y, helmert.Delta.Z,
                        helmert.RotationArcSeconds.X, helmert.RotationArcSeconds.Y, helmert.RotationArcSeconds.Z,
                        helmert.ScaleDeltaPartsPerMillion
                    };
                    result.DatumType = DatumType.Param7;
                }
            }
            else {
                result.DatumType = DatumType.Unknown;
            }

            return result;
        }