Exemplo n.º 1
0
        private static bool ExtractHelmertParams(TransformationCompilationParams opData, out Vector3 translation, out Vector3 rotation, out double scale)
        {
            Contract.Requires(opData != null);
            var xTransParam = new KeywordNamedParameterSelector("XAXIS", "TRANS");
            var yTransParam = new KeywordNamedParameterSelector("YAXIS", "TRANS");
            var zTransParam = new KeywordNamedParameterSelector("ZAXIS", "TRANS");
            var xRotParam   = new KeywordNamedParameterSelector("XAXIS", "ROT");
            var yRotParam   = new KeywordNamedParameterSelector("YAXIS", "ROT");
            var zRotParam   = new KeywordNamedParameterSelector("ZAXIS", "ROT");
            var scaleParam  = new KeywordNamedParameterSelector("SCALE");

            translation = Vector3.Invalid;
            rotation    = Vector3.Invalid;
            scale       = Double.NaN;

            if (!opData.ParameterLookup.Assign(xTransParam, yTransParam, zTransParam, xRotParam, yRotParam, zRotParam, scaleParam))
            {
                return(false);
            }
            if (!TryCreateVector3(xTransParam.Selection, yTransParam.Selection, zTransParam.Selection, out translation))
            {
                return(false);
            }
            if (!TryCreateVector3(xRotParam.Selection, yRotParam.Selection, zRotParam.Selection, OgcAngularUnit.DefaultArcSeconds, out rotation))
            {
                return(false);
            }
            if (!NamedParameter.TryGetDouble(scaleParam.Selection, out scale))
            {
                return(false);
            }

            ConvertIfVaild(scaleParam.Selection.Unit, ScaleUnitPartsPerMillion.Value, ref scale);
            return(true);
        }
Exemplo n.º 2
0
        private static bool TryGetDouble(INamedParameter parameter, IUnit unit, out double value)
        {
            if (!NamedParameter.TryGetDouble(parameter, out value))
            {
                return(false);
            }

            ConvertIfVaild(parameter.Unit, unit, ref value);
            return(true);
        }
Exemplo n.º 3
0
 private static bool TryGetCoefficientValue(INamedParameter parameter, out double value)
 {
     if (null != parameter && NamedParameter.TryGetDouble(parameter, out value))
     {
         ConvertIfVaild(parameter.Unit, ScaleUnitUnity.Value, ref value);
         return(true);
     }
     value = default(double);
     return(false);
 }
Exemplo n.º 4
0
        private static bool TryCreatePoint2(INamedParameter xParam, INamedParameter yParam, IUnit linearUnit, out Point2 result)
        {
            double x, y;

            if (NamedParameter.TryGetDouble(xParam, out x) && NamedParameter.TryGetDouble(yParam, out y))
            {
                if (null != linearUnit)
                {
                    ConvertIfVaild(xParam.Unit, linearUnit, ref x);
                    ConvertIfVaild(yParam.Unit, linearUnit, ref y);
                }
                result = new Point2(x, y);
                return(true);
            }
            result = Point2.Invalid;
            return(false);
        }
Exemplo n.º 5
0
        private static bool TryCreateVector3(INamedParameter xParam, INamedParameter yParam, INamedParameter zParam, IUnit linearUnit, out Vector3 result)
        {
            double x, y, z;

            if (NamedParameter.TryGetDouble(xParam, out x) && NamedParameter.TryGetDouble(yParam, out y) && NamedParameter.TryGetDouble(zParam, out z))
            {
                if (null != linearUnit)
                {
                    ConvertIfVaild(xParam.Unit, linearUnit, ref x);
                    ConvertIfVaild(yParam.Unit, linearUnit, ref y);
                    ConvertIfVaild(zParam.Unit, linearUnit, ref z);
                }
                result = new Vector3(x, y, z);
                return(true);
            }
            result = Vector3.Invalid;
            return(false);
        }
Exemplo n.º 6
0
        private static StaticCoordinateOperationCompiler.StepCompilationResult CreateVerticalOffset(TransformationCompilationParams opData)
        {
            Contract.Requires(opData != null);
            double offsetValue = 0;

            var offsetParam = new KeywordNamedParameterSelector("OFFSET", "VERTICAL");

            if (opData.ParameterLookup.Assign(offsetParam))
            {
                if (!NamedParameter.TryGetDouble(offsetParam.Selection, out offsetValue))
                {
                    offsetValue = 0;
                }
            }

            return(new StaticCoordinateOperationCompiler.StepCompilationResult(
                       opData.StepParams,
                       opData.StepParams.InputUnit,
                       new VerticalOffset(offsetValue)));
        }
Exemplo n.º 7
0
        private static StaticCoordinateOperationCompiler.StepCompilationResult CreateGeographicOffset(TransformationCompilationParams opData)
        {
            Contract.Requires(opData != null);
            var latParam    = new KeywordNamedParameterSelector("LAT");
            var lonParam    = new KeywordNamedParameterSelector("LON");
            var heightParam = new KeywordNamedParameterSelector("HEIGHT");

            opData.ParameterLookup.Assign(latParam, lonParam);


            var deltaLatitude  = 0.0;
            var deltaLongitude = 0.0;
            var deltaHeight    = 0.0;

            if (!latParam.IsSelected && !lonParam.IsSelected && !heightParam.IsSelected)
            {
                return(null);
            }

            if (latParam.IsSelected)
            {
                TryGetDouble(latParam.Selection, opData.StepParams.InputUnit, out deltaLatitude);
            }
            if (lonParam.IsSelected)
            {
                TryGetDouble(lonParam.Selection, opData.StepParams.InputUnit, out deltaLongitude);
            }
            if (heightParam.IsSelected)
            {
                NamedParameter.TryGetDouble(heightParam.Selection, out deltaHeight);
            }

            var transformation = new GeographicOffset(deltaLatitude, deltaLongitude, deltaHeight);

            return(new StaticCoordinateOperationCompiler.StepCompilationResult(
                       opData.StepParams,
                       opData.StepParams.InputUnit,
                       transformation));
        }
