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 StaticCoordinateOperationCompiler.StepCompilationResult CreateAffineParametricTransformation(TransformationCompilationParams opData)
        {
            Contract.Requires(opData != null);
            var a0Param = new KeywordNamedParameterSelector("A0");
            var a1Param = new KeywordNamedParameterSelector("A1");
            var a2Param = new KeywordNamedParameterSelector("A2");
            var b0Param = new KeywordNamedParameterSelector("B0");
            var b1Param = new KeywordNamedParameterSelector("B1");
            var b2Param = new KeywordNamedParameterSelector("B2");

            if (!opData.ParameterLookup.Assign(a0Param, a1Param, a2Param, b0Param, b1Param, b2Param))
            {
                return(null);
            }

            Vector3 a, b;

            if (!TryCreateVector3(a0Param.Selection, a1Param.Selection, a2Param.Selection, out a))
            {
                return(null);
            }
            if (!TryCreateVector3(b0Param.Selection, b1Param.Selection, b2Param.Selection, out b))
            {
                return(null);
            }

            return(new StaticCoordinateOperationCompiler.StepCompilationResult(
                       opData.StepParams,
                       opData.StepParams.InputUnit,
                       new AffineParametricTransformation(a.X, a.Y, a.Z, b.X, b.Y, b.Z)));
        }
Exemplo n.º 3
0
        private static StaticCoordinateOperationCompiler.StepCompilationResult CreateGeocentricTopocentric(TransformationCompilationParams opData)
        {
            Contract.Requires(opData != null);
            var xParam = new KeywordNamedParameterSelector("XAXIS", "X");
            var yParam = new KeywordNamedParameterSelector("YAXIS", "Y");
            var zParam = new KeywordNamedParameterSelector("ZAXIS", "Z");

            opData.ParameterLookup.Assign(xParam, yParam, zParam);

            Point3 origin;

            if (!TryCreatePoint3(xParam.Selection, yParam.Selection, zParam.Selection, opData.StepParams.InputUnit, out origin))
            {
                origin = Point3.Zero;
            }

            var spheroid = opData.StepParams.ConvertRelatedInputSpheroidUnit(opData.StepParams.InputUnit);

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

            return(new StaticCoordinateOperationCompiler.StepCompilationResult(
                       opData.StepParams,
                       opData.StepParams.InputUnit,
                       new GeocentricTopocentricTransformation(origin, spheroid)));
        }
Exemplo n.º 4
0
        private static StaticCoordinateOperationCompiler.StepCompilationResult CreateGeographicTopocentric(TransformationCompilationParams opData)
        {
            Contract.Requires(opData != null);
            var outputUnit = opData.StepParams.RelatedOutputCrsUnit;

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

            var latParam = new KeywordNamedParameterSelector("LAT");
            var lonParam = new KeywordNamedParameterSelector("LON");
            var hParam   = new KeywordNamedParameterSelector("H");

            opData.ParameterLookup.Assign(latParam, lonParam, hParam);

            GeographicHeightCoordinate origin;

            if (!TryCreateGeographicHeightCoordinate(latParam.Selection, lonParam.Selection, hParam.Selection, OgcAngularUnit.DefaultRadians, opData.StepParams.RelatedOutputCrsUnit, out origin))
            {
                origin = GeographicHeightCoordinate.Zero;
            }

            var spheroidIn = opData.StepParams.ConvertRelatedInputSpheroidUnit(outputUnit);

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

            var spheroidOut = opData.StepParams.ConvertRelatedOutputSpheroidUnit(outputUnit);

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

            var geographicGeocentric = new GeographicGeocentricTransformation(spheroidIn);
            var topocentricOrigin    = geographicGeocentric.TransformValue(origin);

            var transformations = new List <ITransformation>()
            {
                geographicGeocentric,
                new GeocentricTopocentricTransformation(topocentricOrigin, spheroidOut)
            };

            var inputUnitConversion = StaticCoordinateOperationCompiler.CreateCoordinateUnitConversion(opData.StepParams.InputUnit, OgcAngularUnit.DefaultRadians);

            if (null != inputUnitConversion)
            {
                transformations.Insert(0, inputUnitConversion);
            }

            return(new StaticCoordinateOperationCompiler.StepCompilationResult(
                       opData.StepParams,
                       outputUnit,
                       new ConcatenatedTransformation(transformations)
                       ));
        }
Exemplo n.º 5
0
        private static StaticCoordinateOperationCompiler.StepCompilationResult CreateGeocentricTranslation(TransformationCompilationParams opData)
        {
            Contract.Requires(opData != null);
            var xParam = new KeywordNamedParameterSelector("XAXIS", "X");
            var yParam = new KeywordNamedParameterSelector("YAXIS", "Y");
            var zParam = new KeywordNamedParameterSelector("ZAXIS", "Z");

            opData.ParameterLookup.Assign(xParam, yParam, zParam);

            Vector3 delta;

            if (!TryCreateVector3(xParam.Selection, yParam.Selection, zParam.Selection, out delta))
            {
                return(null);
            }

            if (opData.StepParams.RelatedInputCrs is ICrsGeocentric && opData.StepParams.RelatedOutputCrs is ICrsGeocentric)
            {
                // assume the units are correct
                return(new StaticCoordinateOperationCompiler.StepCompilationResult(
                           opData.StepParams,
                           opData.StepParams.RelatedOutputCrsUnit ?? opData.StepParams.RelatedInputCrsUnit ?? opData.StepParams.InputUnit,
                           new GeocentricTranslation(delta)));
            }

            // TODO: need to handle unit here
            var inputSpheroid = opData.StepParams.RelatedInputSpheroid;

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

            // TODO: may even need to convert units while translating

            // TODO: need to handle unit here
            var outputSpheroid = opData.StepParams.RelatedOutputSpheroid;

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

            ITransformation transformation = new GeographicGeocentricTranslation(inputSpheroid, delta, outputSpheroid);
            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));
        }
Exemplo n.º 6
0
        private static StaticCoordinateOperationCompiler.StepCompilationResult CreateVerticalPerspective(TransformationCompilationParams opData)
        {
            Contract.Requires(opData != null);
            var outputUnit = opData.StepParams.RelatedOutputCrsUnit;

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

            var latParam     = new KeywordNamedParameterSelector("LAT");
            var lonParam     = new KeywordNamedParameterSelector("LON");
            var hOriginParam = new KeywordNamedParameterSelector("H", "HEIGHT", "ORIGIN");
            var hViewParam   = new KeywordNamedParameterSelector("H", "HEIGHT", "VIEW");

            opData.ParameterLookup.Assign(latParam, lonParam, hOriginParam, hViewParam);

            GeographicHeightCoordinate origin;

            if (!TryCreateGeographicHeightCoordinate(latParam.Selection, lonParam.Selection, hOriginParam.Selection, OgcAngularUnit.DefaultRadians, outputUnit, out origin))
            {
                origin = GeographicHeightCoordinate.Zero;
            }

            double viewHeight;

            if (!TryGetDouble(hViewParam.Selection, outputUnit, out viewHeight))
            {
                viewHeight = Double.NaN;
            }

            var spheroidIn = opData.StepParams.ConvertRelatedInputSpheroidUnit(outputUnit);

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

            ITransformation transformation = new VerticalPerspective(origin, viewHeight, spheroidIn);

            return(new StaticCoordinateOperationCompiler.StepCompilationResult(
                       opData.StepParams,
                       outputUnit,
                       transformation
                       ));
        }
Exemplo n.º 7
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.º 8
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.º 9
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.º 10
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));
        }