/// <summary> /// Parses the datum from the esri string /// </summary> /// <param name="esriString">The string to parse values from</param> public void ParseEsriString(string esriString) { if (string.IsNullOrEmpty(esriString)) { return; } if (esriString.Contains("DATUM") == false) { return; } int iStart = esriString.IndexOf("DATUM") + 7; int iEnd = esriString.IndexOf(@""",", iStart) - 1; if (iEnd < iStart) { return; } _name = esriString.Substring(iStart, iEnd - iStart + 1); var datumEntry = _datumsHandler.Value[_name]; if (datumEntry != null) { DatumType = datumEntry.Type; switch (DatumType) { case DatumType.Param3: { var transform = new double[3]; transform[0] = ParseDouble(datumEntry.P1); transform[1] = ParseDouble(datumEntry.P2); transform[2] = ParseDouble(datumEntry.P3); ToWGS84 = transform; } break; case DatumType.Param7: { double[] transform = new double[7]; transform[0] = ParseDouble(datumEntry.P1); transform[1] = ParseDouble(datumEntry.P2); transform[2] = ParseDouble(datumEntry.P3); transform[3] = ParseDouble(datumEntry.P4); transform[4] = ParseDouble(datumEntry.P5); transform[5] = ParseDouble(datumEntry.P6); transform[6] = ParseDouble(datumEntry.P7); ToWGS84 = transform; break; } case DatumType.GridShift: if (!string.IsNullOrEmpty(datumEntry.Shift)) { NadGrids = datumEntry.Shift.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); } break; } } _spheroid.ParseEsriString(esriString); }
/// <summary> /// parses the datum from the esri string /// </summary> /// <param name="esriString">The string to parse values from</param> public void ParseEsriString(string esriString) { if (System.String.IsNullOrEmpty(esriString)) { return; } if (esriString.Contains("DATUM") == false) { return; } int iStart = esriString.IndexOf("DATUM") + 7; int iEnd = esriString.IndexOf(@""",", iStart) - 1; if (iEnd < iStart) { return; } _name = esriString.Substring(iStart, iEnd - iStart + 1); Assembly currentAssembly = Assembly.GetExecutingAssembly(); string fileName = null; string currentAssemblyLocation = currentAssembly.Location; if (!String.IsNullOrEmpty(currentAssemblyLocation)) { fileName = Path.GetDirectoryName(currentAssemblyLocation) + "\\datums.xml"; } Stream datumStream = File.Exists(fileName) ? File.Open(fileName, FileMode.Open) : currentAssembly.GetManifestResourceStream("DotSpatial.Projections.XML.datums.xml"); if (datumStream != null) { XmlTextReader reader = new XmlTextReader(datumStream); while (reader.Read()) { if (reader.AttributeCount == 0) { continue; } reader.MoveToAttribute("Name"); if (reader.Value != _name) { continue; } reader.MoveToAttribute("Type"); if (string.IsNullOrEmpty(reader.Value)) { break; } DatumType = (DatumType)Enum.Parse(typeof(DatumType), reader.Value); switch (DatumType) { case DatumType.Param3: { double[] transform = new double[3]; for (int i = 0; i < 3; i++) { reader.MoveToAttribute("P" + (i + 1)); if (!string.IsNullOrEmpty(reader.Value)) { transform[i] = double.Parse(reader.Value, CultureInfo.InvariantCulture); } } ToWGS84 = transform; } break; case DatumType.Param7: { double[] transform = new double[7]; for (int i = 0; i < 7; i++) { reader.MoveToAttribute("P" + (i + 1)); if (!string.IsNullOrEmpty(reader.Value)) { transform[i] = double.Parse(reader.Value, CultureInfo.InvariantCulture); } } ToWGS84 = transform; break; } case DatumType.GridShift: reader.MoveToAttribute("Shift"); if (string.IsNullOrEmpty(reader.Value)) { continue; } NadGrids = reader.Value.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); break; } break; } } _spheroid.ParseEsriString(esriString); }