예제 #1
0
        /// <summary>
        /// Constructs a new projected CRS.
        /// </summary>
        /// <param name="name">The name of the CRS.</param>
        /// <param name="baseCrs">The CRS this CRS is based on.</param>
        /// <param name="projection">The projection operation.</param>
        /// <param name="linearUnit">The linear unit of the projection.</param>
        /// <param name="axes">The axes of the projected CRS.</param>
        /// <param name="authority">The authority.</param>
        public OgcCrsProjected(
            string name,
            ICrsGeodetic baseCrs,
            ICoordinateOperationInfo projection,
            IUnit linearUnit,
            IEnumerable <IAxis> axes,
            IAuthorityTag authority = null
            )
            : base(name, authority)
        {
            if (null == baseCrs)
            {
                throw new ArgumentNullException("baseCrs");
            }
            if (null == projection)
            {
                throw new ArgumentNullException("projection");
            }
            if (null == linearUnit)
            {
                throw new ArgumentNullException("linearUnit");
            }
            if (null == axes)
            {
                throw new ArgumentNullException("axes");
            }
            Contract.Requires(name != null);

            BaseCrs    = baseCrs;
            Projection = projection;
            Unit       = linearUnit;
            Axes       = Array.AsReadOnly(null == axes ? new IAxis[0] : axes.ToArray());
        }
예제 #2
0
        public void WriteCrs(ICrsGeodetic entity, WktKeyword keyword)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            Contract.EndContractBlock();
            Write(keyword);
            WriteOpenParenthesis();
            WriteQuoted(entity.Name);
            Indent();

            StartNextLineParameter();
            Write(entity.Datum);

            StartNextLineParameter();
            var primeMeridian = entity.Datum.PrimeMeridian;

            if (primeMeridian != null)
            {
                Write(entity.Datum.PrimeMeridian);
            }

            StartNextLineParameter();
            Write(entity.Unit);

            foreach (var axis in entity.Axes)
            {
                StartNextLineParameter();
                if (axis != null)
                {
                    Write(axis);
                }
            }

            if (null != entity.Authority)
            {
                StartNextLineParameter();
                Write(entity.Authority);
            }

            UnIndent();
            WriteCloseParenthesis();
        }
예제 #3
0
        public static GeographicInfo CreateGeographic(ICrsGeodetic crsGeodetic)
        {
            if (crsGeodetic == null)
            {
                throw new ArgumentNullException("crsGeodetic");
            }
            Contract.Requires(crsGeodetic.Datum.PrimeMeridian != null);
            Contract.Ensures(Contract.Result <GeographicInfo>() != null);

            var result = new GeographicInfo {
                Name = crsGeodetic.Name
            };

            result.Datum = Proj4DatumWrapper.Create(crsGeodetic.Datum);

            Contract.Assume(crsGeodetic.Datum.PrimeMeridian != null);
            result.Meridian = Proj4MeridianWrapper.Create(crsGeodetic.Datum.PrimeMeridian);

            // TODO: set the unit

            return(result);
        }
예제 #4
0
        private ICoordinateOperationCrsPathInfo GenerateCoreProjectedLevel(ICrsGeodetic from, ICrsGeodetic to)
        {
            Contract.Requires(from != null);
            Contract.Requires(to != null);

            var unProjectFromPath   = FindPathToNonProjectedFromCrs(from);
            var unProjectedFromNode = unProjectFromPath.To as ICrsGeodetic;

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

            var projectToPath     = FindPathFromNonProjectedToCrs(to);
            var unProjectedToNode = projectToPath.From as ICrsGeodetic;

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

            var geocentricShiftPath = GenerateCoreDatumShift(unProjectedFromNode, unProjectedToNode);

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

            var nodes = unProjectFromPath.CoordinateReferenceSystems.ToList();

            nodes.AddRange(geocentricShiftPath.CoordinateReferenceSystems.Skip(1));
            nodes.AddRange(projectToPath.CoordinateReferenceSystems.Skip(1));
            var operations = unProjectFromPath.CoordinateOperations.ToList();

            operations.AddRange(geocentricShiftPath.CoordinateOperations);
            operations.AddRange(projectToPath.CoordinateOperations);

            return(new CoordinateOperationCrsPathInfo(nodes, operations));
        }
