示例#1
0
 /// <summary>
 /// Adds all track points from a GX.Track to the map point list
 /// </summary>
 /// <param name="gxtrack">track to use</param>
 /// <param name="mapPointList">map point list</param>
 private static void AddGxTrackPointsToTrack(SharpKml.Dom.GX.Track gxtrack, List <MapPoint> mapPointList)
 {
     foreach (var vector in gxtrack.Coordinates)
     {
         mapPointList.Add(new MapPoint(vector.Latitude, vector.Longitude, vector.Altitude));
     }
 }
示例#2
0
        /// <summary>
        /// Loads track from given GX.Track object.
        /// </summary>
        /// <param name="gxtrack">track object</param>
        /// <returns>loaded track </returns>
        private static Track LoadTrackFromGXTrack(SharpKml.Dom.GX.Track gxtrack)
        {
            var track = CreateTrackFromPlacemark(gxtrack.Parent as Placemark);

            AddGxTrackPointsToTrack(track, gxtrack);

            return(track);
        }
示例#3
0
        /// <summary>
        /// Adds GX.Track points to given Track object
        /// </summary>
        /// <param name="track">track object to add points to</param>
        /// <param name="gxtrack">GX.Track object to use</param>
        private static void AddGxTrackPointsToTrack(Track track, SharpKml.Dom.GX.Track gxtrack)
        {
            foreach (var vector in gxtrack.Coordinates)
            {
                TrackPoint trackPoint = GetTrackPointFromVector(vector);

                track.TrackPoints.Add(trackPoint);
            }
        }
示例#4
0
        private void ExtractPlacemarks(Feature feature)
        {
            // Is the passed in value a Placemark?
            if (feature is Placemark placemark)
            {
                SharpKml.Dom.GX.Track  track       = placemark.Geometry as SharpKml.Dom.GX.Track;
                SharpKml.Base.Vector[] vector      = track.Coordinates.ToArray();
                DateTime[]             whenElement = track.When.ToArray();

                var sqlTransactionBatch = googleLocationDatabaseCache.TransactionBegin();
                for (int i = 0; i < vector.Length; i++)
                {
                    if (i % 5000 == 0)
                    {
                        googleLocationDatabaseCache.TransactionCommit(sqlTransactionBatch);
                        sqlTransactionBatch = googleLocationDatabaseCache.TransactionBegin();
                    }
                    LocationFoundParam?.Invoke(this, i, i, vector.Length);

                    GoogleJsonLocations googleJsonLocations = new GoogleJsonLocations();
                    googleJsonLocations.Accuracy  = 0;
                    googleJsonLocations.Altitude  = vector[i].Altitude == null ? 0 : (float)vector[i].Altitude;
                    googleJsonLocations.Latitude  = (float)vector[i].Latitude;
                    googleJsonLocations.Longitude = (float)vector[i].Longitude;
                    googleJsonLocations.Timestamp = whenElement[i];
                    googleLocationDatabaseCache.WriteLocationHistory(username, googleJsonLocations);
                }
                googleLocationDatabaseCache.TransactionCommit(sqlTransactionBatch);
            }
            else
            {
                // Is it a Container, as the Container might have a child Placemark?
                if (feature is Container container)
                {
                    // Check each Feature to see if it's a Placemark or another Container
                    foreach (Feature f in container.Features)
                    {
                        ExtractPlacemarks(f);
                    }
                }
            }
        }
示例#5
0
 /// <summary>
 /// Adds the specified <see cref="Track"/> to this instance.
 /// </summary>
 /// <param name="track">The <c>Track</c> to add to this instance.</param>
 /// <exception cref="System.ArgumentNullException">track is null.</exception>
 /// <exception cref="System.InvalidOperationException">
 /// track belongs to another <see cref="Element"/>.
 /// </exception>
 public void AddTrack(Track track)
 {
     this.AddChild(track);
 }
