/// <summary> /// Computes the Geodetic coordinate reference system. /// </summary> /// <returns>The Geodetic coordinate reference system.</returns> /// <exception cref="System.IO.InvalidDataException">Geodetic coordinate reference system code is invalid.</exception> private GeographicCoordinateReferenceSystem ComputeGeodeticCoordinateReferenceSystem() { Int32 code = Convert.ToInt32(_currentGeoKeys[GeoKey.GeodeticCoordinateReferenceSystemType]); // EPSG geodetic coordinate reference system codes if (code < 32767) { GeographicCoordinateReferenceSystem referenceSystem = GeographicCoordinateReferenceSystems.FromIdentifier("EPSG::" + code).FirstOrDefault(); if (referenceSystem == null) { return(new GeographicCoordinateReferenceSystem("EPSG::" + code, "undefined", CoordinateSystems.EllipsoidalLatLonD, GeodeticDatums.WGS84, AreasOfUse.World)); } return(referenceSystem); } // user-defined geodetic coordinate reference system if (code == Int16.MaxValue) { String citation = _currentGeoKeys[GeoKey.GeodeticCoordinateReferenceSystemCitation].ToString(); GeodeticDatum datum = ComputeGeodeticDatum(); UnitOfMeasurement angleUnit = ComputeAngularUnit(); CoordinateSystem coordinateSystem = new CoordinateSystem(CoordinateSystem.UserDefinedIdentifier, CoordinateSystem.UserDefinedName, CoordinateSystemType.Ellipsoidal, CoordinateSystemAxisFactory.GeodeticLatitude(angleUnit), CoordinateSystemAxisFactory.GeodeticLongitude(angleUnit)); return(new GeographicCoordinateReferenceSystem(GeographicCoordinateReferenceSystem.UserDefinedIdentifier, GeographicCoordinateReferenceSystem.UserDefinedName, citation, null, null, coordinateSystem, datum, null)); } throw new InvalidDataException("Geodetic coordinate reference system code is invalid."); }
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()); }
/// <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); } }