Exemplo n.º 1
0
 public TransformationCompilationParams(
     StaticCoordinateOperationCompiler.StepCompilationParameters stepParams,
     NamedParameterLookup parameterLookup,
     string operationName
     )
 {
     Contract.Requires(stepParams != null);
     Contract.Requires(parameterLookup != null);
     Contract.Requires(!String.IsNullOrEmpty(operationName));
     StepParams      = stepParams;
     ParameterLookup = parameterLookup;
     OperationName   = operationName;
 }
Exemplo n.º 2
0
        private StaticCoordinateOperationCompiler.StepCompilationResult CompileForwardToTransform(StaticCoordinateOperationCompiler.StepCompilationParameters stepParameters)
        {
            Contract.Requires(stepParameters != null);
            string operationName = null;
            IEnumerable <INamedParameter> parameters = null;

            var parameterizedOperation = stepParameters.CoordinateOperationInfo as IParameterizedCoordinateOperationInfo;

            if (null != parameterizedOperation)
            {
                if (null != parameterizedOperation.Method)
                {
                    operationName = parameterizedOperation.Method.Name;
                }
                parameters = parameterizedOperation.Parameters;
            }

            if (String.IsNullOrEmpty(operationName))
            {
                operationName = stepParameters.CoordinateOperationInfo.Name;
            }
            if (String.IsNullOrEmpty(operationName))
            {
                return(null);
            }

            var parameterLookup   = new NamedParameterLookup(parameters ?? Enumerable.Empty <INamedParameter>());
            var compilationParams = new TransformationCompilationParams(stepParameters, parameterLookup, operationName);

            var normalizedName = _coordinateOperationNameComparer.Normalize(compilationParams.OperationName);

            if (normalizedName.StartsWith("POSITIONVECTORTRANSFORMATION"))
            {
                return(CreatePositionVectorTransformation(compilationParams));
            }
            if (normalizedName.StartsWith("COORDINATEFRAMEROTATION"))
            {
                return(CreateCoordinateFrameRotationTransformation(compilationParams));
            }
            if (normalizedName.StartsWith("MOLODENSKYBADEKAS"))
            {
                return(CreateMolodenskyBadekas(compilationParams));
            }
            if (normalizedName.Equals("GEOGRAPHICOFFSET") || (normalizedName.StartsWith("GEOGRAPHIC") && normalizedName.EndsWith("OFFSET")))
            {
                return(CreateGeographicOffset(compilationParams));
            }
            if (normalizedName.StartsWith("GEOCENTRICTRANSLATION"))
            {
                return(CreateGeocentricTranslation(compilationParams));
            }
            if (normalizedName.Equals("VERTICALOFFSET"))
            {
                return(CreateVerticalOffset(compilationParams));
            }
            if (normalizedName.Equals("MADRIDTOED50POLYNOMIAL"))
            {
                return(CreateMadridToEd50Polynomial(compilationParams));
            }
            if (normalizedName.Equals("SIMILARITYTRANSFORMATION"))
            {
                return(CreateSimilarityTransformation(compilationParams));
            }
            if (normalizedName.Equals("AFFINEPARAMETRICTRANSFORMATION"))
            {
                return(CreateAffineParametricTransformation(compilationParams));
            }
            if (normalizedName.Equals("GEOGRAPHIC3DTO2DCONVERSION") || normalizedName.Equals("GEOGRAPHIC2DTO3DCONVERSION"))
            {
                return(CreateGeographicDimensionChange(compilationParams));
            }
            if (normalizedName.Equals("TUNISIAMININGGRID"))
            {
                return(CreateTunisiaMiningGrid(compilationParams));
            }
            if (normalizedName.StartsWith("GEOCENTRICTOPOCENTRIC"))
            {
                return(CreateGeocentricTopocentric(compilationParams));
            }
            if (normalizedName.StartsWith("GEOGRAPHICTOPOCENTRIC"))
            {
                return(CreateGeographicTopocentric(compilationParams));
            }
            if (normalizedName.StartsWith("VERTICALPERSPECTIVE"))
            {
                return(CreateVerticalPerspective(compilationParams));
            }
            return(null);
        }
 public TransformationCompilationParams(
     StaticCoordinateOperationCompiler.StepCompilationParameters stepParams,
     NamedParameterLookup parameterLookup,
     string operationName
 )
 {
     Contract.Requires(stepParams != null);
     Contract.Requires(parameterLookup != null);
     Contract.Requires(!String.IsNullOrEmpty(operationName));
     StepParams = stepParams;
     ParameterLookup = parameterLookup;
     OperationName = operationName;
 }
        private StaticCoordinateOperationCompiler.StepCompilationResult CompileForwardToTransform(StaticCoordinateOperationCompiler.StepCompilationParameters stepParameters)
        {
            Contract.Requires(stepParameters != null);
            string operationName = null;
            IEnumerable<INamedParameter> parameters = null;

            var parameterizedOperation = stepParameters.CoordinateOperationInfo as IParameterizedCoordinateOperationInfo;
            if (null != parameterizedOperation) {
                if (null != parameterizedOperation.Method)
                    operationName = parameterizedOperation.Method.Name;
                parameters = parameterizedOperation.Parameters;
            }

            if (String.IsNullOrEmpty(operationName))
                operationName = stepParameters.CoordinateOperationInfo.Name;
            if (String.IsNullOrEmpty(operationName))
                return null;

            var parameterLookup = new NamedParameterLookup(parameters ?? Enumerable.Empty<INamedParameter>());
            var compilationParams = new TransformationCompilationParams(stepParameters, parameterLookup, operationName);

            var normalizedName = _coordinateOperationNameComparer.Normalize(compilationParams.OperationName);
            if (normalizedName.StartsWith("POSITIONVECTORTRANSFORMATION"))
                return CreatePositionVectorTransformation(compilationParams);
            if (normalizedName.StartsWith("COORDINATEFRAMEROTATION"))
                return CreateCoordinateFrameRotationTransformation(compilationParams);
            if (normalizedName.StartsWith("MOLODENSKYBADEKAS"))
                return CreateMolodenskyBadekas(compilationParams);
            if (normalizedName.Equals("GEOGRAPHICOFFSET") || (normalizedName.StartsWith("GEOGRAPHIC") && normalizedName.EndsWith("OFFSET")))
                return CreateGeographicOffset(compilationParams);
            if (normalizedName.StartsWith("GEOCENTRICTRANSLATION"))
                return CreateGeocentricTranslation(compilationParams);
            if (normalizedName.Equals("VERTICALOFFSET"))
                return CreateVerticalOffset(compilationParams);
            if (normalizedName.Equals("MADRIDTOED50POLYNOMIAL"))
                return CreateMadridToEd50Polynomial(compilationParams);
            if (normalizedName.Equals("SIMILARITYTRANSFORMATION"))
                return CreateSimilarityTransformation(compilationParams);
            if (normalizedName.Equals("AFFINEPARAMETRICTRANSFORMATION"))
                return CreateAffineParametricTransformation(compilationParams);
            if (normalizedName.Equals("GEOGRAPHIC3DTO2DCONVERSION") || normalizedName.Equals("GEOGRAPHIC2DTO3DCONVERSION"))
                return CreateGeographicDimensionChange(compilationParams);
            if (normalizedName.Equals("TUNISIAMININGGRID"))
                return CreateTunisiaMiningGrid(compilationParams);
            if (normalizedName.StartsWith("GEOCENTRICTOPOCENTRIC"))
                return CreateGeocentricTopocentric(compilationParams);
            if (normalizedName.StartsWith("GEOGRAPHICTOPOCENTRIC"))
                return CreateGeographicTopocentric(compilationParams);
            if (normalizedName.StartsWith("VERTICALPERSPECTIVE")) {
                return CreateVerticalPerspective(compilationParams);
            }
            return null;
        }
