private async Task <PointOfInterestExtended> FeatureToExtendedPoi(Feature feature, string language) { var poiItem = await ConvertToPoiItem <PointOfInterestExtended>(feature, language); await AddExtendedData(poiItem, feature, language); poiItem.IsRoute = poiItem.DataContainer.routes.Any(r => r.segments.Count > 1); poiItem.IsEditable = _tagsHelper.GetAllTags() .Any(t => feature.Attributes.GetNames().Contains(t.Key) && feature.Attributes[t.Key].Equals(t.Value)); return(poiItem); }
private async Task UpdatePointsOfInterest(OsmChange changes) { var deleteTasks = new List <Task>(); var relevantTagsDictionary = _tagsHelper.GetAllTags(); foreach (var poiToRemove in changes.Delete) { var task = _elasticSearchGateway.DeletePointOfInterestById(poiToRemove.Id.ToString(), poiToRemove.Type.ToString().ToLower()); deleteTasks.Add(task); } await Task.WhenAll(deleteTasks); var updateTasks = new List <Task <ICompleteOsmGeo> >(); foreach (var poiToUpdate in changes.Modify .Concat(changes.Create) .Where(o => IsRelevantPointOfInterest(o, relevantTagsDictionary))) { var task = _osmGateway.GetElement(poiToUpdate.Id.ToString(), poiToUpdate.Type.ToString().ToLower()); updateTasks.Add(task); } var allElemets = await Task.WhenAll(updateTasks); var osmNamesDictionary = allElemets.GroupBy(e => e.Tags.GetName()).ToDictionary(g => g.Key, g => g.ToList()); var geoJsonNamesDictionary = _osmGeoJsonPreprocessorExecutor.Preprocess(osmNamesDictionary); await _elasticSearchGateway.UpdatePointsOfInterestData(geoJsonNamesDictionary.Values.SelectMany(v => v).ToList()); }
private async Task UpdatePointsOfInterest(OsmChange changes) { var deleteTasks = new List <Task>(); var relevantTagsDictionary = _tagsHelper.GetAllTags(); foreach (var poiToRemove in changes.Delete) { var task = _elasticSearchGateway.DeleteOsmPointOfInterestById(poiToRemove.Type.ToString().ToLower() + "_" + poiToRemove.Id); deleteTasks.Add(task); } await Task.WhenAll(deleteTasks); var updateTasks = new List <Task <ICompleteOsmGeo> >(); foreach (var poiToUpdate in changes.Modify .Concat(changes.Create) .Where(o => IsRelevantPointOfInterest(o, relevantTagsDictionary))) { var task = _osmGateway.GetCompleteElement(poiToUpdate.Id.Value, poiToUpdate.Type); updateTasks.Add(task); } var allElemets = await Task.WhenAll(updateTasks); var osmNamesDictionary = allElemets.GroupBy(e => e.Tags.GetName()).ToDictionary(g => g.Key, g => g.ToList()); var features = _osmGeoJsonPreprocessorExecutor.Preprocess(osmNamesDictionary); foreach (var poiToUpdate in changes.Modify .Where(o => IsRelevantPointOfInterest(o, relevantTagsDictionary))) { var featureFromDb = await _elasticSearchGateway.GetPointOfInterestById(poiToUpdate.Type.ToString().ToLower() + "_" + poiToUpdate.Id, Sources.OSM); if (featureFromDb == null) { continue; } var featureToUpdate = features.First(f => f.GetId().Equals(featureFromDb.GetId())); foreach (var attributeKey in featureFromDb.Attributes.GetNames().Where(n => n.StartsWith(FeatureAttributes.POI_PREFIX))) { featureToUpdate.Attributes.AddOrUpdate(attributeKey, featureFromDb.Attributes[attributeKey]); } if (featureToUpdate.Geometry.OgcGeometryType == OgcGeometryType.Point && featureFromDb.Geometry.OgcGeometryType != OgcGeometryType.Point) { featureToUpdate.Geometry = featureFromDb.Geometry; } } await _elasticSearchGateway.UpdatePointsOfInterestData(features); }
/// <inheritdoc /> public override async Task <List <Feature> > GetPointsForIndexing() { _logger.LogInformation("Starting getting OSM points of interest"); using (var stream = _latestFileFetcherExecutor.Get()) { var osmNamesDictionary = await _osmRepository.GetElementsWithName(stream); var relevantTagsDictionary = _tagsHelper.GetAllTags(); var namelessNodes = await _osmRepository.GetPointsWithNoNameByTags(stream, relevantTagsDictionary); osmNamesDictionary.Add(string.Empty, namelessNodes.Cast <ICompleteOsmGeo>().ToList()); var features = _osmGeoJsonPreprocessorExecutor.Preprocess(osmNamesDictionary); _logger.LogInformation("Finished getting OSM points of interest: " + features.Count); return(features); } }