private async Task SetDataContainerAndLength(PointOfInterestExtended poiItem, Feature feature) { ElevationSetterHelper.SetElevation(feature.Geometry, _elevationDataStorage); poiItem.FeatureCollection = new FeatureCollection { feature }; poiItem.DataContainer = await _dataContainerConverterService.ToDataContainer( poiItem.FeatureCollection.ToBytes(), poiItem.Title + ".geojson"); foreach (var coordinate in poiItem.DataContainer.Routes .SelectMany(r => r.Segments) .SelectMany(s => s.Latlngs) .Where(l => l.Alt == null || l.Alt.Value == 0)) { coordinate.Alt = await _elevationDataStorage.GetElevation(coordinate.ToCoordinate()); } foreach (var route in poiItem.DataContainer.Routes) { var itmRoute = route.Segments.SelectMany(s => s.Latlngs) .Select(l => _wgs84ItmMathTransform.Transform(l.ToCoordinate().ToDoubleArray())) .Select(c => c.ToCoordinate()).ToArray(); var skip1 = itmRoute.Skip(1); poiItem.LengthInKm += itmRoute.Zip(skip1, (curr, prev) => curr.Distance(prev)).Sum() / 1000; } }
public async Task <IActionResult> GetRouting(string from, string to, string type) { LineString lineString; var profile = ConvertProfile(type); var pointFrom = await GetGeographicPosition(from); var pointTo = await GetGeographicPosition(to); if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } if (profile == ProfileType.None) { lineString = GetDenseStraightLine(pointFrom, pointTo); } else { lineString = await _graphHopperGateway.GetRouting(new RoutingGatewayRequest { From = from, To = to, Profile = profile, }); if (!lineString.Coordinates.Any()) { lineString = _geometryFactory.CreateLineString(new[] { pointFrom, pointTo }) as LineString; } } ElevationSetterHelper.SetElevation(lineString, _elevationDataStorage); var table = new AttributesTable { { "Name", "Routing from " + @from + " to " + to + " profile type: " + profile }, { "Creator", "IsraelHikingMap" } }; var feature = new Feature(lineString, table); return(Ok(new FeatureCollection { feature })); }