Exemplo n.º 5
0
        private static void ApplyParametersStere(ProjectionInfo result, IEnumerable<INamedParameter> parameters)
        {
            Contract.Requires(result != null);
            Contract.Requires(parameters != null);
            var lon0Param = new MultiParameterSelector(
                new CentralMeridianParameterSelector(),
                new LongitudeOfNaturalOriginParameterSelector(),
                new LongitudeOfCenterParameterSelector());
            var spParam = new MultiParameterSelector(
                new LatitudeOfTrueScaleParameterSelector(),
                new StandardParallelParameterSelector(),
                new LatitudeOfNaturalOriginParameterSelector(),
                new LatitudeOfCenterParameterSelector());
            var k0Param = new ScaleFactorParameterSelector();
            var x0Param = new FalseEastingParameterSelector();
            var y0Param = new FalseNorthingParameterSelector();

            var paramLookup = new NamedParameterLookup(parameters);
            paramLookup.Assign(lon0Param, spParam, k0Param, x0Param, y0Param);

            if (lon0Param.IsSelected)
                result.CentralMeridian = lon0Param.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);
            if (spParam.IsSelected)
                result.StandardParallel1 = spParam.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);
            if (k0Param.IsSelected)
                result.ScaleFactor = k0Param.GetValueAsDouble(ScaleUnitUnity.Value) ?? 1.0;
            if (x0Param.IsSelected)
                result.FalseEasting = x0Param.GetValueAsDouble(OgcLinearUnit.DefaultMeter);
            if (y0Param.IsSelected)
                result.FalseNorthing = y0Param.GetValueAsDouble(OgcLinearUnit.DefaultMeter);

            if (!result.LatitudeOfOrigin.HasValue && result.StandardParallel1.HasValue)
                result.LatitudeOfOrigin = result.StandardParallel1.GetValueOrDefault() >= 0 ? 90.0 : -90.0;
        }
