private void CheckEqual(KMLWriter writer, IGeometry geom, string expected) { string actual = writer.Write(geom); string actualNorm = normalizeKML(actual); string expectedNorm = normalizeKML(expected); bool isEqual = string.Equals(actualNorm, expectedNorm, StringComparison.OrdinalIgnoreCase); Assert.IsTrue(isEqual, string.Format("\nGenerated KML: {0}\n Expected KML: {1}", actualNorm, expectedNorm)); }
public static void WriteFeaturesToKML(string path, List <Feature> features) { string filename = path + "KMLFeatures" + ".kml"; string header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; string documentOpen = "<Document>\n"; string xmlns = "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"; string placemarkOpen = "<Placemark>\n"; string placemarkClose = "</Placemark>\n"; string documentClose = "</Document>\n"; string kmlClose = "</kml>\n"; KMLWriter writer = new KMLWriter(); StringBuilder sb = new StringBuilder(); string[] title = new string[features.Count]; string[] description = new string[features.Count]; for (int i = 0; i < features.Count; ++i) { sb.Append(placemarkOpen); sb.Append("<name>" + features[i].Attributes["Title"].ToString() + "</name>\n"); sb.Append("<description>" + features[i].Attributes["Description"].ToString() + "</description>\n"); writer.Write(features[i].Geometry, sb); sb.Append(placemarkClose); } if (File.Exists(filename)) { File.Delete(filename); } string fileContents = header + xmlns + documentOpen + sb.ToString() + documentClose + kmlClose; using (StreamWriter streamWriter = File.CreateText(filename)) { streamWriter.Write(fileContents); streamWriter.Close(); } }