Пример #1
0
        private IReferenceSystem ResolveCoordinateReferenceSystem(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(GeographicCoordinateReferenceSystems.FromName("WGS84").FirstOrDefault());
            }

            IList <IReferenceSystem> systems = GeocentricCoordinateReferenceSystems.FromIdentifier(id).ToList <IReferenceSystem>();

            if (systems.Count > 0)
            {
                return(systems[0]);
            }

            systems = GeographicCoordinateReferenceSystems.FromIdentifier(id).ToList <IReferenceSystem>();
            if (systems.Count > 0)
            {
                return(systems[0]);
            }

            systems = GridReferenceSystems.FromIdentifier(id).ToList <IReferenceSystem>();
            if (systems.Count > 0)
            {
                return(systems[0]);
            }

            systems = ProjectedCoordinateReferenceSystems.FromIdentifier(id).ToList <IReferenceSystem>();
            if (systems.Count > 0)
            {
                return(systems[0]);
            }

            systems = VerticalCoordinateReferenceSystems.FromIdentifier(id).ToList <IReferenceSystem>();
            if (systems.Count > 0)
            {
                return(systems[0]);
            }

            return(GeographicCoordinateReferenceSystems.FromName("WGS84").FirstOrDefault());
        }
Пример #2
0
        /// <summary>
        /// Determines the ReferenceSystem from the Crs object.
        /// </summary>
        /// <param name="obj">The input crs object.</param>
        /// <returns>The determined ReferenceSystem.</returns>
        private IReferenceSystem GetReferenceSystem(CrsObject obj)
        {
            if (obj == null)
            {
                return(GeographicCoordinateReferenceSystems.FromName("WGS84").FirstOrDefault());
            }

            if (obj.Type == "name")
            {
                if (obj.Properties.ContainsKey("name"))
                {
                    IList <IReferenceSystem> systems = GeocentricCoordinateReferenceSystems.FromIdentifier(obj.Properties["name"]).ToList <IReferenceSystem>();
                    if (systems.Count > 0)
                    {
                        return(systems[0]);
                    }

                    systems = GeographicCoordinateReferenceSystems.FromIdentifier(obj.Properties["name"]).ToList <IReferenceSystem>();
                    if (systems.Count > 0)
                    {
                        return(systems[0]);
                    }

                    systems = GridReferenceSystems.FromIdentifier(obj.Properties["name"]).ToList <IReferenceSystem>();
                    if (systems.Count > 0)
                    {
                        return(systems[0]);
                    }

                    systems = ProjectedCoordinateReferenceSystems.FromIdentifier(obj.Properties["name"]).ToList <IReferenceSystem>();
                    if (systems.Count > 0)
                    {
                        return(systems[0]);
                    }

                    systems = VerticalCoordinateReferenceSystems.FromIdentifier(obj.Properties["name"]).ToList <IReferenceSystem>();
                    if (systems.Count > 0)
                    {
                        return(systems[0]);
                    }

                    throw new NotSupportedException("Not supported Coordinate Reference System: " + obj.Properties["name"]);
                }
                else
                {
                    throw new IOException("Named Crs must have a \"name\" property with string value.");
                }
            }
            else if (obj.Type == "link")
            {
                if (obj.Properties.ContainsKey("href"))
                {
                    if (!obj.Properties.ContainsKey("type") || obj.Properties.ContainsKey("type") && obj.Properties["type"] == "esriwkt")
                    {
                        return(ReadReferenceSystemFromFile(obj.Properties["href"]));
                    }

                    else
                    {
                        throw new NotSupportedException("The given Reference System type is not supported.");
                    }
                }
                else
                {
                    throw new InvalidDataException("Linked Crs must have an \"href\" property with string value.");
                }
            }
            else
            {
                throw new NotSupportedException("Not supported Coordinate Reference System type: " + obj.Type);
            }
        }