Exemplo n.º 6
0
        private static void ApplyParametersDefault(ProjectionInfo result, IEnumerable<INamedParameter> parameters)
        {
            Contract.Requires(result != null);
            Contract.Requires(parameters != null);
            var lon0Param = new MultiParameterSelector(
                new CentralMeridianParameterSelector(),
                new LongitudeOfNaturalOriginParameterSelector()
            );
            var loncParam = new LongitudeOfCenterParameterSelector();
            var lat0Param = new MultiParameterSelector(
                new LatitudeOfCenterParameterSelector(),
                new LatitudeOfNaturalOriginParameterSelector());
            var lat1Param = new StandardParallelParameterSelector(1);
            var lat2Param = new StandardParallelParameterSelector(2);
            var x0Param = new FalseEastingParameterSelector();
            var y0Param = new FalseNorthingParameterSelector();
            var k0Param = new ScaleFactorParameterSelector();
            var alphaParam = new KeywordNamedParameterSelector("ALPHA", "AZIMUTH");
            var angleSkewParam = new KeywordNamedParameterSelector("SKEW", "GAMMA");
            var zoneParam = new FullMatchParameterSelector("ZONE");
            var southParam = new FullMatchParameterSelector("SOUTH");
            var standardParallel1Param = new MultiParameterSelector(
                new StandardParallelParameterSelector(),
                new StandardParallelParameterSelector(1));
            var standardParallel2Param = new StandardParallelParameterSelector(2);

            var paramLookup = new NamedParameterLookup(parameters);
            paramLookup.Assign(lon0Param, loncParam, lat0Param, lat1Param, lat2Param, x0Param, y0Param, k0Param, alphaParam, angleSkewParam, zoneParam, southParam, standardParallel1Param, standardParallel2Param);

            if (lon0Param.IsSelected)
                result.CentralMeridian = lon0Param.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);
            if (loncParam.IsSelected)
                result.LongitudeOfCenter = loncParam.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);
            if (lat0Param.IsSelected)
                result.LatitudeOfOrigin = lat0Param.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);
            if (lat1Param.IsSelected)
                result.StandardParallel1 = lat1Param.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);
            if (lat2Param.IsSelected)
                result.StandardParallel2 = lat2Param.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);
            if (x0Param.IsSelected)
                result.FalseEasting = x0Param.GetValueAsDouble(OgcLinearUnit.DefaultMeter);
            if (y0Param.IsSelected)
                result.FalseNorthing = y0Param.GetValueAsDouble(OgcLinearUnit.DefaultMeter);
            if (k0Param.IsSelected)
                result.ScaleFactor = k0Param.GetValueAsDouble(ScaleUnitUnity.Value) ?? 1.0;
            if (alphaParam.IsSelected)
                result.alpha = alphaParam.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);
            /*if (angleSkewParam.IsSelected)
                result.gamma = angleSkewParam.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);*/
            if (southParam.IsSelected)
                result.IsSouth = southParam.GetValueAsBoolean().GetValueOrDefault();
            if (standardParallel1Param.IsSelected)
                result.StandardParallel1 = standardParallel1Param.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);
            if (standardParallel2Param.IsSelected)
                result.StandardParallel2 = standardParallel2Param.GetValueAsDouble(OgcAngularUnit.DefaultDegrees);
            if (zoneParam.IsSelected)
                result.Zone = zoneParam.GetValueAsInt32();
        }
