This project has moved. For the latest updates, please go here.

How to add sequence of placemarks (from list, dataset, etc.)?

Dec 31, 2012 at 6:36 AM

Hi,

In a loop I'm able to generate tours via a step like the following:

tour.Playlist.AddTourPrimitive(flyTo);

as I loop thru a sequence of lat/long items.

I don't see how generate a sequence of kml *placemarks* - for a non-tour - like just to draw the line/nodes for the data set I have.

How can I loop through lat/long data, and append placemark after placemark to my generated kml? i'm sure i'm missing something simple - just not seeing it.

thanks for any tips,

sff

Apr 7, 2013 at 12:40 AM
It doesn't seem obvious to me either. I'm digging around now. If anyone has a quick same which includes a foreach loop it'd be great. I search the SharpKml Examples in Visual Studio for foreach and came up with nothing.
May 15, 2013 at 8:07 PM
I was able to use the Folder class as a means of packaging up several Placemarks from a KML file using Google extensions and punch it out into a KML file without gx for a tool that doesn't support Gx:Track. Snippet below....
                KmlFile sourcefile = KmlFile.Load(googleKML);
                Kml sourcekml = sourcefile.Root as Kml;
                Kml targetkml = new Kml();
                Folder folder = new Folder();
                targetml.Feature = folder;

                if (sourcekml != null)
                {
                    foreach (var placemark in sourcekml.Flatten().OfType<Placemark>())
                    {
                        if (placemark.Geometry is SharpKml.Dom.Point)
                        {
                            Placemark tmp = new Placemark();
                            tmp = placemark.Clone();
                            folder.AddFeature(tmp);
                        }
                        else if (placemark.Geometry is SharpKml.Dom.GX.Track)
                        {
                            Placemark tmp = new Placemark();
                            tmp.Description = placemark.Description.Clone();
                            tmp.Name = placemark.Name;

                            LineString linestring = new LineString();
                            linestring.Extrude = true;
                            linestring.Tessellate = true;
                            linestring.AltitudeMode = AltitudeMode.Absolute;
                            CoordinateCollection coordinates = new CoordinateCollection();
                            foreach (var track in placemark.Flatten().OfType<SharpKml.Dom.GX.Track>())
                            {
                                foreach (var point in track.Coordinates)
                                {
                                    coordinates.Add(point);
                                }
                            }

                            linestring.Coordinates = coordinates;
                            tmp.Geometry = linestring;
                            folder.AddFeature(tmp);                        }
                        else
                        {
                            Console.WriteLine("Unsupported Geometry type in KML file.");
                        }
                        Console.WriteLine(placemark.Geometry.ToString());
                    }
                }
                KmlFile outputKmlFile = KmlFile.Create(targetkml,false);
                outputKmlFile.Save("foo.kml");