/// <summary> /// Computes the projected coordinate reference system. /// </summary> /// <returns>The projected coordinate reference system.</returns> /// <exception cref="System.IO.InvalidDataException">Projected coordinate reference system code is invalid.</exception> private ProjectedCoordinateReferenceSystem ComputeProjectedCoordinateReferenceSystem() { Int32 code = Convert.ToInt32(_currentGeoKeys[GeoKey.ProjectedCoordinateReferenceSystemType]); // EPSG Projected Coordinate Reference System codes if (code < 32767) { ProjectedCoordinateReferenceSystem referenceSystem = ProjectedCoordinateReferenceSystems.FromIdentifier("EPSG::" + code).FirstOrDefault(); if (referenceSystem == null) { return(new ProjectedCoordinateReferenceSystem("EPSG::" + code, "undefined", Geographic2DCoordinateReferenceSystems.WGS84, CoordinateSystems.CartesianENM, AreasOfUse.World, null)); } return(referenceSystem); } // user-defined Projected Coordinate Reference System if (code == Int16.MaxValue) { GeographicCoordinateReferenceSystem baseReferenceSystem = ComputeGeodeticCoordinateReferenceSystem(); CoordinateProjection projection = ComputeProjection(baseReferenceSystem.Datum.Ellipsoid); return(new ProjectedCoordinateReferenceSystem(ProjectedCoordinateReferenceSystem.UserDefinedIdentifier, ProjectedCoordinateReferenceSystem.UserDefinedName, baseReferenceSystem, CoordinateSystems.CartesianENM, baseReferenceSystem.AreaOfUse, projection)); } throw new InvalidDataException("Projected coordinate reference system code is invalid."); }
/// <summary> /// Reads the reference system stored in the metafile stream. /// </summary> /// <returns>The reference system.</returns> protected override IReferenceSystem ReadReferenceSystemInternal() { IReferenceSystem referenceSystem = null; XElement referenceSystemElement = _document.Element("Dimap_Document").Element("Coordinate_Reference_System"); if (referenceSystemElement == null) { return(null); } // horizontal reference system based on type XElement codeElement = referenceSystemElement.Element("Horizontal_CS").Element("HORIZONTAL_CS_CODE"); XElement nameElement = referenceSystemElement.Element("Horizontal_CS").Element("HORIZONTAL_CS_NAME"); switch (referenceSystemElement.Element("Horizontal_CS").Element("HORIZONTAL_CS_TYPE").Value) { case "GEOGRAPHIC": if (codeElement == null) { codeElement = referenceSystemElement.Element("Horizontal_CS").Element("Geographic_CS").Element("GEOGRAPHIC_CS_CODE"); } if (nameElement == null) { nameElement = referenceSystemElement.Element("Horizontal_CS").Element("Geographic_CS").Element("GEOGRAPHIC_CS_NAME"); } if (codeElement != null) { referenceSystem = Geographic2DCoordinateReferenceSystems.FromIdentifier(codeElement.Value).FirstOrDefault(); } if (referenceSystem == null && nameElement != null) { referenceSystem = Geographic2DCoordinateReferenceSystems.FromName(nameElement.Value).FirstOrDefault(); } // TODO: process custom datums break; case "PROJECTED": if (codeElement != null) { referenceSystem = ProjectedCoordinateReferenceSystems.FromIdentifier(codeElement.Value).FirstOrDefault(); } if (referenceSystem == null && nameElement != null) { referenceSystem = ProjectedCoordinateReferenceSystems.FromName(nameElement.Value).FirstOrDefault(); } // TODO: process custom projections break; // TODO: process other horizontal reference system information } // TODO: process vertical reference system information return(referenceSystem); }
/// <summary> /// Reads the reference system stored in the metafile stream. /// </summary> /// <returns>The reference system.</returns> protected override IReferenceSystem ReadReferenceSystemInternal() { ReadContent(); if (_metadata.ContainsKey("MAP_PROJECTION")) { return(ProjectedCoordinateReferenceSystems.FromName(_metadata["MAP_PROJECTION"]).FirstOrDefault()); } return(Geographic2DCoordinateReferenceSystems.FromName(_metadata["DATUM"]).FirstOrDefault()); }
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); } }