///<summary>
        /// Creates a transformation from a source <see cref="CoordinateReferenceSystem"/> to a target one.
        ///</summary>
        ///<param name="sourceCRS">the source CRS to transform from</param>
        ///<param name="targetCRS">the target CRS to transform to</param>
        public BasicCoordinateTransform(CoordinateReferenceSystem sourceCRS,
                                        CoordinateReferenceSystem targetCRS)
        {
            if (sourceCRS == null)
            {
                throw new ArgumentNullException("sourceCRS");
            }
            if (targetCRS == null)
            {
                throw new ArgumentNullException("targetCRS");
            }

            _sourceCRS = sourceCRS;
            _targetCRS = targetCRS;

            // compute strategy for transformation at initialization time, to make transformation more efficient
            // this may include precomputing sets of parameters

            _doInverseProjection = (sourceCRS != CoordinateReferenceSystem.CS_GEO);
            _doForwardProjection = (targetCRS != CoordinateReferenceSystem.CS_GEO);
            _doDatumTransform    = _doInverseProjection && _doForwardProjection &&
                                   !sourceCRS.Datum.Equals(targetCRS.Datum);

            if (!_doDatumTransform)
            {
                return;
            }

            var isEllipsoidEqual = sourceCRS.Datum.Ellipsoid.Equals(targetCRS.Datum.Ellipsoid);

            if (!isEllipsoidEqual)
            {
                _transformViaGeocentric = true;
            }
            if (sourceCRS.Datum.HasTransformToWGS84 ||
                targetCRS.Datum.HasTransformToWGS84)
            {
                _transformViaGeocentric = true;
            }

            if (!_transformViaGeocentric)
            {
                return;
            }

            _sourceGeoConv = new GeocentricConverter(sourceCRS.Datum.Ellipsoid);
            _targetGeoConv = new GeocentricConverter(targetCRS.Datum.Ellipsoid);
        }
Beispiel #2
0
        public Vector3D ReprojectGeodeticToGeocentric(Vector3D geodetic)
        {
            var xys_as_array = new List <double>
            {
                geodetic.X *Math.PI / 180,
                geodetic.Y *Math.PI / 180
            }.ToArray();

            var zs_as_array = new double[]
            {
                geodetic.Z
            };

            GeocentricConverter.GeodeticToGeocentric(xys_as_array, zs_as_array, 0, 1);

            return(new Vector3D(Convert.ToSingle(xys_as_array[0]), Convert.ToSingle(xys_as_array[1]), Convert.ToSingle(zs_as_array[0])));
        }