public static ElevationProfile GetElevationProfile(this IEnumerable <Point> points) { ElevationProfile elevationProfile = null; var enumerable = points as IList <Point> ?? points.ToList(); if (enumerable.Any()) { elevationProfile = new ElevationProfile(); double min = 1000000; double max = 0; double gain = 0; double loss = 0; double last = 0; foreach (var cur in enumerable.Select(point => point.Elevation != null ? (float)point.Elevation : 0)) { if (cur > max) { max = cur; } if (cur < min) { min = cur; } if (last != 0) { if (cur > last) { gain = gain + (cur - last); } else if (cur < last) { loss = loss + (last - cur); } } last = cur; } elevationProfile.MaxElevation = Math.Round(((float)(max * 3.2808399)), 0); elevationProfile.MinElevation = Math.Round(((float)(min * 3.2808399)), 0); elevationProfile.Gain = Math.Round(((float)(gain * 3.2808399)), 0); elevationProfile.Loss = Math.Round(((float)(loss * 3.2808399)), 0); } return(elevationProfile); }
public void CalculateProfile() { GpsUtils.BoundingRect(_myLocation, _visibility * 1000, out var min, out var max); _data = new List <GpsLocation>(); string inputFileName = @"c:\Temp\ElevationMap\ALPSMLC30_N049E018_DSM.tif"; GeoTiffReaderList.ReadTiff(inputFileName, min, max, _myLocation, 3, _data); //Calculate old profile /*ElevationProfile ep = new ElevationProfile(); * ep.GenerateElevationProfile(_myLocation, _visibility, _data, progress => { }); * elevationProfileOld = ep.GetProfile();*/ //Calucate new profile var etc = new ElevationTileCollection(_myLocation, (int)_visibility); var d = etc.GetSizeToDownload(); etc.Download(progress => { }); etc.Read(progress => { }); profileGenerator.Generate(_myLocation, 12, etc, progress => { }); /*ProfileGeneratorOld ep2 = new ProfileGeneratorOld(); * //ep2.GenerateElevationProfile3(_myLocation, _visibility, _data, progress => { }); * ep2.GenerateElevationProfile3(_myLocation, _visibility, elevationPainter3.list, progress => { }); * elevationProfileNew = ep2.GetProfile();*/ ElevationProfile ep3 = new ElevationProfile(); ep3.GenerateElevationProfile3(_myLocation, _visibility, profileGenerator.GetProfile(), progress => { }); elevationProfileNew = ep3.GetProfile(); Invalidate(); }
protected override ElevationProfileData RunInBackground(params GpsLocation[] @params) { try { var parts = new List <Part> { new Part() { Title = "DownloadTile", TimeComplexity = 50, Count = _elevationTileCollection.GetCountToDownload() }, new Part() { Title = "ReadTile", TimeComplexity = 10, Count = _elevationTileCollection.GetCount() }, new Part() { Title = "Generate", TimeComplexity = 1, Count = 360 }, new Part() { Title = "MakeLines", TimeComplexity = 1, Count = 360 } }; float totalTimeComplexity = parts.Select(x => x.Count * x.TimeComplexity).Aggregate((sum, part) => sum + part); int totalProgress = 0; var downloadingOk = _elevationTileCollection.Download(progress => { var localProgress = progress * parts[0].TimeComplexity; OnProgressChange?.Invoke((int)((totalProgress + localProgress) / totalTimeComplexity * 100f)); }); totalProgress += parts[0].Count * parts[0].TimeComplexity; var readingOk = _elevationTileCollection.Read(progress => { var localProgress = progress * parts[1].TimeComplexity; OnProgressChange?.Invoke((int)((totalProgress + localProgress) / totalTimeComplexity * 100f)); }); totalProgress += parts[1].Count * parts[1].TimeComplexity; ElevationDataGenerator ep = new ElevationDataGenerator(); ep.Generate(MyLocation, MaxDistance, _elevationTileCollection, progress => { var localProgress = progress * parts[2].TimeComplexity; OnProgressChange?.Invoke((int)((totalProgress + localProgress) / totalTimeComplexity * 100f)); }); totalProgress += parts[2].Count * parts[2].TimeComplexity; ElevationProfile ep2 = new ElevationProfile(); ep2.GenerateElevationProfile3(MyLocation, MaxDistance, ep.GetProfile(), progress => { var localProgress = progress * parts[3].TimeComplexity; OnProgressChange?.Invoke((int)((totalProgress + localProgress) / totalTimeComplexity * 100f)); }); totalProgress += parts[3].Count * parts[3].TimeComplexity; var epd = ep2.GetProfile(); if (!downloadingOk || !readingOk) { epd.ErrorMessage = _elevationTileCollection.GetErrorList(); } return(epd); } catch (Exception ex) { return(new ElevationProfileData(ExceptionHelper.Exception2ErrorMessage(ex))); } }
private void button1_Click(object sender, EventArgs e) { writeKML(); double homealt; double.TryParse(TXT_homealt.Text, out homealt); Form temp = new ElevationProfile(pointlist, homealt); MainV2.fixtheme(temp); temp.ShowDialog(); }