Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Assembly a     = Assembly.GetExecutingAssembly();
            string   title = ((AssemblyProductAttribute)(Attribute.GetCustomAttribute(a, typeof(AssemblyProductAttribute)))).Product + " " +
                             ((AssemblyInformationalVersionAttribute)(Attribute.GetCustomAttribute(a, typeof(AssemblyInformationalVersionAttribute)))).InformationalVersion + ", " +
                             ((AssemblyCopyrightAttribute)(Attribute.GetCustomAttribute(a, typeof(AssemblyCopyrightAttribute)))).Copyright;

            Console.Error.WriteLine(title);
            Console.Error.WriteLine();

            Options opt = new Options();

            try {
                opt.Evaluate(args);
            } catch (Exception ex) {
                Console.Error.WriteLine("Exception beim Ermitteln der Programmoptionen: " + ex.Message);
                return;
            }

            if (opt.Inputfiles.Count > 0)
            {
                List <string> Inputfiles = PrepareInputData(opt.Inputfiles, opt.InputWithSubdirs); // ev. Unterverzeichnisse und Wildcards einbeziehen

                try {
                    GpxFileSpecial gpxfile = ReadAndMergeGpxfiles(Inputfiles, opt.Outputfile, opt.ShowInfo, opt.SimplifyGPX, title);

                    if (opt.Outputfile.Length > 0)
                    {
                        if (File.Exists(opt.Outputfile) && !opt.OutputOverwrite)
                        {
                            Console.Error.WriteLine("Die Datei '" + opt.Outputfile + "' existiert schon, darf aber nicht überschrieben werden.");
                        }
                        else
                        {
                            ProcessGpxfile(gpxfile, opt);

                            if (opt.OneFilePerTrack)
                            {
                                SplitAndSaveGpxfile(gpxfile, opt.OneFilePerTrack, opt.Outputfile, opt.SimplifyGPX, opt.FormatedOutput, Inputfiles.Count, opt.KmlTrackdata);
                            }
                            else
                            {
                                SaveGpxfile(gpxfile, opt.Outputfile, opt.SimplifyGPX, opt.FormatedOutput, Inputfiles.Count, opt.KmlTrackdata);
                            }
                        }
                    }
                } catch (Exception ex) {
                    Console.Error.WriteLine(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// speichert eine GPX-Datei
        /// </summary>
        /// <param name="gpxfile"></param>
        /// <param name="destfile"></param>
        /// <param name="simplify"></param>
        /// <param name="formated"></param>
        /// <param name="inputcount"></param>
        /// <param name="kmltrackdata"></param>
        static void SaveGpxfile(GpxFileSpecial gpxfile,
                                string destfile,
                                bool simplify,
                                bool formated,
                                int inputcount,
                                List <Options.KmlTrackData> kmltrackdata)
        {
            Console.Error.WriteLine("speichere Ergebnis in {0} ...", destfile);

            uint[] cola  = new uint[kmltrackdata.Count];
            uint[] colr  = new uint[kmltrackdata.Count];
            uint[] colg  = new uint[kmltrackdata.Count];
            uint[] colb  = new uint[kmltrackdata.Count];
            uint[] width = new uint[kmltrackdata.Count];
            for (int i = 0; i < kmltrackdata.Count; i++)
            {
                cola[i]  = kmltrackdata[i].ColorA;
                colr[i]  = kmltrackdata[i].ColorR;
                colg[i]  = kmltrackdata[i].ColorG;
                colb[i]  = kmltrackdata[i].ColorB;
                width[i] = kmltrackdata[i].LineWidth;
            }

            if (simplify ||
                gpxfile.InternalGpx == GpxFile.InternalGpxForm.OnlyPoorGpx ||
                inputcount > 1)
            {
                gpxfile.SavePoorGpx(destfile,
                                    formated,
                                    simplify ? 1 : int.MaxValue,
                                    cola,
                                    colr,
                                    colg,
                                    colb,
                                    width);
            }
            else
            {
                gpxfile.Save(destfile,
                             formated,
                             cola,
                             colr,
                             colg,
                             colb,
                             width);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// aus der GPX-Datei einzelne Objekte jeweils als eigene Datei speichern
        /// </summary>
        /// <param name="gpxfile"></param>
        /// <param name="onefilepertrack">jeden Track einzeln speichern</param>
        static void SplitAndSaveGpxfile(GpxFileSpecial gpxfile,
                                        bool onefilepertrack,
                                        string destfile,
                                        bool simplify,
                                        bool formated,
                                        int inputcount,
                                        List <Options.KmlTrackData> kmltrackdata)
        {
            List <GpxFileSpecial> gpxfiles = new List <GpxFileSpecial>()
            {
                gpxfile
            };
            List <string> destfiles = new List <string>()
            {
                destfile
            };

            if (onefilepertrack)
            {
                int track = 0;
                while (gpxfile.TrackCount() > 0)
                {
                    string trackname = gpxfile.GetTrackname(0);

                    // trackname "bereinigen": alles außer Buchstaben, Ziffern und () entfernen
                    //trackname.Replace()
                    trackname = Regex.Replace(trackname, "[^a-zA-Z0-9ßäöüÄÖÜ=\\s{\\[\\]}(),!;\\.\\+\\-#\\*]", "_"); // alle nichterlaubten Zeichen durch '_' ersetzen


                    string trackdestfile = Path.Combine(Path.GetDirectoryName(destfile), Path.GetFileNameWithoutExtension(destfile) + "_" + track.ToString() + "_" + trackname + ".gpx"); // Nummer wegen eindeutiger Namen

                    GpxFileSpecial gpxfiletrack = new GpxFileSpecial(trackdestfile, gpxfile.gpxcreator);
                    gpxfiletrack.InsertTrack(0, gpxfile, 0);
                    gpxfile.DeleteTrack(0);

                    destfiles.Add(gpxfiletrack.Filename);
                    gpxfiles.Add(gpxfiletrack);

                    track++;
                }
            }

            SaveGpxfile(gpxfiles, destfiles, simplify, formated, inputcount, kmltrackdata);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// verarbeitet die GPX-Datei entsprechend der Anforderungen
        /// </summary>
        /// <param name="gpxfile"></param>
        /// <param name="opt"></param>
        static void ProcessGpxfile(GpxFileSpecial gpxfile, Options opt)
        {
            gpxfile.RemoveElements(opt.Output4Waypoints, GpxFileSpecial.ObjectType.Waypoint);
            gpxfile.RemoveElements(opt.Output4Routes, GpxFileSpecial.ObjectType.Route);
            gpxfile.RemoveElements(opt.Output4Tracks, GpxFileSpecial.ObjectType.Track);

            List <string> NewTrackName = new List <string>();

            if (opt.NewTrackName != null)
            {
                NewTrackName.AddRange(opt.NewTrackName);
            }

            if (opt.Filename2TrackName) // noch nicht explizit gesetzte Tracknamen auf den Dateinamen setzen
            {
                int    trackcount = gpxfile.TrackCount();
                string trackname  = Path.GetFileNameWithoutExtension(opt.Outputfile);
                if (NewTrackName.Count == trackcount - 1)
                {
                    NewTrackName.Add(trackname);
                }
                else // ein Zähler ist wegen eindeutiger Tracknamen nötig
                {
                    int count = 1;
                    while (NewTrackName.Count < trackcount)
                    {
                        NewTrackName.Add(trackname + " (" + count.ToString() + ")");
                        count++;
                    }
                }
            }

            if (NewTrackName.Count > 0)
            {
                gpxfile.SetTracknames(NewTrackName);
            }

            if (opt.Segment2Track)
            {
                gpxfile.Segment2Track2();
            }

            if (opt.GapFill)
            {
                gpxfile.GapFill();
            }

            if (opt.DeleteHeight)
            {
                gpxfile.DeleteTrackHeight();
            }

            if (opt.ConstantHeight != double.MinValue ||
                opt.MinHeight != double.MinValue ||
                opt.MaxHeight != double.MaxValue)
            {
                gpxfile.HeightSetting(opt.ConstantHeight, opt.MinHeight, opt.MaxHeight);
            }

            if (opt.DeleteTimestamp)
            {
                gpxfile.DeleteTrackTimestamp();
            }

            if (opt.HorizontalMaxSpeed > 0)
            {
                gpxfile.RemoveOutlier(opt.HorizontalMaxSpeed);
            }

            if (opt.HorizontalRestArea != null &&
                opt.HorizontalRestArea.Length == 7)
            {
                gpxfile.RemoveRestingplace(opt.HorizontalRestArea[0],
                                           opt.HorizontalRestArea[1], opt.HorizontalRestArea[2], opt.HorizontalRestArea[3],
                                           opt.HorizontalRestArea[4], opt.HorizontalRestArea[5], opt.HorizontalRestArea[6],
                                           opt.HorizontalRestAreaProt);
            }

            if (opt.HorizontalSimplification != Options.HSimplification.Nothing)
            {
                gpxfile.HorizontalSimplification(opt.HorizontalSimplification, opt.HorizontalWidth);
            }

            if (opt.VerticalOutlierWidth > 0)
            {
                gpxfile.RemoveHeigthOutlier(opt.VerticalOutlierWidth, opt.MaxAscent);
            }

            if (opt.VerticalSimplification != Options.VSimplification.Nothing)
            {
                gpxfile.VerticalSimplification(opt.VerticalSimplification, opt.VerticalWidth);
            }

            if (opt.HeightOutputfile.Length > 0)
            {
                if (File.Exists(opt.HeightOutputfile) && !opt.OutputOverwrite)
                {
                    Console.Error.WriteLine("Die Datei '" + opt.HeightOutputfile + "' existiert schon, darf aber nicht überschrieben werden.");
                }
                else
                {
                    gpxfile.SaveHeight(opt.HeightOutputfile);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// liest (und fügt die Dateien zusammen) und zeigt ev. Infos der Dateien an
        /// </summary>
        /// <param name="Inputfiles">Liste der Eingabedateien</param>
        /// <param name="destfile">Name der Zieldatei</param>
        /// <param name="showinfo">Dateiinfos anzeigen</param>
        /// <param name="simplify">GPX vereinfachen</param>
        /// <param name="gpxcreator">Creator der neuen Datei</param>
        /// <returns></returns>
        static GpxFileSpecial ReadAndMergeGpxfiles(List <string> Inputfiles, string destfile, bool showinfo, bool simplify, string gpxcreator)
        {
            GpxFileSpecial gpxfile = null;

            if (Inputfiles.Count == 1)
            {
                gpxfile = new GpxFileSpecial(Inputfiles[0])
                {
                    InternalGpx = simplify ?
                                  GpxFile.InternalGpxForm.OnlyPoorGpx :
                                  GpxFile.InternalGpxForm.NormalAndPoor
                };
                gpxfile.Read();

                if (showinfo)
                {
                    ShowInfoOnStdOut(new GpxInfos(gpxfile, true));
                }
            }
            else  // > 1, dann implizit GpxFile.InternalGpxForm.OnlyPoorGpx bilden

            {
                gpxfiles = new GpxFile[Inputfiles.Count];

                TaskQueue          tq       = new TaskQueue();
                IProgress <string> progress = new Progress <string>(TaskProgress4Read);
                for (int i = 0; i < Inputfiles.Count; i++)
                {
                    tq.StartTask(Inputfiles[i], i, TaskWorker4Read, progress, null);
                }
                tq.Wait4EmptyQueue();
                if (tq.ExeptionMessage != "")
                {
                    throw new Exception(tq.ExeptionMessage);
                }

                if (showinfo)
                {
                    GpxInfos[] infos = new GpxInfos[gpxfiles.Length];
                    progress = new Progress <string>(TaskProgress4Info);
                    for (int i = 0; i < gpxfiles.Length; i++)
                    {
                        tq.StartTask(gpxfiles[i], infos, i, TaskWorker4Info, progress, null);
                    }
                    tq.Wait4EmptyQueue();
                    if (tq.ExeptionMessage != "")
                    {
                        throw new Exception(tq.ExeptionMessage);
                    }

                    for (int i = 0; i < infos.Length; i++)
                    {
                        ShowInfoOnStdOut(infos[i]);
                    }
                }

                // alle Dateien zusammenfügen
                if (destfile.Length > 0)
                {
                    gpxfile = new GpxFileSpecial(Inputfiles[0], gpxcreator)
                    {
                        InternalGpx = GpxFile.InternalGpxForm.OnlyPoorGpx
                    }; // nur Name der 1. Datei, aber nicht einlesen !
                    for (int i = 0; i < Inputfiles.Count; i++)
                    {
                        Console.Error.WriteLine("füge Daten aus {0} ein", Inputfiles[i]);
                        gpxfile.Concat(gpxfiles[i]);
                    }
                }
            }

            return(gpxfile);
        }
Ejemplo n.º 6
0
                    /// <summary>
                    /// liefert die Länge und die min. und max. Höhe der Punktliste (falls vorhanden, sonst double.MaxValue bzw. double.MinValue)
                    /// </summary>
                    /// <param name="pt"></param>
                    /// <param name="minheight"></param>
                    /// <param name="maxheight"></param>
                    /// <param name="descent"></param>
                    /// <param name="ascent"></param>
                    /// <param name="averagespeed">Durchschnittsgeschwindigkeit in m/s</param>
                    /// <returns></returns>
                    double GetLengthAndMinMaxHeight(List <GpxTrackPoint> pt,
                                                    out double minheight,
                                                    out double maxheight,
                                                    out double descent,
                                                    out double ascent,
                                                    out double averagespeed)
                    {
                        minheight    = double.MaxValue;
                        maxheight    = double.MinValue;
                        descent      = 0;
                        ascent       = 0;
                        averagespeed = 0;

                        double length = 0;

                        if (pt.Count > 0)
                        {
                            if (pt[0].Elevation != BaseElement.NOTVALID_DOUBLE)
                            {
                                minheight = Math.Min(pt[0].Elevation, minheight);
                                maxheight = Math.Max(pt[0].Elevation, maxheight);
                            }

                            int starttimeidx = -1;
                            int endtimeidx   = -1;
                            if (pt[0].Time != BaseElement.NOTVALID_TIME)
                            {
                                starttimeidx = endtimeidx = 0;
                            }

                            for (int p = 1; p < pt.Count; p++)
                            {
                                if (starttimeidx < 0 && pt[p].Time != BaseElement.NOTVALID_TIME)
                                {
                                    starttimeidx = endtimeidx = p;
                                }
                                else
                                {
                                    if (pt[p].Time != BaseElement.NOTVALID_TIME)
                                    {
                                        endtimeidx = p;
                                    }
                                }

                                if (pt[p].Elevation != BaseElement.NOTVALID_DOUBLE)
                                {
                                    minheight = Math.Min(pt[p].Elevation, minheight);
                                    maxheight = Math.Max(pt[p].Elevation, maxheight);
                                    if (pt[p - 1].Elevation != BaseElement.NOTVALID_DOUBLE)
                                    {
                                        double diff = pt[p].Elevation - pt[p - 1].Elevation;
                                        if (diff > 0)
                                        {
                                            descent += diff;
                                        }
                                        else
                                        {
                                            ascent -= diff;
                                        }
                                    }
                                }
                            }

                            length = GpxFileSpecial.GetLength(pt);

                            if (starttimeidx >= 0 &&
                                endtimeidx >= 0)
                            {
                                TimeSpan ts = pt[endtimeidx].Time.Subtract(pt[starttimeidx].Time);
                                double   l  = GpxFileSpecial.GetLength(pt, starttimeidx, endtimeidx);
                                averagespeed = l / ts.TotalSeconds;
                            }
                        }
                        return(length);
                    }