示例#1
0
        private static void Main(string[] args)
        {
            IGpxReader gpxReader = new GpxReader();
            IKmlWriter kmlWriter = new KmlWriter();
            ICommandLineParserService commandLineParserService = new CommandLineParserService();
            IGpxToKmlConverter        gpxToKmlConverter        = new GpxToKmlConverter(commandLineParserService, gpxReader, kmlWriter);

            gpxToKmlConverter.Run(args);
        }
示例#2
0
        public static void run(string apikey, string output)
        {
            Console.WriteLine("Generate KML!");
            List <Entry> entries = SearchDataModel();

            //TODO normalize the data set
            // e.g. if there is no enddate for an entry take the startdate of the next entry for the same unit etc ....
            var kmlData = Normalizer.ForRendering(entries, apikey);

            using (var writer = KmlWriter.Create(output + "-" + DateTime.Now.Ticks))
            {
                kmlData.ToList().ForEach(async re => await writer.Write(re));
            }
        }
示例#3
0
        public static XmlElement CreatePlacemark(XmlDocument document, Waypoint wp, bool visible, bool showLabel, bool paddleMarker, bool ssidLabel)
        {
            //Create the main placemark element
            XmlElement xeMain = document.CreateElement("Placemark");

            string color = KmlWriter.EncryptionColor(wp.Extensions.Security);

            //Visibility is default true
            xeMain.AppendChild(CreateElementWithText(document, "visibility", visible ? "1" : "0"));

            //placemark style
            XmlElement xeStyle = document.CreateElement("Style");

            xeStyle.SetAttribute("id", "sn_shaded_dot");

            XmlElement xeIconStyle = document.CreateElement("IconStyle");
            XmlElement xeIcon      = document.CreateElement("Icon");

            xeIcon.AppendChild(CreateElementWithText(document, "href",
                                                     paddleMarker
                                                         ? "http://maps.google.com/mapfiles/kml/paddle/wht-blank.png"
                                                         : "http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png"));
            //Add icon element to iconstyle element
            xeIconStyle.AppendChild(xeIcon);

            xeIconStyle.AppendChild(CreateElementWithText(document, "color", color));
            xeIconStyle.AppendChild(CreateElementWithText(document, "scale", KmlWriter.IconScale(wp.Extensions.Rssi).ToString(CultureInfo.InvariantCulture)));

            //Add element
            xeStyle.AppendChild(xeIconStyle);

            //LabelStyle element
            XmlElement xeLabelStyle = document.CreateElement("LabelStyle");

            xeLabelStyle.AppendChild(CreateElementWithText(document, "color", color));
            xeLabelStyle.AppendChild(CreateElementWithText(document, "scale", showLabel ? "1" : "0"));

            //Add element
            xeStyle.AppendChild(xeLabelStyle);

            //Add Style to main placemark element
            xeMain.AppendChild(xeStyle);

            //Add name element
            xeMain.AppendChild(CreateElementWithText(document, "name", ssidLabel ? wp.Extensions.Ssid + ": " + wp.Extensions.Rssi : wp.Extensions.Rssi.ToString(CultureInfo.InvariantCulture)));

            //Add description element
            xeMain.AppendChild(CreateElementWithText(document, "description", wp.BuildKmlDescription()));
            //Location
            //KML requires Lon,Lat,Alt. It's backwards!
            XmlElement xePoint = document.CreateElement("Point");

            xePoint.AppendChild(CreateElementWithText(document, "coordinates",
                                                      string.Format("{0},{1},{2}",
                                                                    wp.Longitude.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                                                    wp.Latitude.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                                                    wp.Elevation.ToString(CultureInfo.InvariantCulture.NumberFormat))));
            xeMain.AppendChild(xePoint);

            return(xeMain);
        }
示例#4
0
        private void ExportButtonClick(object sender, EventArgs e)
        {
            if (txtInFiles.Text.Trim() == string.Empty)
            {
                MessageBox.Show(Localizer.GetString("ErrorNoLogFileSelected"), Localizer.GetString("Error"),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtOutDir.Text.Trim() == string.Empty)
            {
                MessageBox.Show(Localizer.GetString("ErrorKmlDirectoryMissing"), Localizer.GetString("Error"),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!txtOutDir.Text.EndsWith("\\"))
            {
                txtOutDir.AppendText("\\");
            }
            _outPath = txtOutDir.Text;

            //Append the log filename to the directory path
            int lastS = _inFiles[0].LastIndexOf('\\');
            int lastP = _inFiles[0].Substring(lastS).LastIndexOf('.');

            _outPath += _inFiles[0].Substring(lastS).Remove(lastP) + "\\";

            try
            {
                //Create the output directory
                System.IO.Directory.CreateDirectory(_outPath);
            }
            catch (UnauthorizedAccessException ex)
            {
                MessageBox.Show(string.Format("{0}\r\n\r\n{1}", ex.Message, Localizer.GetString("ErrorExportDirectory")), Localizer.GetString("Error"));
                return;
            }
            catch (DirectoryNotFoundException ex)
            {
                MessageBox.Show(ex.Message, Localizer.GetString("Error"));
                return;
            }

            //All is well, let's go
            Waypoint[] allPoints;
            try
            {
                //Load all files. An array is required because all KML classes accept arrays
                allPoints = GpxIO.ReadGpxFiles(_inFiles).ToArray();
            }
            catch (IOException)
            {
                //This happens when the file is locked by another process or WirelessFireless is still logging to it.
                MessageBox.Show(
                    Localizer.GetString("GpxFileOpenError"),
                    Localizer.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Filter data
            WaypointFilterArgs farg = new WaypointFilterArgs
            {
                GpsFixLost         = chGPSFixLost.Checked,
                GpsLockedUp        = chGPSLockup.Checked,
                MaximumSpeedKmh    = chMaxSpeed.Checked ? (int)numMaxSpeed.Value : -1,
                MaxSignal          = chMaxSignal.Checked ? (int)numMaxSignal.Value : -1,
                MinimumSatsVisible = chGPSsatCount.Checked ? (int)numSatCount.Value : -1
            };

            allPoints = KmlWriter.FilterData(allPoints, farg);

            ApOrganization group = (ApOrganization)cmbOrganize.SelectedIndex;

            if (chExportSummary.Checked) //Export a summary file
            {
                if (!System.IO.File.Exists(_outPath + "Summary.kml") ||
                    MessageBox.Show(Localizer.GetString("WarningSummaryKmlExists"),
                                    Localizer.GetString("FileExists"), MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    KmlWriter.WriteSummaryKml(allPoints, _outPath + "Summary.kml", group, chShowRssiMarkers.Checked);
                }
            }

            if (chExportComp.Checked) //Comprehensive
            {
                if (!System.IO.File.Exists(_outPath + "Comprehensive.kml") ||
                    MessageBox.Show(Localizer.GetString("WarningComprehensiveKmlExists"),
                                    Localizer.GetString("FileExists"), MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    KmlWriter.WriteComprehensiveKml(allPoints, _outPath + "Comprehensive.kml", group, chShowRssiMarkers.Checked);
                }
            }

            if (chExportEachAp.Checked) //Export each AP to ./APs/{SSID}.kml
            {
                KmlWriter.WriteAccessPointKml(allPoints, _outPath, chShowRssiMarkers.Checked);
            }

            MessageBox.Show(Localizer.GetString("ExportComplete"), Localizer.GetString("Finished"), MessageBoxButtons.OK);
        }