Beispiel #1
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);
        }
Beispiel #2
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);
                }
            }
        }