Ejemplo n.º 1
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='query'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <IList <CrsRecord> > GetByqueryAsync(this ICrs operations, string query, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.GetByqueryWithHttpMessagesAsync(query, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 public CoordinateOperationCrsPathInfo(ICrs node)
 {
     if(node == null) throw new ArgumentNullException("node");
     Contract.EndContractBlock();
     CrsNodesArray = new[] { node };
     OperationEdgesArray = new ICoordinateOperationInfo[0];
 }
Ejemplo n.º 3
0
        public static EpsgCrs GetEpsgCrs(ICrs crs)
        {
            Contract.Requires(crs != null);
            var result = crs as EpsgCrs;

            if (result != null)
            {
                return(result);
            }

            var authorityTag = crs.Authority;

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

            EpsgAuthorityTag epsgTag;

            if (EpsgAuthorityTag.TryConvert(authorityTag, out epsgTag))
            {
                return(EpsgMicroDatabase.Default.GetCrs(epsgTag.NumericalCode));
            }

            return(null);
        }
Ejemplo n.º 4
0
        public static IUnit ExtractUnit(ICrs crs)
        {
            var crsGeodetic = crs as ICrsGeodetic;

            if (null != crsGeodetic)
            {
                return(crsGeodetic.Unit);
            }
            var crsVertical = crs as ICrsVertical;

            if (null != crsVertical)
            {
                return(crsVertical.Unit);
            }
            var crsFitted = crs as ICrsFitted;

            if (null != crsFitted)
            {
                return(ExtractUnit(crsFitted.BaseCrs));
            }
            var crsLocal = crs as ICrsLocal;

            if (null != crsLocal)
            {
                return(crsLocal.Unit);
            }
            return(null);
        }
 private CoordinateOperationCrsPathInfo(ICrs[] nodes, ICoordinateOperationInfo[] edges)
 {
     Contract.Requires(nodes != null);
     Contract.Requires(edges != null);
     CrsNodesArray = nodes;
     OperationEdgesArray = edges;
     if ((OperationEdgesArray.Length + 1) != CrsNodesArray.Length)
         throw new ArgumentException("There must be exactly one more node than edge.");
 }
 public static ISpheroidInfo ExtractSpheroid(ICrs crs)
 {
     var geodetic = crs as ICrsGeodetic;
     if (null == geodetic)
         return null;
     var datum = geodetic.Datum;
     if (null == datum)
         return null;
     return datum.Spheroid;
 }
 public CoordinateOperationCrsPathInfo(ICrs node)
 {
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     Contract.EndContractBlock();
     CrsNodesArray       = new[] { node };
     OperationEdgesArray = new ICoordinateOperationInfo[0];
 }
Ejemplo n.º 8
0
 public Proj4Transform(ICrs source, ICrs target)
 {
     if (source == null) throw new ArgumentNullException("source");
     if (target == null) throw new ArgumentNullException("target");
     Contract.EndContractBlock();
     Source = source;
     Target = target;
     SourceProj4 = Proj4Crs.CreateProjection(source);
     TargetProj4 = Proj4Crs.CreateProjection(target);
 }
 public ICoordinateOperationCrsPathInfo Generate(ICrs from, ICrs to)
 {
     if (from is EpsgCrs && to is EpsgCrs)
     {
         return(Generate(from as EpsgCrs, to as EpsgCrs));
     }
     // TODO: if one is not an EpsgCrs we should try making it one (but really it should already have been... so maybe not)
     // TODO: if one is EpsgCrs and the other is not, we need to find the nearest EpsgCrs along the way and use standard methods to get us there
     throw new NotImplementedException("Currently only 'EpsgCrs' to 'EpsgCrs' is supported."); // TODO: just return null if we don't know what to do with it?
 }
Ejemplo n.º 10
0
        public static ProjectionInfo CreateProjection(ICrs crs)
        {
            var projectedCrs = crs as ICrsProjected;
            if (projectedCrs != null)
                return Proj4CrsProjected.CreateProjection(projectedCrs);
            var geographicCrs = crs as ICrsGeographic;
            if (geographicCrs != null)
                return Proj4CrsGeographic.CreateProjection(geographicCrs);

            throw new NotSupportedException();
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates a new compound CRS.
 /// </summary>
 /// <param name="name">The name of the compound.</param>
 /// <param name="head">The head CRS.</param>
 /// <param name="tail">The tail CRS.</param>
 /// <param name="authority">The authority.</param>
 public OgcCrsCompound(
     string name,
     ICrs head,
     ICrs tail,
     IAuthorityTag authority
     )
     : base(name, authority)
 {
     if(null == head) throw new ArgumentNullException("head");
     if(null == tail) throw new ArgumentNullException("tail");
     Contract.Requires(name != null);
     Head = head;
     Tail = tail;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Constructs a new fitted CRS.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="toBaseOperation">The operation which converts to <paramref name="baseCrs"/>.</param>
 /// <param name="baseCrs">The base CRS.</param>
 /// <param name="authority">The authority code of the CRS.</param>
 public OgcCrsFitted(
     string name,
     ICoordinateOperationInfo toBaseOperation,
     ICrs baseCrs,
     IAuthorityTag authority = null
     )
     : base(name, authority)
 {
     if (null == toBaseOperation) throw new ArgumentNullException("toBaseOperation");
     if (null == baseCrs) throw new ArgumentNullException("baseCrs");
     Contract.Requires(name != null);
     ToBaseOperation = toBaseOperation;
     BaseCrs = baseCrs;
 }
 public static CoordinateOperationCrsPathInfo Join(CoordinateOperationCrsPathInfo primary, CoordinateOperationCrsPathInfo other)
 {
     if (primary == null) throw new ArgumentNullException("primary");
     if (other == null) throw new ArgumentNullException("other");
     Contract.Ensures(Contract.Result<CoordinateOperationCrsPathInfo>() != null);
     // TODO: make sure that the last node of the first list and the first node of the last list are a match
     var nodes = new ICrs[primary.CrsNodesArray.Length + other.CrsNodesArray.Length - 1];
     primary.CrsNodesArray.CopyTo(nodes, 0);
     other.CrsNodesArray.CopyTo(nodes, primary.CrsNodesArray.Length - 1);
     var edges = new ICoordinateOperationInfo[primary.OperationEdgesArray.Length + other.OperationEdgesArray.Length];
     primary.OperationEdgesArray.CopyTo(edges, 0);
     other.OperationEdgesArray.CopyTo(edges, primary.OperationEdgesArray.Length);
     return new CoordinateOperationCrsPathInfo(nodes, edges);
 }
 public static IUnit ExtractUnit(ICrs crs)
 {
     var crsGeodetic = crs as ICrsGeodetic;
     if (null != crsGeodetic)
         return crsGeodetic.Unit;
     var crsVertical = crs as ICrsVertical;
     if (null != crsVertical)
         return crsVertical.Unit;
     var crsFitted = crs as ICrsFitted;
     if (null != crsFitted)
         return ExtractUnit(crsFitted.BaseCrs);
     var crsLocal = crs as ICrsLocal;
     if (null != crsLocal)
         return crsLocal.Unit;
     return null;
 }
Ejemplo n.º 15
0
 public Proj4Transform(ICrs source, ICrs target)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     Contract.EndContractBlock();
     Source      = source;
     Target      = target;
     SourceProj4 = Proj4Crs.CreateProjection(source);
     TargetProj4 = Proj4Crs.CreateProjection(target);
 }
Ejemplo n.º 16
0
        public static ISpheroidInfo ExtractSpheroid(ICrs crs)
        {
            var geodetic = crs as ICrsGeodetic;

            if (null == geodetic)
            {
                return(null);
            }
            var datum = geodetic.Datum;

            if (null == datum)
            {
                return(null);
            }
            return(datum.Spheroid);
        }
Ejemplo n.º 17
0
        public static ProjectionInfo CreateProjection(ICrs crs)
        {
            var projectedCrs = crs as ICrsProjected;

            if (projectedCrs != null)
            {
                return(Proj4CrsProjected.CreateProjection(projectedCrs));
            }
            var geographicCrs = crs as ICrsGeographic;

            if (geographicCrs != null)
            {
                return(Proj4CrsGeographic.CreateProjection(geographicCrs));
            }

            throw new NotSupportedException();
        }
Ejemplo n.º 18
0
        private ICrsFitted ReadFittedCsFromParams()
        {
            var name = String.Empty;
            ICoordinateOperationInfo toBaseOperation = null;
            ICrs baseCrs = null;

            foreach (var parameter in ReadParams())
            {
                if (parameter is string)
                {
                    name = (string)parameter;
                }
                else if (parameter is ICoordinateOperationInfo)
                {
                    toBaseOperation = (ICoordinateOperationInfo)parameter;
                }
                else if (parameter is ICrs)
                {
                    baseCrs = (ICrs)parameter;
                }
            }

            if (baseCrs == null)
            {
                if (Options.ThrowOnError)
                {
                    throw new WktParseExceptioncs("Fitted CS", "No base CRS.");
                }
                return(null);
            }
            if (toBaseOperation == null)
            {
                if (Options.ThrowOnError)
                {
                    throw new WktParseExceptioncs("Fitted CS", "No to-base operation.");
                }
                return(null);
            }

            return(new OgcCrsFitted(
                       name,
                       toBaseOperation,
                       baseCrs
                       ));
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Creates a new compound CRS.
 /// </summary>
 /// <param name="name">The name of the compound.</param>
 /// <param name="head">The head CRS.</param>
 /// <param name="tail">The tail CRS.</param>
 /// <param name="authority">The authority.</param>
 public OgcCrsCompound(
     string name,
     ICrs head,
     ICrs tail,
     IAuthorityTag authority
     )
     : base(name, authority)
 {
     if (null == head)
     {
         throw new ArgumentNullException("head");
     }
     if (null == tail)
     {
         throw new ArgumentNullException("tail");
     }
     Contract.Requires(name != null);
     Head = head;
     Tail = tail;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Constructs a new fitted CRS.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="toBaseOperation">The operation which converts to <paramref name="baseCrs"/>.</param>
 /// <param name="baseCrs">The base CRS.</param>
 /// <param name="authority">The authority code of the CRS.</param>
 public OgcCrsFitted(
     string name,
     ICoordinateOperationInfo toBaseOperation,
     ICrs baseCrs,
     IAuthorityTag authority = null
     )
     : base(name, authority)
 {
     if (null == toBaseOperation)
     {
         throw new ArgumentNullException("toBaseOperation");
     }
     if (null == baseCrs)
     {
         throw new ArgumentNullException("baseCrs");
     }
     Contract.Requires(name != null);
     ToBaseOperation = toBaseOperation;
     BaseCrs         = baseCrs;
 }
Ejemplo n.º 21
0
        public IEnumerable <ICoordinateOperationCrsPathInfo> Generate(ICrs from, ICrs to)
        {
            if (from == null || to == null)
            {
                return(Enumerable.Empty <ICoordinateOperationCrsPathInfo>());
            }

            var fromEpsg = GetEpsgCrs(from);
            var toEpsg   = GetEpsgCrs(to);

            if (fromEpsg != null && toEpsg != null)
            {
                return(Generate(fromEpsg, toEpsg));
            }

            // TODO: if one of the CRSs is not an EpsgCrs while the other is not, no indirect operations can be used as WGS84 will be required to bridge them
            // TODO: force and indirect path between ICrs->WGS84->EpsgCrs or EpsgCrs->WGS84->ICrs

            return(Enumerable.Empty <ICoordinateOperationCrsPathInfo>());
        }
        public CoordinateOperationCrsPathInfo Append(ICrs node, ICoordinateOperationInfo edge)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (edge == null)
            {
                throw new ArgumentNullException("edge");
            }
            Contract.Ensures(Contract.Result <CoordinateOperationCrsPathInfo>() != null);
            var nodes = new ICrs[CrsNodesArray.Length + 1];

            CrsNodesArray.CopyTo(nodes, 0);
            nodes[nodes.Length - 1] = node;
            var edges = new ICoordinateOperationInfo[OperationEdgesArray.Length + 1];

            OperationEdgesArray.CopyTo(edges, 0);
            edges[edges.Length - 1] = edge;
            return(new CoordinateOperationCrsPathInfo(nodes, edges));
        }
Ejemplo n.º 23
0
 public void Write(ICrs entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     Contract.EndContractBlock();
     if (entity is ICrsCompound)
     {
         Write(entity as ICrsCompound);
     }
     else if (entity is ICrsProjected)
     {
         Write(entity as ICrsProjected);
     }
     else if (entity is ICrsGeocentric)
     {
         WriteCrs(entity as ICrsGeocentric, WktKeyword.GeocentricCs);
     }
     else if (entity is ICrsGeographic)
     {
         WriteCrs(entity as ICrsGeographic, WktKeyword.GeographicCs);
     }
     else if (entity is ICrsVertical)
     {
         Write(entity as ICrsVertical);
     }
     else if (entity is ICrsLocal)
     {
         Write(entity as ICrsLocal);
     }
     else if (entity is ICrsFitted)
     {
         Write(entity as ICrsFitted);
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Ejemplo n.º 24
0
            public StepCompilationParameters(
                ICoordinateOperationInfo coordinateOperationInfo,
                IUnit inputUnit,
                ICrs relatedInputCrs,
                ICrs relatedOutputCrs
                )
            {
                if (null == coordinateOperationInfo)
                {
                    throw new ArgumentNullException("coordinateOperationInfo");
                }
                if (null == inputUnit)
                {
                    throw new ArgumentNullException("inputUnit");
                }
                Contract.EndContractBlock();

                CoordinateOperationInfo = coordinateOperationInfo;
                InputUnit        = inputUnit;
                RelatedInputCrs  = relatedInputCrs;
                RelatedOutputCrs = relatedOutputCrs;
            }
        public static CoordinateOperationCrsPathInfo Join(CoordinateOperationCrsPathInfo primary, CoordinateOperationCrsPathInfo other)
        {
            if (primary == null)
            {
                throw new ArgumentNullException("primary");
            }
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }
            Contract.Ensures(Contract.Result <CoordinateOperationCrsPathInfo>() != null);
            // TODO: make sure that the last node of the first list and the first node of the last list are a match
            var nodes = new ICrs[primary.CrsNodesArray.Length + other.CrsNodesArray.Length - 1];

            primary.CrsNodesArray.CopyTo(nodes, 0);
            other.CrsNodesArray.CopyTo(nodes, primary.CrsNodesArray.Length - 1);
            var edges = new ICoordinateOperationInfo[primary.OperationEdgesArray.Length + other.OperationEdgesArray.Length];

            primary.OperationEdgesArray.CopyTo(edges, 0);
            other.OperationEdgesArray.CopyTo(edges, primary.OperationEdgesArray.Length);
            return(new CoordinateOperationCrsPathInfo(nodes, edges));
        }
Ejemplo n.º 26
0
        public ICrsCompound ReadCompoundCsFromParams()
        {
            IAuthorityTag authority = null;
            ICrs          headCrs   = null;
            ICrs          tailCrs   = null;
            string        name      = String.Empty;

            foreach (var parameter in ReadParams())
            {
                if (parameter is IAuthorityTag)
                {
                    if (null == authority)
                    {
                        authority = (IAuthorityTag)parameter;
                    }
                }
                else if (parameter is ICrs)
                {
                    if (null == headCrs)
                    {
                        headCrs = (ICrs)parameter;
                    }
                    else if (null == tailCrs)
                    {
                        tailCrs = (ICrs)parameter;
                    }
                }
                else if (parameter is string)
                {
                    name = (string)parameter;
                }
            }

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

            if (headCrs == null)
            {
                if (Options.ThrowOnError)
                {
                    throw new WktParseExceptioncs("Compoint CRS", "No head CRS.");
                }
                return(null);
            }
            if (tailCrs == null)
            {
                if (Options.ThrowOnError)
                {
                    throw new WktParseExceptioncs("Compoint CRS", "No tail CRS.");
                }
                return(null);
            }

            return(new OgcCrsCompound(
                       name,
                       headCrs,
                       tailCrs,
                       authority
                       ));
        }
            public StepCompilationParameters(
                ICoordinateOperationInfo coordinateOperationInfo,
                IUnit inputUnit,
                ICrs relatedInputCrs,
                ICrs relatedOutputCrs
            )
            {
                if (null == coordinateOperationInfo) throw new ArgumentNullException("coordinateOperationInfo");
                if (null == inputUnit) throw new ArgumentNullException("inputUnit");
                Contract.EndContractBlock();

                CoordinateOperationInfo = coordinateOperationInfo;
                InputUnit = inputUnit;
                RelatedInputCrs = relatedInputCrs;
                RelatedOutputCrs = relatedOutputCrs;
            }
Ejemplo n.º 28
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='query'>
 /// </param>
 public static IList <CrsRecord> GetByquery(this ICrs operations, string query)
 {
     return(Task.Factory.StartNew(s => ((ICrs)s).GetByqueryAsync(query), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 public CoordinateOperationCrsPathInfo Append(ICrs node, ICoordinateOperationInfo edge)
 {
     if(node == null) throw new ArgumentNullException("node");
     if(edge == null) throw new ArgumentNullException("edge");
     Contract.Ensures(Contract.Result<CoordinateOperationCrsPathInfo>() != null);
     var nodes = new ICrs[CrsNodesArray.Length + 1];
     CrsNodesArray.CopyTo(nodes, 0);
     nodes[nodes.Length - 1] = node;
     var edges = new ICoordinateOperationInfo[OperationEdgesArray.Length + 1];
     OperationEdgesArray.CopyTo(edges, 0);
     edges[edges.Length - 1] = edge;
     return new CoordinateOperationCrsPathInfo(nodes, edges);
 }