private void OnNewPointButton_Click(object sender, RoutedEventArgs e)
        {
            CurrentPointNumber++;
            SharpKml.Base.Vector coord = new SharpKml.Base.Vector(0, 0);
            CoordsList.Add(coord);
            EditPointControl pointControl = new EditPointControl(coord, CurrentPointNumber);

            this.Stack.Children.Add(pointControl);
        }
示例#2
0
 public EditPointControl(SharpKml.Base.Vector coordinates, int pointNumber)
 {
     InitializeComponent();
     Coordinates       = coordinates;
     CurrLat.Text      = Coordinates.Latitude.ToString();
     CurrLong.Text     = Coordinates.Longitude.ToString();
     Point.Text        = pointNumber.ToString();
     PreviewTextInput += NumberValidation;
 }
示例#3
0
        /// <summary>
        /// Creates track point object from SharpKml Vector object
        /// </summary>
        /// <param name="vector">vector object</param>
        /// <returns>track point object</returns>
        private static TrackPoint GetTrackPointFromVector(SharpKml.Base.Vector vector)
        {
            double?altitude = null;

            if (vector.Altitude.HasValue)
            {
                altitude = vector.Altitude;
            }

            return(new TrackPoint(vector.Latitude, vector.Longitude, altitude, heading: null));
        }
        /// <summary>
        /// Calculates azimuth of a line between 2 points
        /// </summary>
        /// <param name="position1"></param>
        /// <param name="position2"></param>
        /// <returns></returns>
        public static double CalculateBearing(Coord.Vector position1, Coord.Vector position2)
        {
            var lat1  = AngleConverter.ConvertDegreesToRadians(position1.Latitude);
            var lat2  = AngleConverter.ConvertDegreesToRadians(position2.Latitude);
            var long1 = AngleConverter.ConvertDegreesToRadians(position2.Longitude);
            var long2 = AngleConverter.ConvertDegreesToRadians(position1.Longitude);
            var dLon  = long1 - long2;

            var y    = Math.Sin(dLon) * Math.Cos(lat2);
            var x    = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(dLon);
            var brng = Math.Atan2(y, x);

            return((AngleConverter.ConvertRadiansToDegrees(brng) + 360) % 360);
        }
        /// <summary>
        /// Calculates a point with a starting point, distance and azimuth
        /// </summary>
        /// <param name="start">Starting point in latitude and longitude</param>
        /// <param name="distance">Distance in kilometers</param>
        /// <param name="bearing">Azimuth in degrees</param>
        /// <returns></returns>
        public static Coord.Vector CalculatePoint(Coord.Vector start, double distance, double bearing)
        {
            double dista = distance / EarthsRadius;
            double tc    = -AngleConverter.ConvertDegreesToRadians(bearing);
            double lat1  = AngleConverter.ConvertDegreesToRadians(start.Latitude);
            double lon1  = AngleConverter.ConvertDegreesToRadians(start.Longitude);

            double lat  = Math.Asin(Math.Sin(lat1) * Math.Cos(dista) + Math.Cos(lat1) * Math.Sin(dista) * Math.Cos(tc));
            double dlon = Math.Atan2(Math.Sin(tc) * Math.Sin(dista) * Math.Cos(lat1), Math.Cos(dista) - Math.Sin(lat1) * Math.Sin(lat));
            double lon  = ((lon1 - dlon + Math.PI) % (2 * Math.PI)) - Math.PI;

            lat = AngleConverter.ConvertRadiansToDegrees(lat);
            lon = AngleConverter.ConvertRadiansToDegrees(lon);

            return(new Coord.Vector(lat, lon));
        }
        public void AddMarkerToContainer(Coord.Vector place, Container container, int number)
        {
            SharpKml.Dom.Style style = new SharpKml.Dom.Style();
            style.Id        = "MarkerStyle" + number.ToString();
            style.Icon      = new IconStyle();
            style.Icon.Icon = new IconStyle.IconLink(new Uri("http://maps.google.com/mapfiles/kml/paddle/red-circle.png"));

            Placemark placemark = new Placemark();

            placemark.StyleUrl = new Uri("MarkerStyle" + number.ToString(), UriKind.Relative);
            placemark.Geometry = new SharpKml.Dom.Point()
            {
                Coordinate = place
            };

            container.AddFeature(placemark);
            container.AddStyle(style);
        }
        public void AddSingleLineToContainer(Coord.Vector start, Coord.Vector end, byte color, Container container, int number)
        {
            SharpKml.Dom.Style style = new SharpKml.Dom.Style();

            style.Id         = "LineStyle" + number.ToString();
            style.Line       = new LineStyle();
            style.Line.Color = new Coord.Color32(255, 0, (byte)(255 - color), color);
            style.Line.Width = 3;

            Placemark placemark = new Placemark();

            placemark.StyleUrl = new Uri("LineStyle" + number.ToString(), UriKind.Relative);

            LineString lineString = new LineString();

            lineString.Coordinates = new CoordinateCollection();
            lineString.Coordinates.Add(start);
            lineString.Coordinates.Add(end);

            placemark.Geometry = lineString;
            container.AddFeature(placemark);
            container.AddStyle(style);
        }
        private void DoAnalize(FileButton <Profile> butt)
        {
            SectionReadWindow sectionReadWindow = new SectionReadWindow(butt.File.ProfSection, false);

            sectionReadWindow.ShowDialog();

            Kml file = (Kml)butt.File.ProfKmlFile.Root;
            List <Placemark> lineList = new List <Placemark>();

            ExtractPlacemarks(file.Feature, lineList);

            LineString line = new LineString();

            try
            {
                line = lineList.Single().Geometry as LineString;
            }
            catch
            {
                MessageBox.Show("Kml nie spełnia wymogów profilu. Należy wczytać plik zawierający jedną linię.");
            }

            List <Coord.Vector> points = new List <Coord.Vector>();

            foreach (Coord.Vector j in line.Coordinates)
            {
                points.Add(j);
            }

            Coord.Vector startCoord = points[0];
            Coord.Vector endCoord   = points[points.Count - 1];
            List <System.Windows.Point> secPoints = sectionReadWindow.Points;
            List <Coord.Vector>         vectors   = new List <Coord.Vector>();

            int    pointsAmount  = sectionReadWindow.Points.Count;
            double profLength    = CoordinatesCalculator.CalculateDistance(startCoord.Latitude, startCoord.Longitude, endCoord.Latitude, endCoord.Longitude);
            double sectionLength = sectionReadWindow.LastPoint.X - sectionReadWindow.ZeroPoint.X;
            double scale         = profLength / sectionLength;
            double maxDepth      = sectionReadWindow.LastPoint.Y - sectionReadWindow.ZeroPoint.Y;
            double azimuth       = CoordinatesCalculator.CalculateBearing(startCoord, endCoord);
            var    pp            = from t in secPoints
                                   orderby t.X ascending
                                   select t;

            secPoints = pp.ToList <System.Windows.Point>();

            List <byte> depths = new List <byte>();
            byte        depth  = new byte();

            for (int i = 0; i < pointsAmount; i++)
            {
                depth = (byte)(secPoints[i].Y / maxDepth * 255);
                double dist;

                if (i == 0)
                {
                    dist = secPoints[i].X * scale;
                    vectors.Add(startCoord);
                    depths.Add((byte)(sectionReadWindow.ZeroPoint.Y / maxDepth * 255));
                }
                else
                {
                    dist = (secPoints[i].X - secPoints[i - 1].X) * scale;
                }

                Coord.Vector vector = CoordinatesCalculator.CalculatePoint(vectors[vectors.Count - 1], dist, azimuth);
                vectors.Add(vector);
                depths.Add(depth);
            }

            vectors.RemoveAt(vectors.Count - 1);
            depths.RemoveAt(depths.Count - 1);
            vectors.RemoveAt(vectors.Count - 1);
            depths.RemoveAt(depths.Count - 1);

            vectors.Add(endCoord);
            depths.Add(depths[depths.Count - 1]);

            Document document = new Document();

            document.Name = butt.File.Name + ".kml";

            for (int i = 1; i < vectors.Count; i++)
            {
                AddSingleLineToContainer(vectors[i - 1], vectors[i], (byte)((depths[i] + depths[i - 1]) / 2), document, i);
            }

            List <Coord.Vector> markers = new List <Coord.Vector>();

            foreach (var point in sectionReadWindow.Markers)
            {
                double       dist   = point.X * scale;
                Coord.Vector vector = CoordinatesCalculator.CalculatePoint(startCoord, dist, azimuth);
                markers.Add(vector);
            }

            int n = 1;

            foreach (var coord in markers)
            {
                AddMarkerToContainer(coord, document, n);
                n++;
            }

            Kml kml = new Kml();

            kml.Feature = document;
            KmlFile kmlFile = KmlFile.Create(kml, true);

            AddToList(kmlFile);
            SaveKmls(kmlFile);
            FileButton <KmlFile> button = new FileButton <KmlFile>(kmlFile)
            {
                Height  = 40,
                Margin  = new Thickness(10, 5, 5, 10),
                Content = document.Name
            };

            button.Click += OnOutFileButtonClick;

            OutStack.Children.Add(button);
        }