/// <summary> /// Open a file and load KML data /// </summary> /// <param name="filename"></param> /// <returns></returns> private void GetPlacemarks(string filename) { // open the KML _parser.ParseString(File.ReadAllText(filename), false); _data = (Kml)_parser.Root; Feature feature = _data.Feature; SharpKml.Dom.Container c = (SharpKml.Dom.Container)feature; List <Placemark> placemarks = new List <Placemark>(); foreach (Feature f in c.Features) { ExtractPlacemarks(f, placemarks); } // set the towns Towns = placemarks; }
private void ExtractPlaceMarkLineStrings(Feature feature, TreeView trv) { // Google Earth Paths are PlaceMarks with a Geometry property of type LineString // Extract these and add to the treeview object (include also the points) // Is the passed in value a Placemark? Placemark placemark = feature as Placemark; if (placemark != null && placemark.Geometry is LineString) { LineString ln = (LineString)placemark.Geometry; //if (ln.Coordinates.Count > 2) // must have at least 2 points //{ if (arrRouteNames.Any(s => placemark.Name.ToUpper() == (s))) { TreeNode node = trv.Nodes.Add(placemark.Name + " (Path with " + ln.Coordinates.Count.ToString() + " Points)"); // add coordinates as object to the Tag property node.Tag = new List <Vector>(ln.Coordinates); } if (arrNBLNames.Any(s => placemark.Name.ToUpper().Contains(s))) { // add NonBacktrack lines directly to list ListOfNBL.Add(new List <Vector>(ln.Coordinates)); ListOfNBLNames.Add(placemark.Name.ToUpper()); } // } } else { // Is it a Container, as the Container might have a child Placemark? SharpKml.Dom.Container container = feature as SharpKml.Dom.Container; if (container != null) { // Check each Feature to see if it's a Placemark or another Container foreach (var f in container.Features) { ExtractPlaceMarkLineStrings(f, trv); } } } }
/// <summary> /// Extracts the placemarks from the feature. /// </summary> /// <param name="feature">The feature.</param> /// <param name="placemarks">The list to add the placemark to.</param> private static void ExtractPlacemarks(Dom.Feature feature, List <Dom.Placemark> placemarks) { // Is the passed in value a Placemark? Dom.Placemark placemark = feature as Dom.Placemark; if (placemark != null) { placemarks.Add(placemark); } else { // Is it a Container, as the Container might have a child Placemark? Dom.Container container = feature as Dom.Container; if (container == null) { return; } // Check each Feature to see if it's a Placemark or another Container foreach (var f in container.Features) { ExtractPlacemarks(f, placemarks); } } }
TreeViewItem ProcessContainer(Container container) { if (container is Document) { return ProcessDocument(container as Document); } return null; }