Exemplo n.º 1
0
        public static GpsLog FromNmeaGprmcFile(string filename)
        {
            GpsLog log = new GpsLog();

            FileStream fs          = File.OpenRead(filename);
            TextReader tr          = new StreamReader(fs);
            String     inputString = tr.ReadToEnd();

            tr.Close();

            Regex regexGprmc = new Regex(REGEX_NMEA_GPRMC);
            Match match      = regexGprmc.Match(inputString);

            while (match.Success)
            {
                try
                {
                    GpsLogEntry e = new GpsLogEntry();

                    e.Latitude = Convert(match.Groups["lat"].Value);
                    if (match.Groups["latdir"].Value == "S")
                    {
                        e.Latitude *= -1;
                    }

                    e.Longitude = Convert(match.Groups["lon"].Value);
                    if (match.Groups["londir"].Value == "W")
                    {
                        e.Longitude *= -1;
                    }

                    string time = match.Groups["time"].Value;
                    int    h    = int.Parse(time.Substring(0, 2));
                    int    min  = int.Parse(time.Substring(2, 2));
                    int    s    = int.Parse(time.Substring(4, 2));

                    string date = match.Groups["date"].Value;
                    int    d    = int.Parse(date.Substring(0, 2));
                    int    m    = int.Parse(date.Substring(2, 2));
                    int    y    = int.Parse(date.Substring(4, 2));
                    if (y > 80)
                    {
                        y += 1900;
                    }
                    else
                    {
                        y += 2000;
                    }

                    e.Time = new DateTime(y, m, d, h, min, s); // TODO  ms?

                    log.AddEntry(e);
                }
                catch { }

                match = match.NextMatch();
            }

            Regex regexGpwpl = new Regex(REGEX_NMEA_GPWPL);

            match = regexGpwpl.Match(inputString);
            while (match.Success)
            {
                try
                {
                    NamedGpsLogEntry e = new NamedGpsLogEntry();

                    e.Latitude = Convert(match.Groups["lat"].Value);
                    if (match.Groups["latdir"].Value == "S")
                    {
                        e.Latitude *= -1;
                    }

                    e.Longitude = Convert(match.Groups["lon"].Value);
                    if (match.Groups["londir"].Value == "W")
                    {
                        e.Longitude *= -1;
                    }

                    e.Name = match.Groups["name"].Value.Trim();

                    log.Waypoints.Add(e);
                }
                catch {}

                match = match.NextMatch();
            }

            return(log);
        }
Exemplo n.º 2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            Settings.Default.KmzOpenFile = this.chkOpen.Checked;

            if (this.txtKmzFile.Text == "")
            {
                return;
            }

            KmlDocument doc = new KmlDocument();

            doc.Name = this.txtName.Text;

            // create placemarks for photos (one, selectend or subdirs)
            if (this.radOneFile.Checked)
            {
                Placemark placemark = PlacemarkFromPicture(currentPicture);
                if (placemark != null)
                {
                    doc.Placemarks.Add(placemark);
                }
            }
            else if (this.radSelected.Checked)
            {
                List <string> filenames = this.getAllFilesDelegate(false);
                foreach (string filename in filenames)
                {
                    PictureMetaData pmd       = new PictureMetaData(filename);
                    Placemark       placemark = PlacemarkFromPicture(pmd);
                    if (placemark != null)
                    {
                        doc.Placemarks.Add(placemark);
                    }
                    pmd.Close();
                }
            }
            else if (this.radSubdirs.Checked)
            {
                List <string> filenames = this.getAllFilesDelegate(false);
                foreach (string filename in filenames)
                {
                    PictureMetaData pmd       = new PictureMetaData(filename);
                    Placemark       placemark = PlacemarkFromPicture(pmd);
                    if (placemark != null)
                    {
                        doc.Placemarks.Add(placemark);
                    }
                    pmd.Close();
                }

                FileInfo      fi      = new FileInfo(filenames[0]);
                DirectoryInfo startdi = fi.Directory;
                foreach (DirectoryInfo di in startdi.GetDirectories())
                {
                    doc.Folders.Add(CreateFolder(di));
                }
            }

            // create route
            if (this.chkRoute.Checked && File.Exists(this.txtRouteFile.Text))
            {
                GpsLog log = GpsLogFactory.FromFile(this.txtRouteFile.Text);

                PlacemarkLine p = new PlacemarkLine();
                p.LineWidth = Settings.Default.KmzLineWidth;
                p.LineColor = Settings.Default.KmzLineColor;
                p.Name      = "route";
                foreach (GpsLogEntry l in log)
                {
                    p.Coordinates.Add(new Coordinate(l.Longitude, l.Latitude));
                }
                doc.Placemarks.Add(p);
            }

            if (doc.IsEmpty)
            {
                this.Cursor = Cursors.Default;

                MessageBox.Show("No photos with GPS data found and no kmz-file created.", "PhotoTagStudio",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                KmzArchiv arc = new KmzArchiv(doc);
                arc.Create(this.txtKmzFile.Text);

                this.Cursor = Cursors.Default;

                if (this.chkOpen.Checked)
                {
                    System.Diagnostics.Process.Start(this.txtKmzFile.Text);
                }
            }
        }
Exemplo n.º 3
0
        public static GpsLog FromNmeaGpggaFile(string filename)
        {
            GpsLog log = new GpsLog();

            FileStream fs = File.OpenRead(filename);
            TextReader tr = new StreamReader(fs);

            string   line      = tr.ReadLine();
            TimeSpan lastTime  = new TimeSpan(0, 0, 0);
            int      dayoffset = 0;

            while (line != null)
            {
                // $GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,g.g,z,t.t,iii*CC
                // $GPGGA,183456.000,3424.8054,N,11941.2676,W,1,05,1.4,-2.7,M,-33.3,M,,0000*44
                if (line.StartsWith("$GPGGA"))
                {
                    string[] parts = line.Split(',');

                    if (parts.Length >= 7)
                    {
                        string time    = parts[1];
                        string lat     = parts[2];
                        string latdir  = parts[3];
                        string lon     = parts[4];
                        string londir  = parts[5];
                        string quality = parts[6];

                        if (time != "" &&
                            lat != "" &&
                            (latdir == "N" || latdir == "S") &&
                            lon != "" &&
                            (londir == "E" || londir == "W") &&
                            quality != "")
                        {
                            try
                            {
                                GpsLogEntry e = new GpsLogEntry();

                                e.Latitude = Convert(lat);
                                if (latdir == "S")
                                {
                                    e.Latitude *= -1;
                                }

                                e.Longitude = Convert(lon);
                                if (londir == "W")
                                {
                                    e.Longitude *= -1;
                                }

                                int      h           = int.Parse(time.Substring(0, 2));
                                int      m           = int.Parse(time.Substring(2, 2));
                                int      s           = int.Parse(time.Substring(4, 2));
                                TimeSpan currentTime = new TimeSpan(dayoffset, h, m, s); //TODO ms?
                                if (lastTime.CompareTo(currentTime) > 0)
                                {
                                    dayoffset++;
                                    currentTime = new TimeSpan(dayoffset, h, m, s); //TODO ms?
                                }
                                lastTime = currentTime;

                                // Fixed when starting to use DatetTime Type
                                e.Time = new DateTime(2000, 0, currentTime.Days, currentTime.Hours, currentTime.Minutes, currentTime.Seconds);

                                log.AddEntry(e);
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                line = tr.ReadLine();
            }

            return(log);
        }