示例#6
0
        public string GetKml()
        {
            var matchId = _currentMatchProvider.GetMatchId();

            SharpKml.Dom.Kml kml = new SharpKml.Dom.Kml();

            var document = new Document();
            kml.Feature = document;

            var c = System.Drawing.ColorTranslator.FromHtml("#33FF33");
            var postStyle = new Style();
            postStyle.Id = "post_vanlig";
            postStyle.Icon = new IconStyle
            {
                Color = new Color32(c.A, c.R, c.G, c.B),
                Icon = new IconStyle.IconLink(new Uri("http://maps.google.com/mapfiles/kml/paddle/wht-blank.png")),
                Scale = 0.5
            };

            document.AddStyle(postStyle);

            var lagFolder = new Folder { Name = "Lag" };
            var postFolder = new Folder { Name = "Poster" };

            document.AddFeature(lagFolder);
            document.AddFeature(postFolder);

            using (var context = _dataContextFactory.Create())
            {
                var match = context.Matcher.Single(x => x.MatchId == matchId);

                var maxLat = match.GeoboxNWLatitude.GetValueOrDefault();
                var minLat = match.GeoboxSELatitude.GetValueOrDefault();
                var minLon = match.GeoboxNWLongitude.GetValueOrDefault();
                var maxLon = match.GeoboxSELongitude.GetValueOrDefault();

                var poster = (from pim in context.PosterIMatch
                              where pim.Match.MatchId == matchId
                              select
                                  new
                                  {
                                      pim.SynligFraTid,
                                      pim.SynligTilTid,
                                      pim.Post.Navn,
                                      pim.Post.Latitude,
                                      pim.Post.Longitude
                                  }).ToList();

                foreach (var p in poster)
                {
                    var placemark = new Placemark();
                    placemark.StyleUrl = new Uri("#post_vanlig", UriKind.Relative);
                    placemark.Time = new TimeSpan { Begin = p.SynligFraTid, End = p.SynligTilTid };
                    placemark.Name = p.Navn;
                    placemark.Geometry = new Point { Coordinate = new Vector(p.Latitude, p.Longitude) };

                    postFolder.AddFeature(placemark);
                }

                var lag = context.Lag.ToList();

                var lagDictionary = new Dictionary<string, Folder>();

                foreach (var lag1 in lag)
                {
                    var color = System.Drawing.ColorTranslator.FromHtml("#" + lag1.Farge);
                    var style = new Style();
                    style.Id = LagStyleKey(lag1.LagId);
                    style.Icon = new IconStyle
                    {
                        Color = new Color32(color.A, color.R, color.G, color.B),
                        Icon = new IconStyle.IconLink(new Uri("http://maps.google.com/mapfiles/kml/paddle/wht-blank-lv.png")),
                        Scale = 0.3
                    };

                    document.AddStyle(style);
                    var folder = new Folder { Name = lag1.Navn };
                    lagDictionary.Add(lag1.LagId, folder);
                    lagFolder.AddFeature(folder);
                }

                var førsteRegistering = (from r in context.PostRegisteringer
                                         select r.RegistertTidspunkt).Min().AddMinutes(-5);

                var avsluttet = (from r in poster
                                    select r.SynligTilTid).Min().AddMinutes(5);

                var deltakerPosisjoner = (from p in context.DeltakerPosisjoner
                                          join d in context.Deltakere on p.DeltakerId equals d.DeltakerId
                                          where førsteRegistering < p.Tidspunkt && p.Tidspunkt < avsluttet
                                          select new
                                          {
                                              p.Latitude,
                                              p.Longitude,
                                              p.DeltakerId,
                                              d.Navn,
                                              d.Lag.Farge,
                                              d.Lag.LagId,
                                              p.Tidspunkt
                                          }).GroupBy(x => x.DeltakerId).ToDictionary(x => x.Key, y => y);

                foreach (var deltaker in deltakerPosisjoner)
                {
                    //if (deltaker.Key != "MS_3-2")

                    //    continue;
                    var førstePosisjon = deltaker.Value.FirstOrDefault();
                    var placemark = new Placemark();
                    placemark.StyleUrl = new Uri("#" + LagStyleKey(førstePosisjon.LagId), UriKind.Relative);
                    placemark.Name = førstePosisjon.Navn;

                    var posisjoner = deltaker.Value.OrderBy(x => x.Tidspunkt).ToList();

                    var track = new Track();

                    var forrigePosisjon = førstePosisjon;
                    foreach (var pos in posisjoner)
                    {
                        // Utafor boksen
                        if (pos.Latitude > maxLat || pos.Latitude < minLat || pos.Longitude > maxLon || pos.Longitude < minLon)
                        {
                            continue;
                        }

                        var meter = DistanseKalkulator.MeterMellom(forrigePosisjon.Latitude, forrigePosisjon.Longitude, pos.Latitude, pos.Longitude);
                        var sekunder = pos.Tidspunkt.Subtract(forrigePosisjon.Tidspunkt).TotalSeconds;

                        if (sekunder > 0)
                        {
                            var fart = meter / sekunder;
                            if (fart > 8.333) // raskere enn 12 blank på 100m
                            {
                                continue;
                            }
                        }

                        track.AddWhen(pos.Tidspunkt);
                        track.AddCoordinate(new Vector(pos.Latitude, pos.Longitude));
                        forrigePosisjon = pos;
                    }

                    placemark.Geometry = track;

                    lagDictionary[førstePosisjon.LagId].AddFeature(placemark);
                }

            }

            Serializer serializer = new Serializer();
            serializer.Serialize(kml);

            return serializer.Xml;
        }
示例#7
0
 /// <summary>
 /// Adds the specified <see cref="Track"/> to this instance.
 /// </summary>
 /// <param name="track">The <c>Track</c> to add to this instance.</param>
 /// <exception cref="System.ArgumentNullException">track is null.</exception>
 /// <exception cref="System.InvalidOperationException">
 /// track belongs to another <see cref="Element"/>.
 /// </exception>
 public void AddTrack(Track track)
 {
     this.AddChild(track);
 }