예제 #1
0
        public void TestSave()
        {
            // Create the Kml data
            const string Xml    = "<Placemark xmlns='http://www.opengis.net/kml/2.2'><name>tmp kml</name></Placemark>";
            var          parser = new Parser();

            parser.ParseString(Xml, true);
            var kml = KmlFile.Create(parser.Root, false);

            using (var stream = new MemoryStream())
            {
                // Create and save the archive
                using (var file = KmzFile.Create(kml))
                {
                    file.Save(stream);
                }

                // Try to open the saved archive, rewinding the stream
                stream.Position = 0;
                using (var file = KmzFile.Open(stream))
                {
                    // Make sure it's the same as what we saved
                    parser.ParseString(file.ReadKml(), true);
                    SampleData.CompareElements(kml.Root, parser.Root);
                }
            }
        }
예제 #2
0
        private static KmlFile CreateFile(string kml, bool duplicates)
        {
            var parser = new Parser();

            parser.ParseString(kml, false);
            return(KmlFile.Create(parser.Root, duplicates));
        }
예제 #3
0
        private void MI_Kml_Click(object sender, RoutedEventArgs e)
        {
            if (_selectProjection == null)
            {
                return;
            }
            if (_workData == null)
            {
                return;
            }
            var ph = GetSaveFilePath();

            if (ph == null)
            {
                return;
            }
            foreach (var l in _workData)
            {
                if (!l.HasGeometry())
                {
                    continue;
                }
                //var doc = l.GetKmlDocument(SelectProjection);
                var kmlConverter = new KmlConverter(l, _selectProjection);
                var kml          = KmlFile.Create(kmlConverter.GetKmlDocument(), false);
                using (var stream = File.OpenWrite(ph + "_" + l.Name + ".kml"))
                {
                    kml.Save(stream);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Basic output of the instances Kml to a Kmz as specified in configuration.
        /// </summary>
        public void Save(string band = "")
        {
            string FileName;

            if (String.IsNullOrWhiteSpace(settings.FileName))
            {
                if (band == "")
                {
                    FileName = $"{DateTime.Now.ToString("yyyy-MM-dd")} - Subscriber Map.kmz";
                }
                else
                {
                    FileName = $"{DateTime.Now.ToString("yyyy-MM-dd")} - Subscriber Map ({band}).kmz";
                }
            }
            else
            {
                FileName = settings.FileName;
            }

            KmlFile kmlFile = KmlFile.Create(OutputKml, true);

            using (FileStream fs = new FileStream(FileName, FileMode.Create))
            {
                using (KmzFile kmz = KmzFile.Create(kmlFile))
                {
                    kmz.Save(fs);
                }
            }
        }
예제 #5
0
        public static void Run()
        {
            var point = new sd.Point
            {
                Coordinate = new sb.Vector(37.42052549, -122.0816695)
            };

            var placemark = new sd.Placemark
            {
                Name     = "Да круто",
                Geometry = point
            };

            var point1 = new sd.Point
            {
                Coordinate = new sb.Vector(37.419837, -122.078902)
            };

            var placemark1 = new sd.Placemark
            {
                Name     = "Да круто",
                Geometry = point1
            };

            var document = new sd.Document
            {
                Description = new sd.Description {
                    Text = "Документ"
                }
            };

            var kml = new sd.Kml
            {
                Feature = document
            };

            var folder = new sd.Folder
            {
                Description = new sd.Description {
                    Text = "Светофоры"
                },
                Name = "СО"
            };

            folder.AddFeature(placemark);
            document.AddFeature(folder);
            document.AddFeature(placemark1);

            //var serializer = new sb.Serializer();

            //using FileStream fileStream = new FileStream("kmlTest.kml", FileMode.OpenOrCreate);
            //serializer.Serialize(kml, fileStream);
            var kmlFile = KmlFile.Create(kml, true);

            //using KmzFile kmz = SaveKmlAndLinkedContentIntoAKmzArchive(kmlFile, OutputPath);
            //using Stream output = File.Create(OutputPath);
            //kmz.Save(output);
            //Console.WriteLine("Saved to '{0}'.", OutputPath);
            //Console.ReadKey();
        }
예제 #6
0
        public static KmlFile JoinFoldersIntoKml(String inputPath)
        {
            DirectoryInfo dir = new DirectoryInfo(inputPath);

            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException();
            }

            FileInfo kmlf = dir.EnumerateFiles().ToList().FirstOrDefault(f => ".kml".Equals(f.Extension, StringComparison.OrdinalIgnoreCase));

            if (kmlf == null)
            {
                throw new Exception();
            }

            KmlFile rootKmlFile = FileHelper.LoadKmlKmzFile(kmlf.FullName);

            if (!(rootKmlFile.Root is Document))
            {
                throw new Exception();
            }
            Document rootDoc = (Document)(rootKmlFile.Root.Clone());

            dir.EnumerateDirectories().ToList().ForEach(f => { processFolder(rootDoc, f); });
            KmlFile kmlOut = KmlFile.Create(rootDoc, false);

            return(kmlOut);
        }
예제 #7
0
        static void Main(string[] args)
        {
            String  inFile  = @"C:\tmp\Test\Ferrocarril Belgrano.kml";
            String  outFile = @"C:\tmp\Test\out.kml";
            KmlFile kmlFile = null;

            using (Stream fileStream = File.OpenRead(inFile))
            {
                kmlFile = KmlFile.Load(fileStream);
            }
            Kml      kml = kmlFile.Root as Kml;
            Document d   = kml.Feature as Document;
            Folder   f   = (Folder)d.Features.FirstOrDefault();
            Folder   f2  = (Folder)f.Features.FirstOrDefault();

            Document doc = new Document();

            doc.Name = "MyTestKml";
            d.Schemas.ToList().ForEach(s => doc.AddSchema(s.Clone()));
            doc.AddFeature(f2.Clone());

            // This allows us to save and Element easily.
            KmlFile kmlOut = KmlFile.Create(doc, false);

            using (var stream = System.IO.File.OpenWrite(outFile))
            {
                kmlOut.Save(stream);
            }
        }
예제 #8
0
        public void TestSingleSimpleChange()
        {
            const string ChangeXml =
                "<Update>" +
                "<targetHref/>" +
                "<Change>" +
                "<Placemark targetId=\"p\">" +
                "<name>NEW NAME</name>" +
                "</Placemark>" +
                "</Change>" +
                "</Update>";

            var parser = new Parser();

            parser.ParseString("<Placemark id=\"p\"><name>hi</name></Placemark>", false);
            var file = KmlFile.Create(parser.Root, false);

            var target = file.FindObject("p") as Placemark;

            Assert.That(target, Is.Not.Null);
            Assert.That(target.Name, Is.EqualTo("hi"));

            parser.ParseString(ChangeXml, false);
            var update = parser.Root as Update;

            Assert.That(update, Is.Not.Null); // Verify the test XML

            update.Process(file);
            Assert.That(target.Name, Is.EqualTo("NEW NAME"));
            Assert.That(target.TargetId, Is.Null);
        }
예제 #9
0
        public void TestSingleSimpleDelete()
        {
            const string DeleteXml =
                "<Update>" +
                "<targetHref/>" +
                "<Delete>" +
                "<Placemark targetId=\"p\"/>" +
                "</Delete>" +
                "</Update>";

            var parser = new Parser();

            parser.ParseString("<Folder><Placemark id=\"p\"/></Folder>", false);
            var file = KmlFile.Create(parser.Root, false);

            var target = parser.Root as Folder;

            Assert.That(target, Is.Not.Null);
            Assert.That(target.Features.Count(), Is.EqualTo(1));

            parser.ParseString(DeleteXml, false);
            var update = parser.Root as Update;

            Assert.That(update, Is.Not.Null);

            update.Process(file);
            Assert.That(target.Features.Count(), Is.EqualTo(0));
            Assert.That(file.FindObject("p"), Is.Null); // Make sure it was deleted from the KmlFile too.
        }
예제 #10
0
        public void TestManyDeletes()
        {
            const int NumberOfFolders = 100;

            var folder = new Folder();

            for (int i = 0; i < NumberOfFolders; ++i)
            {
                folder.AddFeature(CreateFeature(i, true)); // Add the features with their Id set
            }
            Assert.That(folder.Features.Count(), Is.EqualTo(NumberOfFolders));

            var file   = KmlFile.Create(folder, false);
            var update = new Update();

            for (int i = 0; i < NumberOfFolders; ++i)
            {
                var delete = new DeleteCollection
                {
                    CreateFeature(i, false) // This time set the TargetId
                };
                update.AddUpdate(delete);
            }
            update.Process(file);
            Assert.That(folder.Features.Count(), Is.EqualTo(0));
        }
예제 #11
0
        public void TestSave()
        {
            // Create the Kml data
            const string Xml    = "<Placemark xmlns='http://www.opengis.net/kml/2.2'><name>tmp kml</name></Placemark>";
            var          parser = new Parser();

            parser.ParseString(Xml, true);
            var kml = KmlFile.Create(parser.Root, false);

            // This will be where we temporary save the archive to
            string tempFile = Path.GetTempFileName();

            try
            {
                // Create and save the archive
                using (var file = KmzFile.Create(kml))
                {
                    file.Save(tempFile);
                }

                // Try to open the saved archive
                using (var file = KmzFile.Open(tempFile))
                {
                    // Make sure it's the same as what we saved
                    parser.ParseString(file.ReadKml(), true);
                    SampleData.CompareElements(kml.Root, parser.Root);
                }
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
예제 #12
0
        public void TestDispose()
        {
            // Make sure we can't call any methods after the object has been disposed
            var file = KmzFile.Create(KmlFile.Create(new Kml(), false));

            file.Dispose();

            // Make sure we can call Dispose more than once
            Assert.That(() => file.Dispose(), Throws.Nothing);

            // Check all methods and properties throw.
            var flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public;

            foreach (var method in typeof(KmzFile).GetMethods(flags))
            {
                // Dispose should be able to be called mutliple times without
                // an exception being thrown.
                if (method.Name != "Dispose")
                {
                    // Actual exception thrown will be TargetInvocationException
                    // so check the InnerException.
                    object[] arguments = new object[method.GetParameters().Length];
                    Assert.That(() => method.Invoke(file, arguments),
                                Throws.InnerException.TypeOf <ObjectDisposedException>());
                }
            }
            foreach (var property in typeof(KmzFile).GetProperties(flags))
            {
                // Mono doesn't throw a TargetInvocationException so just check that the property
                // throws, as it doesn't throw any other type of exception.
                Assert.That(() => property.GetValue(file, null),
                            Throws.Exception);
            }
        }
예제 #13
0
        public void SaveKmz(string outputPathFile)
        {
            var kmlFile = KmlFile.Create(Kml, true);

            using KmzFile kmz   = SaveKmlAndLinkedContentIntoAKmzArchive(kmlFile, outputPathFile);
            using Stream output = File.Create(outputPathFile);
            kmz.Save(output);
            Console.WriteLine("Saved to '{0}'.", outputPathFile);
        }
예제 #14
0
        public void Save(string filename)
        {
            KmlFile kmlfile = KmlFile.Create(_data, false);

            using (var stream = System.IO.File.OpenWrite(filename))
            {
                kmlfile.Save(stream);
            }
        }
예제 #15
0
        public static void Run()
        {
            // Create our Kml
            var folder = new Folder();

            folder.Id   = "f0";
            folder.Name = "Folder 0";

            var placemark = new Placemark();

            placemark.Id   = "pm0";
            placemark.Name = "Placemark 0";
            folder.AddFeature(placemark);

            placemark      = new Placemark();
            placemark.Id   = "pm1";
            placemark.Name = "Placemark 1";
            folder.AddFeature(placemark);

            var kml = new Kml();

            kml.Feature = folder;

            // Display to the user
            var serializer = new Serializer();

            serializer.Serialize(kml);
            Console.WriteLine("Original Kml:\n" + serializer.Xml);

            // This is what we're going to change to
            placemark          = new Placemark();
            placemark.Geometry = new Point {
                Coordinate = new Vector(38, -120)
            };
            placemark.Name     = "new name";
            placemark.TargetId = "pm0";

            var update = new Update();

            update.AddUpdate(new ChangeCollection()
            {
                placemark
            });

            serializer.Serialize(update);
            Console.WriteLine("\nUpdate:\n" + serializer.Xml);

            // Run the update
            var file = KmlFile.Create(kml, false);

            update.Process(file);

            serializer.Serialize(kml);
            Console.WriteLine("\nUpdated Kml:\n" + serializer.Xml);
        }
예제 #16
0
        public void TestChangeCoordinates()
        {
            // Create the target
            var point = new Point
            {
                Coordinate = new Vector(38.38, -122.122)
            };

            var placemark = new Placemark
            {
                Id       = "placemark123",
                Geometry = point,
                Name     = "placemark name"
            };

            var file = KmlFile.Create(placemark, false);

            // Now create the Update
            const double latitude  = -38.38;
            const double longitude = 122.122;

            point = new Point
            {
                Coordinate = new Vector(latitude, longitude)
            };

            placemark = new Placemark
            {
                Geometry = point,
                TargetId = "placemark123"
            };

            var change = new ChangeCollection {
                placemark
            };

            var update = new Update();

            update.AddUpdate(change);

            // Now test the update worked
            update.Process(file);

            placemark = file.Root as Placemark;
            Assert.That(placemark, Is.Not.Null);
            Assert.That(placemark.Id, Is.EqualTo("placemark123"));
            Assert.That(placemark.Name, Is.EqualTo("placemark name"));

            point = placemark.Geometry as Point;
            Assert.That(point, Is.Not.Null);
            Assert.That(point.Coordinate.Latitude, Is.EqualTo(latitude));
            Assert.That(point.Coordinate.Longitude, Is.EqualTo(longitude));
        }
예제 #17
0
        public void TestReadKmlDoesNotReturnTheBOM()
        {
            const string ExampleString = "Example string with no Byte Order Mark.";
            KmzFile      kmz           = KmzFile.Create(KmlFile.Create(new Kml(), duplicates: false));

            byte[] data = Encoding.UTF8.GetBytes(ExampleString);
            byte[] bom  = Encoding.UTF8.GetPreamble();
            kmz.UpdateFile("doc.kml", bom.Concat(data).ToArray());

            string result = kmz.ReadKml();

            Assert.That(result, Is.EqualTo(ExampleString));
        }
예제 #18
0
        public override void saveKmlDocument(Document kmlDoc)
        {
            // This allows us to save and Element easily.
            var kml = new Kml();

            kml.AddNamespacePrefix(KmlNamespaces.GX22Prefix, KmlNamespaces.GX22Namespace);
            kml.Feature = kmlDoc;


            KmlFile kmlF = KmlFile.Create(kml, false);

            kmlF.Save(@"mykmlFile.kml");
        }
예제 #19
0
        private static void RunTestCase(TestCase test, KmlFile file)
        {
            // Need to create a file from the element for Process to use,
            // making sure we pass a copy not the real thing!
            var target = KmlFile.Create(file.FindObject(test.Target).Clone(), false);

            // Update is stored as an orphan of the parent folder
            var update   = (Update)(file.FindObject(test.Input).Orphans.ElementAt(0));
            var expected = file.FindObject(test.Output).Children.ElementAt(0);

            update.Process(target);
            SampleData.CompareElements(expected, target.Root.Children.ElementAt(0));
        }
예제 #20
0
        private static KmzFile CreateArchive()
        {
            // Create an empty KmlFile
            var kml = KmlFile.Create(new Kml(), false);

            // This adds a "doc.kml" for us
            var file = KmzFile.Create(kml);

            // Add a couple more files and return
            file.AddFile("files/new.kml", Encoding.Unicode.GetBytes("new.kml"));
            file.AddFile("other/blah.kml", Encoding.Unicode.GetBytes("blah.kml"));
            return(file);
        }
예제 #21
0
        private static KmlFileWriter GetKmlWriter(string vehicleId, string outputDir)
        {
            var document = new Document();

            document.Name        = string.Format("Vehicle {0} trace", vehicleId);
            document.Description = new Description
            {
                Text = string.Format(
                    "Vehicle {0} trace, starts from {1}",
                    vehicleId,
                    DateTime.Now.ToString("u"))
            };

            var style = new Style
            {
                Id   = "routePathStyle",
                Line = new LineStyle
                {
                    Color = Color32.Parse("7f00ffff"),
                    Width = 4
                }
            };

            document.AddStyle(style);

            var placeMark = new Placemark
            {
                Name     = string.Format("Vehicle {0} path", vehicleId),
                StyleUrl = new Uri("#routePathStyle", UriKind.RelativeOrAbsolute)
            };

            var lineString = new LineString
            {
                Extrude      = true,
                AltitudeMode = AltitudeMode.ClampToGround,
                Coordinates  = new CoordinateCollection(),
                Tessellate   = true
            };

            placeMark.Geometry = lineString;
            document.AddFeature(placeMark);

            var kmlOutputDirectory = new DirectoryInfo(_outputDir).FullName;

            return(new KmlFileWriter
            {
                KmlFile = KmlFile.Create(document, false),
                Path = lineString,
                OutputFile = Path.Combine(kmlOutputDirectory, string.Format("trace-{0}.kml", vehicleId))
            });
        }
예제 #22
0
        public FileContentResult DownloadKMLStatic(int id = 0)
        {
            var route = db.Flights.Where(r => r.FlightID == id).Select(r => r.RouteID).FirstOrDefault();

            if (route == null)
            {
                route = id;                //patch if route is for some reason empty
            }
            var flights = db.Flights.Where(r => r.RouteID == route).Select(r => new { r.FlightID }).ToList();

            var doc = new Document();

            doc.Id   = "Route";
            doc.Name = "Route";
            var folder = new Folder();

            folder.Id   = "Flights";
            folder.Name = "Flights";

            foreach (var f in flights)
            {
                var i = flights.IndexOf(f);
                var flightLineStyles = new FlightLineStyles(i);
                var docStyle         = flightLineStyles.style;
                folder.AddStyle(docStyle);

                var placemark = new FlightPlacemarkLineString(f.FlightID);
                placemark.styleUrlRef = docStyle.Id;
                folder.AddFeature(placemark.placemark);
            }
            doc.AddFeature(folder);

            var kml = new Kml();

            kml.Feature = doc;
            KmlFile kmlFile = KmlFile.Create(kml, true);

            //using (var stream = System.IO.File.OpenWrite("C:/temp/kmlfile.kml"))
            //{
            //    kmlFile.Save(stream);

            //};

            using (var stream = new System.IO.MemoryStream())
            {
                kmlFile.Save(stream);
                var kmlFileName = "Flight_" + id + ".kml";
                var fileBytes   = new System.Text.UTF8Encoding().GetBytes(new System.Text.UTF8Encoding().GetString(stream.ToArray()));
                return(File(fileBytes, "application/vnd.google-earth.kml+xml", kmlFileName));
            };
        }
        void ofd_FileOkSaveKML(object sender, CancelEventArgs e)
        {
            AirNavigationRaceLiveMain.SetStatusText("");
            double channelRadius;
            double altitude;

            // retrieve points from selected tree element

            if (ListOfRouteNames.Count == 0)
            {
                return;
            }

            bool ret = double.TryParse(txtChannelWidth.Text, out channelRadius);

            if (!ret)
            {
                channelRadius = DEFAULT_CHANNEL_WIDTH / 2.0;
            }
            else
            {
                channelRadius = channelRadius / 2.0;
            }

            ret = double.TryParse(txtHeight.Text, out altitude);
            if (!ret)
            {
                altitude = 300;
            }

            bool hasRoundedCorners = chkUseRoundedCorners.Checked;

            SaveFileDialog sfd     = sender as SaveFileDialog;
            string         fname   = sfd.FileName;
            ANRData        anrData = new ANRData();

            anrData.generateParcour(ListOfRoutes, ListOfRouteNames, ListOfNBL, ListOfNBLNames, HAS_MARKERS, CREATE_PROH_AREA, USE_STANDARD_ORDER, channelRadius, altitude, hasRoundedCorners);
            Document document = anrData.Document;
            Kml      kml      = new Kml();

            kml.Feature = document;
            KmlFile file = KmlFile.Create(kml, false);

            using (var stream = System.IO.File.Open(fname, FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                file.Save(stream);
            }
            AirNavigationRaceLiveMain.SetStatusText(string.Format("Route Generator - saved file {0}", sfd.FileName));
        }
예제 #24
0
        public void StartProcess(ProgressDialog dialog, DoWorkEventArgs e)
        {
            int   count = dialog.Maximum = binds.Count;
            int   done  = 0;
            Color c     = Color.FromArgb(255, 82, 82);

            dialog.ReportProgress(-1, null, "Экспорт данных..", null);

            var style = new Style();

            style.Id             = $"colorIcon_{c.R}_{c.G}_{c.B}";
            style.Icon           = new IconStyle();
            style.Icon.Color     = new Color32(255, c.B, c.G, c.R);
            style.Icon.ColorMode = ColorMode.Normal;
            style.Icon.Icon      = new IconStyle.IconLink(new Uri("http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png"));
            style.Icon.Scale     = 1;

            style.Label       = new LabelStyle();
            style.Label.Scale = 0;

            var document = new Document();

            document.Name = System.IO.Path.GetFileNameWithoutExtension(this.path);

            foreach (var bind in this.binds)
            {
                var placemark = CreatePlacemark(bind, style);
                document.AddFeature(placemark);

                done++;
                dialog.ReportProgress(done, null, $"Выполнено: {done}/{count}");
            }

            document.AddStyle(style);

            KmlFile kml = KmlFile.Create(document, false);
            KmzFile k   = KmzFile.Create(kml);

            if (System.IO.File.Exists(this.path))
            {
                System.IO.File.Delete(this.path);
            }

            using (var stream = System.IO.File.OpenWrite(this.path))
            {
                k.Save(stream);
            }
            e.Result = this.path;
        }
예제 #25
0
        public static void ExportFleetWaysToKml(this IEnumerable <FleetWay> fleetWays, Stream kmlStream)
        {
            var kml = new Kml();

            foreach (var fleetWay in fleetWays)
            {
                kml.Feature.AddChild(new Placemark
                {
                    Name     = fleetWay.Name,
                    Geometry = new LineString {
                        Coordinates = new CoordinateCollection(fleetWay.Way.Coordinates.Select(coordinate => new Vector(coordinate.X, coordinate.Y)))
                    },
                });
            }
            KmlFile.Create(kml, true).Save(kmlStream);
        }
예제 #26
0
        public void Dispose()
        {
            if (_document == null)
            {
                return;
            }

            var kmlFile  = KmlFile.Create(_document, false);
            var filePath = $"{_filePath}.kml";

            using (var stream = System.IO.File.OpenWrite(filePath))
            {
                kmlFile.Save(stream);
            }
            Console.WriteLine("saved to " + filePath);
        }
        private void CloseIt()
        {
            LineString line = new LineString();

            line.Coordinates = new CoordinateCollection(CoordsList);
            Placemark placemark = new Placemark();

            placemark.Name     = this.NewFileName.Text + ".kml";
            placemark.Geometry = line;
            NewKmlFile.Feature = placemark;

            OutFile = KmlFile.Create(NewKmlFile, true);


            Close();
        }
예제 #28
0
        // Creates a KML file from an array of locations
        public static void CreateKML(string fileName, Location[] locations)
        {
            Document document = new Document();

            foreach (Location l in locations)
            {
                // Creates a new Placemark
                Point point = new Point();
                point.Coordinate = new Vector(l.Lat, l.Lon);
                Placemark placemark = new Placemark();
                placemark.Name     = l.Name;
                placemark.Address  = l.Address;
                placemark.Geometry = point;

                // Stores the Placemark in a the document
                document.AddFeature(placemark);
            }

            // Converts the documento to KML format
            Kml root = new Kml();

            root.Feature = document;
            KmlFile kml = KmlFile.Create(root, false);

            try
            {
                // Delete the old file if it exits
                if (File.Exists(@fileName))
                {
                    File.Delete(@fileName);
                }

                // Creates the file
                using (FileStream stream = File.OpenWrite(fileName))
                {
                    // Saves the stream to the selected path
                    kml.Save(stream);
                    MessageBox.Show("File " + fileName + " created.");
                }
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }
        }
예제 #29
0
        /// <summary>
        /// Tries to read a legacy kml stream by using SharpKml Parser class directly.
        /// </summary>
        /// <param name="stream">stream to read</param>
        /// <param name="isKml">indicates if stream contains a kml or a kmz file</param>
        /// <returns>parsed kml file, or null when file couldn't be loaded</returns>
        private KmlFile ReadLegacyKmlStream(Stream stream, bool isKml)
        {
            if (isKml)
            {
                var parser = new Parser();
                using (var reader = new StreamReader(stream))
                {
                    string xml = reader.ReadToEnd();
                    parser.ParseString(xml, false); // ignore the namespaces
                }

                return(KmlFile.Create(parser.Root, true));
            }
            else
            {
                return(null);
            }
        }
예제 #30
0
        public static void SavePoints(List <PointLatLng> points, string name, string filePath)
        {
            Kml      root     = new Kml();
            Document document = new Document();

            foreach (PointLatLng lng in points)
            {
                Placemark feature = new Placemark();
                Point     point   = new Point
                {
                    Coordinate = new Vector(lng.Lat, lng.Lng)
                };
                feature.Geometry = point;
                document.AddFeature(feature);
            }
            root.Feature = document;
            KmlFile.Create(root, false).Save(filePath);
        }