public void TestElevationLine(string dataSetName, double latStart, double lonStart, double latEnd, double lonEnd, double expectedPointCount, double expectedClimb, double expectedDescent, double expectedMin, double expectedMax) { var elevationLine = GeometryService.ParseGeoPointAsGeometryLine(new GeoPoint(latStart, lonStart), new GeoPoint(latEnd, lonEnd)); Assert.NotNull(elevationLine); Assert.Equal(2, elevationLine.Coordinates.Length); DEMDataSet dataSet = DEMDataSet.RegisteredDatasets.FirstOrDefault(d => d.Name == dataSetName); Assert.NotNull(dataSet); _elevationService.DownloadMissingFiles(dataSet, elevationLine.GetBoundingBox()); var geoPoints = _elevationService.GetLineGeometryElevation(elevationLine, dataSet); Assert.NotNull(geoPoints); Assert.Equal(expectedPointCount, geoPoints.Count); var metrics = geoPoints.ComputeMetrics(); Assert.NotNull(metrics); Assert.Equal(expectedClimb, metrics.Climb, 3); Assert.Equal(expectedDescent, metrics.Descent, 3); Assert.Equal(expectedMin, metrics.MinElevation, 3); Assert.Equal(expectedMax, metrics.MaxElevation, 3); }
private static void GeoTiffBenchmark() { DEMDataSet dataSet = DEMDataSet.AW3D30; ElevationService elevationServiceLibTiff = new ElevationService(new GeoTiffService(_DataDirectory)); string wkt = WKT_BREST_NICE; elevationServiceLibTiff.DownloadMissingFiles(dataSet, GetBoundingBox(wkt)); const int NUM_ITERATIONS = 10; Stopwatch swCoreTiff = new Stopwatch(); Stopwatch swGeoTiff = new Stopwatch(); for (int j = 0; j < 5; j++) { for (int i = 0; i < NUM_ITERATIONS; i++) { swGeoTiff.Start(); var lineElevationData = elevationServiceLibTiff.GetLineGeometryElevation(wkt, dataSet, InterpolationMode.Hyperbolic); swGeoTiff.Stop(); } } long geoTiffMs = swGeoTiff.ElapsedMilliseconds; long codeTiffMs = swCoreTiff.ElapsedMilliseconds; Console.WriteLine($"GeoTiff : {geoTiffMs} ms, Native : {codeTiffMs}"); }
public IHttpActionResult GetPathElevation(Location[] path, int samples = 100) { try { var geoPoints = ModelFactory.Create(path); var geom = GeometryService.ParseGeoPointAsGeometryLine(geoPoints); _elevationService.DownloadMissingFiles(DEMDataSet.AW3D30, geom.GetBoundingBox()); geoPoints = _elevationService.GetLineGeometryElevation(geom, DEMDataSet.AW3D30, InterpolationMode.Bilinear); ElevationMetrics metrics = GeometryService.ComputeMetrics(geoPoints); if (samples > 2) { double ratio = 4 / 2; double tolerance = (metrics.MaxElevation - metrics.MinElevation) / (samples / ratio); geoPoints = DouglasPeucker.DouglasPeuckerReduction(geoPoints, tolerance); } // Model ElevationMetricsModel metricsModel = ModelFactory.CreateElevationMetricsModel(geoPoints, metrics); var feature = ModelFactory.CreateFeature(geoPoints, metricsModel); return(Ok(feature)); } catch (Exception ex) { return(InternalServerError(new Exception(ex.Message))); } }
private void LineSample(DEMDataSet dataSet, double latStart, double lonStart, double latEnd, double lonEnd) { var elevationLine = GeometryService.ParseGeoPointAsGeometryLine(new GeoPoint(latStart, lonStart), new GeoPoint(latEnd, lonEnd)); _elevationService.DownloadMissingFiles(dataSet, elevationLine.GetBoundingBox()); var geoPoints = _elevationService.GetLineGeometryElevation(elevationLine, dataSet); }
static void LineDEMBenchmark(ElevationService elevationService, DEMDataSet dataSet, int numSamples) { Dictionary <string, string> dicWktByName = new Dictionary <string, string>(); //dicWktByName.Add(nameof(WKT_EXAMPLE_GOOGLE), WKT_EXAMPLE_GOOGLE); // Before GeoTiff window optim : 90s // After GeoTiff optim : 77s / release : 60s; dicWktByName.Add(nameof(WKT_BREST_NICE), WKT_BREST_NICE); dicWktByName.Add(nameof(WKT_HORIZONTAL_DEM_EDGE), WKT_HORIZONTAL_DEM_EDGE); dicWktByName.Add(nameof(WKT_VERTICAL_DEM_EDGE), WKT_VERTICAL_DEM_EDGE); dicWktByName.Add(nameof(WKT_MONACO), WKT_MONACO); dicWktByName.Add(nameof(WKT_TEST), WKT_TEST); dicWktByName.Add(nameof(WKT_NO_DEM), WKT_NO_DEM); dicWktByName.Add(nameof(WKT_ZERO), WKT_ZERO); dicWktByName.Add(nameof(WKT_NEG100), WKT_NEG100); dicWktByName.Add(nameof(WKT_BREST_SPAIN_OCEAN), WKT_BREST_SPAIN_OCEAN); dicWktByName.Add(nameof(WKT_EXAMPLE_GOOGLE), WKT_EXAMPLE_GOOGLE); dicWktByName.Add(nameof(WKT_PARIS_AIX), WKT_PARIS_AIX); dicWktByName.Add(nameof(WKT_PETITE_BOUCLE), WKT_PETITE_BOUCLE); dicWktByName.Add(nameof(WKT_GRAND_TRAJET), WKT_GRAND_TRAJET); dicWktByName.Add(nameof(WKT_GRAND_TRAJET_MARSEILLE_ALPES_MULTIPLE_TILES), WKT_GRAND_TRAJET_MARSEILLE_ALPES_MULTIPLE_TILES); dicWktByName.Add(nameof(WKT_BAYONNE_AIX_OUEST_EST), WKT_BAYONNE_AIX_OUEST_EST); dicWktByName.Add(nameof(WKT_AIX_BAYONNE_EST_OUEST), WKT_AIX_BAYONNE_EST_OUEST); dicWktByName.Add(nameof(WKT_BAYONNE_NICE_DIRECT), WKT_BAYONNE_NICE_DIRECT); dicWktByName.Add(nameof(WKT_DEM_INTERPOLATION_BUG), WKT_DEM_INTERPOLATION_BUG); Stopwatch sw = Stopwatch.StartNew(); InterpolationMode[] modes = { InterpolationMode.Bilinear, InterpolationMode.Hyperbolic }; for (int i = 0; i < 5; i++) { foreach (var wkt in dicWktByName) { elevationService.DownloadMissingFiles(dataSet, GetBoundingBox(wkt.Value)); foreach (InterpolationMode mode in modes) { var lineElevationData = elevationService.GetLineGeometryElevation(wkt.Value, dataSet, mode); ElevationMetrics metrics = GeometryService.ComputeMetrics(ref lineElevationData); //var sampledLineElevationData = ReduceList(lineElevationData, numSamples).ToList(); //File.WriteAllText($"ElevationData_{wkt.Key}_{mode}.txt", elevationService.ExportElevationTable(lineElevationData)); //File.WriteAllText($"ElevationData_{wkt.Key}_{mode}_{numSamples}samples.txt", elevationService.ExportElevationTable(sampledLineElevationData)); } } } sw.Stop(); Console.WriteLine($"LineDEMTests performed in {sw.Elapsed:g}."); }
static void LineDEMTest(ElevationService elevationService, DEMDataSet dataSet, string wkt, int numSamples) { Stopwatch sw = Stopwatch.StartNew(); elevationService.DownloadMissingFiles(dataSet, GetBoundingBox(wkt)); var lineElevationData = elevationService.GetLineGeometryElevation(wkt, dataSet, InterpolationMode.Bilinear); ElevationMetrics metrics = GeometryService.ComputeMetrics(ref lineElevationData); var lineElevationData_Reduced = DouglasPeucker.DouglasPeuckerReduction(lineElevationData, (metrics.MaxElevation - metrics.MinElevation) / numSamples); sw.Stop(); Console.WriteLine($"LineDEMTest performed in {sw.Elapsed:g}."); SpatialTrace.Enable(); SpatialTrace.Clear(); SpatialTraceLine(lineElevationData, $"Full resolution line ({lineElevationData.Count} points)"); SpatialTraceLine(lineElevationData_Reduced, $"Reduced line ({lineElevationData_Reduced.Count} points)"); SpatialTrace.ShowDialog(); }
public void Run() { try { // ventoux //double lat1 = 44.17346; //double lon1 = 5.27829; // ste victoire //double lat1 = 43.532456; //double lon1 = 5.612444; // bottom ste victoire (fuveau) //double lat1 = 43.49029208393125; //double lon1 = 5.587234497070313; //double lat2 = 43.53013134607789; //double lon2 = 5.581398010253906; // geneva //double lat1 = 46.08129825372404; //double lon1 = 3.382026672363281; // mont blanc //double lat2 = 45.833; //double lon2 = 6.864; // bob //double lat1 = 37.212627; //double lon1 = 22.321612; //double lat2 = 37.208179; //double lon2 = 22.324373; double lat2 = 44.116655590545705; double lat1 = 44.19524951146881; double lon2 = 5.802505910396577; double lon1 = 5.806566774845124; Stopwatch sw = new Stopwatch(); _logger.LogInformation("Line elevation"); sw.Restart(); // Line starting at mont ventoux peak to Mont Blanc DEMDataSet dataSet = DEMDataSet.ASTER_GDEMV3; // High level way var metrics = _elevationService.GetIntervisibilityReport(new GeoPoint(lat1, lon1), new GeoPoint(lat2, lon2), dataSet , downloadMissingFiles: true, sourceVerticalOffset: 0); PlotVisibilityReport(metrics, 2048, 600, "VisReport.png"); // Low level (tests from 0 to 2000 m) var elevationLine = GeometryService.ParseGeoPointAsGeometryLine(new GeoPoint(lat1, lon1), new GeoPoint(lat2, lon2)); var geoPoints = _elevationService.GetLineGeometryElevation(elevationLine, dataSet); for (int i = 300; i < 10000; i += 500) { var report = _elevationService.GetIntervisibilityReport(geoPoints, i); PlotVisibilityReport(report, 2048, 600, $"VisReport_{i}.png"); } _logger.LogInformation($"{dataSet.Name} metrics: {metrics.ToString()}"); //var geoJson = ConvertLineElevationResultToGeoJson(simplified); _logger.LogInformation($"Done in {sw.Elapsed.TotalMilliseconds:N1}ms"); } catch (Exception ex) { _logger.LogError(ex, ex.Message); } }
public void Run() { try { double lat1 = 46.00000000000004; double lon1 = 10.000000000000007; double lat2 = 45.212278; double lont2 = 5.468857; _logger.LogInformation($"Getting location elevation for each dataset (location lat: {lat1:N2}, lon: {lon1:N2})"); Stopwatch sw = new Stopwatch(); Parallel.ForEach(DEMDataSet.RegisteredNonLocalDatasets, (dataSet, loopState) => //foreach (var dataSet in DEMDataSet.RegisteredNonSingleFileDatasets) { sw.Restart(); _elevationService.DownloadMissingFiles(dataSet, lat1, lon1); GeoPoint geoPoint = _elevationService.GetPointElevation(lat1, lon1, dataSet); _logger.LogInformation($"{dataSet.Name} elevation: {geoPoint.Elevation:N2} (time taken: {sw.Elapsed.TotalMilliseconds:N1}ms)"); } ); _logger.LogInformation("Multiple point elevation"); sw.Restart(); GeoPoint pt1 = new GeoPoint(lat1, lon1); GeoPoint pt2 = new GeoPoint(lat2, lont2); GeoPoint[] points = { pt1, pt2 }; Parallel.ForEach(DEMDataSet.RegisteredNonLocalDatasets, (dataSet, loopState) => //foreach (var dataSet in DEMDataSet.RegisteredNonSingleFileDatasets) { sw.Restart(); var geoPoints = _elevationService.GetPointsElevation(points, dataSet); _logger.LogInformation($"{dataSet.Name} elevation: {string.Join(" / ", geoPoints.Select(e => e.Elevation.GetValueOrDefault().ToString("N2")))} (time taken: {sw.Elapsed.TotalMilliseconds:N1}ms)"); } ); _logger.LogInformation("Line elevation"); sw.Restart(); // Line passing by mont ventoux peak [5.144899, 44.078873], [5.351516, 44.225876] var elevationLine = GeometryService.ParseGeoPointAsGeometryLine(new GeoPoint(44.078873, 5.144899), new GeoPoint(44.225876, 5.351516)); Parallel.ForEach(DEMDataSet.RegisteredNonLocalDatasets, (dataSet, loopState) => //foreach (var dataSet in DEMDataSet.RegisteredNonSingleFileDatasets) { _elevationService.DownloadMissingFiles(dataSet, elevationLine.GetBoundingBox()); var geoPoints = _elevationService.GetLineGeometryElevation(elevationLine, dataSet); var metrics = geoPoints.ComputeMetrics(); _logger.LogInformation($"{dataSet.Name} metrics: {metrics.ToString()}"); var simplified = geoPoints.Simplify(50 /* meters */); _logger.LogInformation($"{dataSet.Name} after reduction : {simplified.Count} points"); var geoJson = ConvertLineElevationResultToGeoJson(simplified); } ); _logger.LogInformation($"Done in {sw.Elapsed.TotalMilliseconds:N1}ms"); } catch (Exception ex) { _logger.LogError(ex, ex.Message); } }
public void Run() { try { // SF GeoPoint location4326 = new GeoPoint(37.766974, -122.431062); //GeoPoint location4326 = new GeoPoint( 43.542544, 5.445379); DEMDataSet dataset = DEMDataSet.NASADEM; double radius = 5000; GeoPoint location3857 = location4326.ReprojectTo(4326, 3857); BoundingBox bbox3857 = BoundingBox.AroundPoint(location3857, radius); // 5km around point bbox3857.SRID = 3857; BoundingBox bbox4326 = bbox3857.ReprojectTo(Reprojection.SRID_PROJECTED_MERCATOR, Reprojection.SRID_GEODETIC); HeightMap heightMap = _elevationService.GetHeightMap(ref bbox4326, dataset); // Highest point var highest = heightMap.Coordinates.First(pt => pt.Elevation.Value == heightMap.Maximum); _logger.LogInformation($"Highest point: {highest} at {highest.DistanceTo(location4326)} meters"); OsmHighwayProcessor roadsProcessor = new OsmHighwayProcessor(GeoTransformPipeline.Default); // Download buildings and convert them to GeoJson IEnumerable <IFeature> features = _osmService.GetOsmDataAsGeoJson(bbox4326, BasicOsmDataFilter.Create(new string[] { "highway" })); // Create internal building model IEnumerable <HighwayModel> parsed = roadsProcessor.CreateModelsFromGeoJson <HighwayModel>(features, roadsProcessor.ModelFactory); int parallelCount = -1; Parallel.ForEach(parsed, new ParallelOptions { MaxDegreeOfParallelism = parallelCount }, model => //foreach(var model in parsed.Models) { model.LineString = _elevationService.GetLineGeometryElevation(model.LineString, dataset); } ); var osmRoads = parsed.ToDictionary(p => p.Id, p => p); var osmRoadLines = parsed.ToDictionary(p => p.Id, p => p.LineString); (Slope Slope, HighwayModel Road)maxSlope = (Slope.Zero, null); (Slope Slope, HighwayModel Road)maxAvgSlope = (Slope.Zero, null); foreach (var model in osmRoadLines) { var metrics = model.Value.ComputeMetrics(); var slope = GetMaxSlope(model.Value); if (slope > maxSlope.Slope) { maxSlope.Slope = slope; maxSlope.Road = osmRoads[model.Key]; } var slopeAvg = ComputeSlope(model.Value.First(), model.Value.Last()); if (slopeAvg > maxAvgSlope.Slope) { maxAvgSlope.Slope = slopeAvg; maxSlope.Road = osmRoads[model.Key]; } } //int parallelCount = -1; //Parallel.ForEach(parsed.Models, new ParallelOptions { MaxDegreeOfParallelism = parallelCount }, model => ////foreach (var model in parsed.Models) //{ // model.LineString =_elevationService.GetLineGeometryElevation(model.LineString, dataset); //} //); //osmRoadLines = parsed.Models.ToDictionary(p => p.Id, p => p.LineString); //maxSlope = (Slope.Zero, null); //maxAvgSlope = (Slope.Zero, null); //foreach (var model in osmRoadLines) //{ // var metrics = model.Value.ComputeMetrics(); // var slope = GetMaxSlope(model.Value); // if (slope > maxSlope.Slope) // { // maxSlope.Slope = slope; // maxSlope.Road = osmRoads[model.Key]; // } // var slopeAvg = ComputeSlope(model.Value.First(), model.Value.Last()); // if (slopeAvg > maxAvgSlope.Slope) // { // maxAvgSlope.Slope = slopeAvg; // maxSlope.Road = osmRoads[model.Key]; // } //} } catch (Exception ex) { _logger.LogError(ex, $"Error in {nameof(HighestPointFinder)}"); } }