/// <summary> /// Adds extended data to point of interest object /// </summary> /// <param name="poiItem">The object to add properties to</param> /// <param name="feature">The feature for reference</param> /// <param name="language">he user interface language</param> /// <returns></returns> protected async Task AddExtendedData(PointOfInterestExtended poiItem, IFeature feature, string language) { foreach (var coordinate in feature.Geometry.Coordinates) { coordinate.Z = await _elevationDataStorage.GetElevation(coordinate); } poiItem.DataContainer = await _dataContainerConverterService.ToDataContainer(new FeatureCollection(new Collection <IFeature> { feature }).ToBytes(), poiItem.Title + ".geojson"); poiItem.Url = feature.Attributes.GetNames().Contains(FeatureAttributes.WEBSITE) ? feature.Attributes[FeatureAttributes.WEBSITE].ToString() : string.Empty; poiItem.ImagesUrls = feature.Attributes.GetNames() .Where(n => n.StartsWith(FeatureAttributes.IMAGE_URL)) .Select(n => feature.Attributes[n].ToString()) .ToArray(); poiItem.SourceImageUrl = feature.Attributes.GetNames().Contains(FeatureAttributes.SOURCE_IMAGE_URL) ? feature.Attributes[FeatureAttributes.SOURCE_IMAGE_URL].ToString() : string.Empty; poiItem.Description = GetAttributeByLanguage(feature.Attributes, FeatureAttributes.DESCRIPTION, language); poiItem.Rating = await _elasticSearchGateway.GetRating(poiItem.Id, poiItem.Source); poiItem.IsEditable = true; }
/// <summary> /// Adds extended data to point of interest object /// </summary> /// <param name="poiItem">The object to add properties to</param> /// <param name="feature">The feature for reference</param> /// <param name="language">he user interface language</param> /// <returns></returns> protected async Task AddExtendedData(PointOfInterestExtended poiItem, IFeature feature, string language) { foreach (var coordinate in feature.Geometry.Coordinates) { coordinate.Z = await _elevationDataStorage.GetElevation(coordinate); } poiItem.DataContainer = await _dataContainerConverterService.ToDataContainer(new FeatureCollection(new Collection <IFeature> { feature }).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(new Coordinate().FromLatLng(coordinate)); } poiItem.Url = GetWebsiteUrl(feature); poiItem.ImagesUrls = feature.Attributes.GetNames() .Where(n => n.StartsWith(FeatureAttributes.IMAGE_URL)) .Select(n => feature.Attributes[n].ToString()) .ToArray(); poiItem.SourceImageUrl = feature.Attributes.GetNames().Contains(FeatureAttributes.SOURCE_IMAGE_URL) ? feature.Attributes[FeatureAttributes.SOURCE_IMAGE_URL].ToString() : string.Empty; poiItem.Description = GetAttributeByLanguage(feature.Attributes, FeatureAttributes.DESCRIPTION, language); poiItem.Rating = await _elasticSearchGateway.GetRating(poiItem.Id, poiItem.Source); poiItem.IsEditable = false; }
private async Task SetDataContainerAndLength(PointOfInterestExtended poiItem, FeatureCollection featureCollection) { foreach (var coordinate in featureCollection.Features.SelectMany(f => f.Geometry.Coordinates)) { coordinate.Z = await _elevationDataStorage.GetElevation(coordinate); } poiItem.FeatureCollection = featureCollection; poiItem.DataContainer = await _dataContainerConverterService.ToDataContainer( 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(new Coordinate().FromLatLng(coordinate)); } foreach (var route in poiItem.DataContainer.Routes) { var itmRoute = route.Segments.SelectMany(s => s.Latlngs) .Select(l => _wgs84ItmMathTransform.Transform(new Coordinate().FromLatLng(l))).ToArray(); var skip1 = itmRoute.Skip(1); poiItem.LengthInKm += itmRoute.Zip(skip1, (curr, prev) => curr.Distance(prev)).Sum() / 1000; } }
private async Task <DataContainer> ConvertToDataContainer(byte[] data, string fileName) { var dataContainer = await _dataContainerConverterService.ToDataContainer(data, fileName); foreach (var latLng in dataContainer.routes.SelectMany(routeData => routeData.segments.SelectMany(routeSegmentData => routeSegmentData.latlngs))) { latLng.alt = await _elevationDataStorage.GetElevation(new Coordinate().FromLatLng(latLng)); } return(dataContainer); }
public void GetPointsOfInterestById_RouteWithMultipleImagesAndDescriptionOnly_ShouldReturnIt() { var poiId = "poiId"; var feature = GetValidFeature(poiId, _adapter.Source); feature.Attributes.DeleteAttribute(FeatureAttributes.NAME); feature.Attributes.AddAttribute(FeatureAttributes.IMAGE_URL, FeatureAttributes.IMAGE_URL); feature.Attributes.AddAttribute(FeatureAttributes.IMAGE_URL + "1", FeatureAttributes.IMAGE_URL + "1"); feature.Attributes.AddAttribute(FeatureAttributes.DESCRIPTION, FeatureAttributes.DESCRIPTION); feature.Attributes.AddAttribute(FeatureAttributes.POI_TYPE, FeatureAttributes.POI_TYPE); _elasticSearchGateway.GetPointOfInterestById(poiId, _adapter.Source, Arg.Any <string>()).Returns(feature); _dataContainerConverterService.ToDataContainer(Arg.Any <byte[]>(), Arg.Any <string>()).Returns( new DataContainer { routes = new List <RouteData> { new RouteData { segments = new List <RouteSegmentData> { new RouteSegmentData(), new RouteSegmentData() } } } }); var result = _adapter.GetPointOfInterestById(poiId, null).Result; Assert.IsNotNull(result); Assert.AreEqual(string.Empty, result.Title); Assert.AreEqual(FeatureAttributes.DESCRIPTION, result.Description); Assert.AreEqual(2, result.ImagesUrls.Length); Assert.AreEqual(FeatureAttributes.IMAGE_URL, result.ImagesUrls.First()); Assert.IsTrue(result.IsRoute); }
public async Task <DataContainer> GetTraceById(int id) { var gateway = CreateClient(); var file = await gateway.GetTraceData(id); using (MemoryStream memoryStream = new MemoryStream()) { file.Stream.CopyTo(memoryStream); var dataContainer = await _dataContainerConverterService.ToDataContainer(memoryStream.ToArray(), file.FileName); foreach (var latLng in dataContainer.Routes.SelectMany(routeData => routeData.Segments.SelectMany(routeSegmentData => routeSegmentData.Latlngs))) { latLng.Alt = await _elevationDataStorage.GetElevation(latLng.ToCoordinate()); } return(dataContainer); } }
public void ConvertGpxToDataContainer_ShouldConvertToDataContainer() { var results = _converterService.ToDataContainer(_simpleGpx.ToBytes(), FlowFormats.GPX).Result; Assert.AreEqual(1, results.Routes.Count); }