public static SqlString ExportToKml(SqlGeography g) { if (g == null || g.IsNull) { return(new SqlString("")); } MemoryStream stream = new MemoryStream(); XmlWriter writer = XmlWriter.Create(stream); KeyholeMarkupLanguageGeography sink = new KeyholeMarkupLanguageGeography(writer); g.Populate(sink); sink.FinalizeKMLDocument(); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); byte[] ba = stream.ToArray(); char[] sData = System.Text.ASCIIEncoding.UTF8.GetChars(ba); string s = new string(sData); writer.Close(); // Removes everything before <?xml> if (s.IndexOf("<?xml>") > 0) { s = s.Remove(0, s.IndexOf("<?xml>")); } return(new SqlString(s)); }
public static SqlString ExportToKml(SqlGeography g) { if (g == null || g.IsNull) { return(new SqlString("")); } var stream = new MemoryStream(); var writer = XmlWriter.Create(stream); var sink = new KeyholeMarkupLanguageGeography(writer); g.Populate(sink); sink.FinalizeKMLDocument(); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); var ba = stream.ToArray(); var sData = System.Text.Encoding.UTF8.GetChars(ba); var str = new string(sData); writer.Close(); // Removes everything before <?xml> var xmlIndex = str.IndexOf("<?xml>", StringComparison.Ordinal); if (xmlIndex > 0) { str = str.Remove(0, xmlIndex); } return(new SqlString(str)); }