예제 #5
0
        private ICoordinateOperationCrsPathInfo GenerateCoreDatumShift(ICrsGeodetic from, ICrsGeodetic to)
        {
            Contract.Requires(from != null);
            Contract.Requires(to != null);

            var fromGeographic = from as ICrsGeographic;
            var toGeographic   = to as ICrsGeographic;

            if (fromGeographic != null)
            {
                if (toGeographic != null)
                {
                    return(GenerateCoreDatumShiftGeographic(fromGeographic, toGeographic));
                }
                var toGeocentric = to as ICrsGeocentric;
                if (toGeocentric != null)
                {
                    return(GenerateCoreDatumShift(fromGeographic, toGeocentric));
                }
            }

            var fromGeocentric = from as ICrsGeocentric;

            if (fromGeocentric != null)
            {
                if (toGeographic != null)
                {
                    return(GenerateCoreDatumShift(fromGeocentric, toGeographic));
                }
                var toGeocentric = to as ICrsGeocentric;
                if (toGeocentric != null)
                {
                    return(GenerateCoreDatumShiftGeocentric(fromGeocentric, toGeocentric));
                }
            }

            return(null);
        }
예제 #6
0
        public ICrsProjected ReadProjectedCsFromParams()
        {
            IAuthorityTag authority = null;
            string        name      = null;
            ICrsGeodetic  baseCrs   = null;
            ICoordinateOperationMethodInfo operationMethodInfo = null;
            var   operationParameters = new List <INamedParameter>();
            IUnit linearUnit          = null;
            var   axes = new List <IAxis>();

            foreach (var parameter in ReadParams())
            {
                if (parameter is string)
                {
                    name = (string)parameter;
                }
                else if (parameter is ICrsGeodetic)
                {
                    baseCrs = (ICrsGeodetic)parameter;
                }
                else if (parameter is ICoordinateOperationMethodInfo)
                {
                    operationMethodInfo = (ICoordinateOperationMethodInfo)parameter;
                }
                else if (parameter is INamedParameter)
                {
                    operationParameters.Add((INamedParameter)parameter);
                }
                else if (parameter is IUnit)
                {
                    linearUnit = (IUnit)parameter;
                }
                else if (parameter is IAxis)
                {
                    axes.Add((IAxis)parameter);
                }
                else if (parameter is IAuthorityTag)
                {
                    authority = (IAuthorityTag)parameter;
                }
            }

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

            if (null == baseCrs)
            {
                if (Options.ThrowOnError)
                {
                    throw new WktParseExceptioncs("Project CRS", "No base CRS.");
                }
                return(null);
            }

            return(new OgcCrsProjected(
                       name ?? String.Empty,
                       baseCrs,
                       new CoordinateOperationInfo(
                           null == operationMethodInfo ? String.Empty : FixName(operationMethodInfo.Name),
                           operationParameters,
                           operationMethodInfo
                           ),
                       linearUnit ?? OgcLinearUnit.DefaultMeter,
                       axes,
                       authority
                       ));
        }
예제 #7
0
        public static GeographicInfo CreateGeographic(ICrsGeodetic crsGeodetic)
        {
            if (crsGeodetic == null) throw new ArgumentNullException("crsGeodetic");
            Contract.Requires(crsGeodetic.Datum.PrimeMeridian != null);
            Contract.Ensures(Contract.Result<GeographicInfo>() != null);

            var result = new GeographicInfo {
                Name = crsGeodetic.Name
            };

            result.Datum = Proj4DatumWrapper.Create(crsGeodetic.Datum);

            Contract.Assume(crsGeodetic.Datum.PrimeMeridian != null);
            result.Meridian = Proj4MeridianWrapper.Create(crsGeodetic.Datum.PrimeMeridian);

            // TODO: set the unit

            return result;
        }