Exemplo n.º 8
0
        private static StaticCoordinateOperationCompiler.StepCompilationResult CreateSimilarityTransformation(TransformationCompilationParams opData)
        {
            Contract.Requires(opData != null);
            var xParam = new KeywordNamedParameterSelector("ORDINATE1");
            var yParam = new KeywordNamedParameterSelector("ORDINATE2");
            var mParam = new KeywordNamedParameterSelector("SCALE");
            var rParam = new KeywordNamedParameterSelector("ROTATION");

            if (!opData.ParameterLookup.Assign(xParam, yParam, mParam, rParam))
            {
                return(null);
            }

            Point2 origin;

            if (!TryCreatePoint2(xParam.Selection, yParam.Selection, out origin))
            {
                return(null);
            }

            double scale, rotation;

            if (!NamedParameter.TryGetDouble(mParam.Selection, out scale))
            {
                return(null);
            }
            if (!NamedParameter.TryGetDouble(rParam.Selection, out rotation))
            {
                return(null);
            }

            ConvertIfVaild(rParam.Selection.Unit, OgcAngularUnit.DefaultRadians, ref rotation);

            return(new StaticCoordinateOperationCompiler.StepCompilationResult(
                       opData.StepParams,
                       opData.StepParams.RelatedOutputCrsUnit ?? opData.StepParams.RelatedInputCrsUnit ?? opData.StepParams.InputUnit,
                       new SimilarityTransformation(origin, scale, rotation)));
        }
Exemplo n.º 9
0
        private static StaticCoordinateOperationCompiler.StepCompilationResult CreateMolodenskyBadekas(TransformationCompilationParams opData)
        {
            Contract.Requires(opData != null);
            var xTransParam = new KeywordNamedParameterSelector("XAXIS", "TRANS");
            var yTransParam = new KeywordNamedParameterSelector("YAXIS", "TRANS");
            var zTransParam = new KeywordNamedParameterSelector("ZAXIS", "TRANS");
            var xRotParam   = new KeywordNamedParameterSelector("XAXIS", "ROT");
            var yRotParam   = new KeywordNamedParameterSelector("YAXIS", "ROT");
            var zRotParam   = new KeywordNamedParameterSelector("ZAXIS", "ROT");
            var scaleParam  = new KeywordNamedParameterSelector("SCALE");
            var ord1Param   = new KeywordNamedParameterSelector("ORDINATE1");
            var ord2Param   = new KeywordNamedParameterSelector("ORDINATE2");
            var ord3Param   = new KeywordNamedParameterSelector("ORDINATE3");

            if (!opData.ParameterLookup.Assign(xTransParam, yTransParam, zTransParam, xRotParam, yRotParam, zRotParam, scaleParam, ord1Param, ord2Param, ord3Param))
            {
                return(null);
            }

            Vector3 translation, rotation;
            Point3  ordinate;
            double  scale;

            if (!TryCreateVector3(xTransParam.Selection, yTransParam.Selection, zTransParam.Selection, out translation))
            {
                return(null);
            }
            if (!TryCreateVector3(xRotParam.Selection, yRotParam.Selection, zRotParam.Selection, OgcAngularUnit.DefaultRadians, out rotation))
            {
                return(null);
            }
            if (!TryCreatePoint3(ord1Param.Selection, ord2Param.Selection, ord3Param.Selection, out ordinate))
            {
                return(null);
            }
            if (!NamedParameter.TryGetDouble(scaleParam.Selection, out scale))
            {
                return(null);
            }

            var molodensky = new MolodenskyBadekasTransformation(translation, rotation, ordinate, scale);

            if (opData.StepParams.RelatedInputCrs is ICrsGeocentric && opData.StepParams.RelatedOutputCrs is ICrsGeocentric)
            {
                return(new StaticCoordinateOperationCompiler.StepCompilationResult(
                           opData.StepParams,
                           opData.StepParams.RelatedOutputCrsUnit ?? opData.StepParams.RelatedInputCrsUnit ?? opData.StepParams.InputUnit,
                           molodensky));
            }

            // TODO: need to handle units here
            var spheroidFrom = opData.StepParams.RelatedInputSpheroid;

            if (null == spheroidFrom)
            {
                return(null);
            }

            // TODO: need to handle units here
            var spheroidTo = opData.StepParams.RelatedOutputSpheroid;

            if (null == spheroidTo)
            {
                return(null);
            }

            ITransformation transformation = new GeocentricTransformationGeographicWrapper(spheroidFrom, spheroidTo, molodensky);
            var             conv           = StaticCoordinateOperationCompiler.CreateCoordinateUnitConversion(opData.StepParams.InputUnit, OgcAngularUnit.DefaultRadians);

            if (null != conv)
            {
                transformation = new ConcatenatedTransformation(new[] { conv, transformation });
            }

            return(new StaticCoordinateOperationCompiler.StepCompilationResult(
                       opData.StepParams,
                       OgcAngularUnit.DefaultRadians,
                       transformation));
        }