Ejemplo n.º 1
0
        public int GetOsmDataCount(BoundingBox bbox, IOsmDataSettings filter)
        {
            try
            {
                using (TimeSpanBlock timeSpanBlock = new TimeSpanBlock("GetOsmDataAsGeoJson", _logger, LogLevel.Debug))
                {
                    OverpassQuery query = new OverpassQuery(bbox, _logger);
                    if (filter != null)
                    {
                        if (filter.WaysFilter != null)
                        {
                            foreach (var tagFilter in filter.WaysFilter)
                            {
                                query.WithWays(tagFilter);
                            }
                        }
                        if (filter.RelationsFilter != null)
                        {
                            foreach (var tagFilter in filter.RelationsFilter)
                            {
                                query.WithRelations(tagFilter);
                            }
                        }
                        if (filter.NodesFilter != null)
                        {
                            foreach (var tagFilter in filter.NodesFilter)
                            {
                                query.WithNodes(tagFilter);
                            }
                        }
                    }

                    var task = query.AsCount()
                               .RunQueryAsync()
                               .ToCountAsync();

                    OverpassCountResult count = task.GetAwaiter().GetResult();

                    return(count.Tags.Nodes * 2);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"{nameof(GetOsmDataAsGeoJson)} error: {ex.Message}");
                throw;
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <IFeature> GetOsmDataAsGeoJson(BoundingBox bbox, IOsmDataSettings filter)
        {
            try
            {
                using (TimeSpanBlock timeSpanBlock = new TimeSpanBlock(nameof(GetOsmDataAsGeoJson), _logger, LogLevel.Debug))
                {
                    OverpassQuery query = new OverpassQuery(bbox, _logger);
                    if (filter != null)
                    {
                        if (filter.WaysFilter != null)
                        {
                            foreach (var tagFilter in filter.WaysFilter)
                            {
                                query.WithWays(tagFilter);
                            }
                        }
                        if (filter.RelationsFilter != null)
                        {
                            foreach (var tagFilter in filter.RelationsFilter)
                            {
                                query.WithRelations(tagFilter);
                            }
                        }
                        if (filter.NodesFilter != null)
                        {
                            foreach (var tagFilter in filter.NodesFilter)
                            {
                                query.WithNodes(tagFilter);
                            }
                        }
                    }

                    var task = query.ToGeoJSONAsync();

                    FeatureCollection ways = task.GetAwaiter().GetResult();

                    _logger.LogInformation($"{ways?.Count} features downloaded");

                    return(ways);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"{nameof(GetOsmDataAsGeoJson)} error: {ex.Message}");
                throw;
            }
        }