private List <IOsmProcessor> Build(OsmLayer layers, bool computeElevations = false, GeoTransformPipeline transform = null, bool withBuildingsColors = false, string defaultBuildingsColor = null) { List <IOsmProcessor> processors = new List <IOsmProcessor>(); if (layers.HasFlag(OsmLayer.Buildings)) { processors.Add(new OsmBuildingProcessor(transform, withBuildingsColors, defaultBuildingsColor)); } if (layers.HasFlag(OsmLayer.Railway)) { processors.Add(new OsmRailwayProcessor(transform)); } if (layers.HasFlag(OsmLayer.Water)) { processors.Add(new OsmWaterProcessor(transform)); } if (layers.HasFlag(OsmLayer.Highways)) { var processor = new OsmHighwayProcessor(transform); if (computeElevations) { processor.AddPostTransform(p => p.ZTranslate(_options.RenderGpxZTranslateTrackMeters)); } processors.Add(processor); } if (layers.HasFlag(OsmLayer.PisteSki)) { var processor = new OsmPisteSkiProcessor(transform); if (computeElevations) { processor.AddPostTransform(p => p.ZTranslate(_options.RenderGpxZTranslateTrackMeters)); } processors.Add(processor); } return(processors); }
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)}"); } }