Exemplo n.º 7
0
        public static ProjectionInfo CreateProjection(ICrsProjected crsProjected)
        {
            if (crsProjected == null) throw new ArgumentNullException("crsProjected");
            Contract.Ensures(Contract.Result<ProjectionInfo>() != null);

            var result = ProjectionInfo.FromProj4String(String.Empty);

            result.Name = crsProjected.Name;

            if (crsProjected.Authority != null) {
                int epsgCode;
                if (crsProjected.Authority.Name == "EPSG" && Int32.TryParse(crsProjected.Authority.Code, out epsgCode))
                    result.EpsgCode = epsgCode;

                result.Authority = crsProjected.Authority.Name;
            }

            var geographicBase = (crsProjected.BaseCrs as ICrsGeodetic) ?? (crsProjected as ICrsGeodetic);
            if (geographicBase != null)
                result.GeographicInfo = Proj4CrsGeographic.CreateGeographic(geographicBase);

            var projectionInfo = crsProjected.Projection as IParameterizedCoordinateOperationInfo;

            if (projectionInfo == null)
                return result;

            var projectionMethod = projectionInfo.Method;
            if(projectionMethod == null)
                throw new InvalidOperationException("No projection method.");

            var proj4Name = ToProj4MethodName(projectionMethod.Name);

            IUnit geographicUnit = geographicBase == null ? null : geographicBase.Unit;
            IUnit projectionUnit = crsProjected.Unit;
            if (projectionUnit != null)
                result.Unit = Proj4LinearUnit.ConvertToProj4(projectionUnit);
            switch (proj4Name) {
                case "stere":
                    ApplyParametersStere(result, projectionInfo.Parameters);
                    break;
                default:
                    ApplyParametersDefault(result, projectionInfo.Parameters);
                    break;
            }

            if (result.Zone.HasValue && proj4Name == "tmerc")
                proj4Name = "utm";

            if (!TransformManager.Transforms.Exists(x => x.Proj4Name == proj4Name)) {
                if (GeodeticOperationNameRegex.IsMatch(proj4Name)) {
                    proj4Name = "longlat";
                }
                else {
                    throw new InvalidOperationException();
                }
            }

            switch (proj4Name) {
                case "omerc": {

                    var offsetXParam = new FalseEastingParameterSelector();
                    var offsetYParam = new FalseNorthingParameterSelector();
                    var xAtOriginParam = new EastingAtCenterParameterSelector();
                    var yAtOriginParam = new NorthingAtCenterParameterSelector();
                    var paramLookup = new NamedParameterLookup(projectionInfo.Parameters);
                    paramLookup.Assign(offsetXParam, offsetYParam, xAtOriginParam, yAtOriginParam);

                    if (offsetXParam.IsSelected || offsetYParam.IsSelected)
                        result.Transform = TransformManager.GetProjection("Hotine_Oblique_Mercator_Azimuth_Center");
                    else if(xAtOriginParam.IsSelected || yAtOriginParam.IsSelected)
                        result.Transform = TransformManager.GetProjection("Hotine_Oblique_Mercator_Azimuth_Natural_Origin");
                    else
                        result.Transform = TransformManager.GetProj4(proj4Name);

                    break;
                }
                default:
                    result.Transform = TransformManager.GetProj4(proj4Name);
                    break;
            }

            var finalResult = ProjectionInfo.FromProj4String(result.ToProj4String()); // TODO: fix this hack
            /*finalResult.CentralMeridian = result.CentralMeridian;
            finalResult.LongitudeOfCenter = result.LongitudeOfCenter;
            finalResult.LatitudeOfOrigin = result.LatitudeOfOrigin;
            finalResult.StandardParallel1 = result.StandardParallel1;
            finalResult.StandardParallel2 = result.StandardParallel2;
            finalResult.FalseEasting = result.FalseEasting;
            finalResult.FalseNorthing = result.FalseNorthing;
            finalResult.ScaleFactor = result.ScaleFactor;
            finalResult.alpha = result.alpha;
            finalResult.IsSouth = result.IsSouth;
            finalResult.Zone = result.Zone;
            finalResult.Unit = result.Unit;
            if (result.GeographicInfo == null) { // NOTE: this is all so terrible
                finalResult.GeographicInfo = null;
            }
            else {
                if (finalResult.GeographicInfo == null) {
                    finalResult.GeographicInfo = result.GeographicInfo;
                }
                else {
                    finalResult.GeographicInfo.Datum.Spheroid = result.GeographicInfo.Datum.Spheroid;
                }
            }*/
            return finalResult;
        }
        private ITransformation<GeographicCoordinate, Point2> CompileForwardToTransform(StaticCoordinateOperationCompiler.StepCompilationParameters stepParameters)
        {
            Contract.Requires(stepParameters != null);
            string operationName = null;
            IEnumerable<INamedParameter> parameters = null;

            var parameterizedOperation = stepParameters.CoordinateOperationInfo as IParameterizedCoordinateOperationInfo;
            if (null != parameterizedOperation) {
                if (null != parameterizedOperation.Method)
                    operationName = parameterizedOperation.Method.Name;
                parameters = parameterizedOperation.Parameters;
            }

            if (null == operationName)
                operationName = stepParameters.CoordinateOperationInfo.Name;

            Func<ProjectionCompilationParams, ITransformation<GeographicCoordinate, Point2>> projectionCompiler;
            if (String.IsNullOrEmpty(operationName) || !_transformationCreatorLookup.TryGetValue(operationName, out projectionCompiler) || null == projectionCompiler)
                return null;

            var parameterLookup = new NamedParameterLookup(parameters ?? Enumerable.Empty<INamedParameter>());
            var projectionCompilationParams = new ProjectionCompilationParams(stepParameters, parameterLookup, operationName);

            return projectionCompiler(projectionCompilationParams);
        }