public async Task Line_SanPedroTwoTrackFileLineToGeoJsonAndBack()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "TwoTrackGpxNearTheSanPedro.gpx"));

            Assert.True(testFile.Exists, "Test File Found");

            var tracks = await SpatialHelpers.TracksFromGpxFile(testFile, DebugTrackers.DebugProgressTracker());

            Assert.AreEqual(2, tracks.Count, "Should find 2 tracks");
            Assert.True(tracks.All(x => !string.IsNullOrWhiteSpace(x.description)),
                        "Found Tracks with Blank Description?");

            var shortTrack = tracks.OrderBy(x => x.track.Count).First().track;
            var geoJson    =
                await SpatialHelpers.GeoJsonWithLineStringFromCoordinateList(shortTrack, false,
                                                                             DebugTrackers.DebugProgressTracker());

            var shortTrackFromGeoJson =
                SpatialHelpers.CoordinateListFromGeoJsonFeatureCollectionWithLinestring(geoJson);

            Assert.AreEqual(shortTrack.Count, shortTrackFromGeoJson.Count, "Count of Track Points does not match");

            for (var i = 0; i < shortTrack.Count; i++)
            {
                Assert.AreEqual(shortTrack[i].X, shortTrackFromGeoJson[i].X, $"Point {i} X Values don't match");
                Assert.AreEqual(shortTrack[i].Y, shortTrackFromGeoJson[i].Y, $"Point {i} Y Values don't match");
                Assert.AreEqual(shortTrack[i].Z, shortTrackFromGeoJson[i].Z, $"Point {i} Z Values don't match");
            }
        }
        public async Task Line_GpxLineFromHorseshoeMesaFileWithMeasurements()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "GrandCanyonHorseShoeMesaEastSideLoop.gpx"));

            Assert.True(testFile.Exists, "Test File Found");

            var tracks = await SpatialHelpers.TracksFromGpxFile(testFile, DebugTrackers.DebugProgressTracker());

            Assert.AreEqual(1, tracks.Count, "Should find 1 track");

            var coordinateList = tracks.First().track;

            var metricStats   = SpatialHelpers.LineStatsInMetricFromCoordinateList(coordinateList);
            var imperialStats = SpatialHelpers.LineStatsInImperialFromMetricStats(metricStats);

            Assert.IsTrue(imperialStats.Length.IsApproximatelyEqualTo(13, .3),
                          $"ExpertGPS Length 13.03, Measured {imperialStats.Length}");
            Assert.IsTrue(imperialStats.ElevationClimb.IsApproximatelyEqualTo(9000, 100),
                          $"ExpertGPS Climb 9023, Measured {imperialStats.ElevationClimb}");
            Assert.IsTrue(imperialStats.ElevationDescent.IsApproximatelyEqualTo(8932, 100),
                          $"ExpertGPS Descent 8932, Measured {imperialStats.ElevationDescent}");
            Assert.IsTrue(imperialStats.MinimumElevation.IsApproximatelyEqualTo(3591, 30),
                          $"ExpertGPS Min Elevation 13.03, Measured {imperialStats.MinimumElevation}");
            Assert.IsTrue(imperialStats.MaximumElevation.IsApproximatelyEqualTo(7384, 30),
                          $"ExpertGPS Max Elevation 13.03, Measured {imperialStats.MaximumElevation}");
        }
        public async Task Line_SanPedroTwoTrackFile()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "TwoTrackGpxNearTheSanPedro.gpx"));

            Assert.True(testFile.Exists, "Test File Found");

            var tracks = await SpatialHelpers.TracksFromGpxFile(testFile, DebugTrackers.DebugProgressTracker());

            Assert.AreEqual(2, tracks.Count, "Should find 2 tracks");
            Assert.True(tracks.All(x => !string.IsNullOrWhiteSpace(x.description)),
                        "Found Tracks with Blank Description?");

            var shortTrack = tracks.OrderBy(x => x.track.Count).First().track;

            Assert.AreEqual(214, shortTrack.Count, "Unexpected Point Count");

            var preElevationReplacementStats = SpatialHelpers.LineStatsInImperialFromCoordinateList(shortTrack);

            Assert.IsTrue(preElevationReplacementStats.Length.IsApproximatelyEqualTo(2.8, .05),
                          $"ExpertGPS Length 2.79, Measured {preElevationReplacementStats.Length}");
            Assert.IsTrue(preElevationReplacementStats.ElevationClimb.IsApproximatelyEqualTo(158, 1),
                          $"ExpertGPS Climb 158.4, Measured {preElevationReplacementStats.ElevationClimb}");
            Assert.IsTrue(preElevationReplacementStats.ElevationDescent.IsApproximatelyEqualTo(285, 1),
                          $"ExpertGPS Descent 285.6, Measured {preElevationReplacementStats.ElevationDescent}");
            Assert.IsTrue(preElevationReplacementStats.MinimumElevation.IsApproximatelyEqualTo(3795, 1),
                          $"ExpertGPS Min Elevation 3795.25, Measured {preElevationReplacementStats.MinimumElevation}");
            Assert.IsTrue(preElevationReplacementStats.MaximumElevation.IsApproximatelyEqualTo(3944, 1),
                          $"ExpertGPS Max Elevation 3944.76, Measured {preElevationReplacementStats.MaximumElevation}");

            await ElevationService.OpenTopoMapZenElevation(new HttpClient(), shortTrack,
                                                           DebugTrackers.DebugProgressTracker());

            Assert.True(shortTrack.All(x => x.Z > 0), "After Elevation replacement some 0 values found");

            var postElevationReplacementStats = SpatialHelpers.LineStatsInImperialFromCoordinateList(shortTrack);

            Assert.IsTrue(postElevationReplacementStats.Length.IsApproximatelyEqualTo(2.8, .05),
                          $"ExpertGPS Length 2.79, Measured {preElevationReplacementStats.Length}");
            Assert.IsTrue(postElevationReplacementStats.ElevationClimb.IsApproximatelyEqualTo(36.08, 1),
                          $"Expected 36.08, Measured {preElevationReplacementStats.ElevationClimb}");
            Assert.IsTrue(postElevationReplacementStats.ElevationDescent.IsApproximatelyEqualTo(187, 1),
                          $"Expected 187, Measured {preElevationReplacementStats.ElevationDescent}");
            Assert.IsTrue(postElevationReplacementStats.MinimumElevation.IsApproximatelyEqualTo(3891.07, 1),
                          $"Expected 3891, Measured {preElevationReplacementStats.MinimumElevation}");
            Assert.IsTrue(postElevationReplacementStats.MaximumElevation.IsApproximatelyEqualTo(4041.99, 1),
                          $"Expected 4041, Measured {preElevationReplacementStats.MaximumElevation}");
        }
        public async Task L01_HorseshoeMesaLineContent()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "GrandCanyonHorseShoeMesaEastSideLoop.gpx"));

            Assert.True(testFile.Exists, "GPX Test File Found");

            var lineTest = new LineContent
            {
                ContentId         = Guid.NewGuid(),
                BodyContent       = "Horseshoe Mesa East Side Loop",
                BodyContentFormat = ContentFormatDefaults.Content.ToString(),
                CreatedOn         = DateTime.Now,
                CreatedBy         = "GPX Import Test",
                Folder            = "GrandCanyon",
                Title             = "Horseshoe Mesa East Side Loop",
                Slug = "horseshoe-mesa-east-side-loop",
                ShowInMainSiteFeed = true,
                Summary            = "Horseshoe Mesa East Side Loop",
                Tags = "grand-canyon, horse-shoe-mesa",
                UpdateNotesFormat = ContentFormatDefaults.Content.ToString()
            };

            var track = (await SpatialHelpers.TracksFromGpxFile(testFile, DebugTrackers.DebugProgressTracker()))
                        .First();

            var stats = SpatialHelpers.LineStatsInMetricFromCoordinateList(track.track);

            lineTest.ClimbElevation   = stats.ElevationClimb;
            lineTest.DescentElevation = stats.ElevationDescent;
            lineTest.MinimumElevation = stats.MinimumElevation;
            lineTest.MaximumElevation = stats.MaximumElevation;
            lineTest.LineDistance     = stats.Length;

            lineTest.Line =
                await SpatialHelpers.GeoJsonWithLineStringFromCoordinateList(track.track, false,
                                                                             DebugTrackers.DebugProgressTracker());

            var validationResult = await LineGenerator.Validate(lineTest);

            Assert.IsFalse(validationResult.HasError);

            var saveResult =
                await LineGenerator.SaveAndGenerateHtml(lineTest, null, DebugTrackers.DebugProgressTracker());

            Assert.IsFalse(saveResult.generationReturn.HasError);
        }