public async Task<List<CompleteWay>> GetHighways(LatLng northEast, LatLng southWest) { var boundsString = string.Join(",", southWest.lat, southWest.lng, northEast.lat, northEast.lng); var address = $"{OVERPASS_INTERPRETER_ADDRESS}?data=(way[\"highway\"]({boundsString});>;);out;"; using (var client = new HttpClient()) { var response = await client.GetAsync(address); var source = new XmlOsmStreamSource(await response.Content.ReadAsStreamAsync()); var completeSource = new OsmSimpleCompleteStreamSource(source); return completeSource.OfType<CompleteWay>().ToList(); } }
public Task<List<CompleteWay>> GetAllHighways(string osmFilePath) { return Task.Run(() => { using (var stream = _fileSystemHelper.FileOpenRead(osmFilePath)) { _logger.Info($"Reading {osmFilePath} to memory - extracting only highways."); var source = new PBFOsmStreamSource(stream); var completeSource = new OsmSimpleCompleteStreamSource(source); var higways = completeSource .OfType<CompleteWay>() .Where(o => o.Tags.ContainsKey("highway")) .ToList(); _logger.Info("Finished getting highways. " + higways.Count); return higways; } }); }
public Task<Dictionary<string, List<ICompleteOsmGeo>>> GetElementsWithName(string osmFilePath) { return Task.Run(() => { using (var stream = _fileSystemHelper.FileOpenRead(osmFilePath)) { _logger.Info($"Reading {osmFilePath} to memory - extracting only elements with name."); var source = new PBFOsmStreamSource(stream); var completeSource = new OsmSimpleCompleteStreamSource(source); var namesDictionary = completeSource .Where(o => string.IsNullOrWhiteSpace(GetName(o)) == false) .GroupBy(GetName) .ToDictionary(g => g.Key, g => g.ToList()); _logger.Info("Finished grouping data by name."); return namesDictionary; } }); }
public void TestWayAreaIsYes() { Node node1 = new Node(); node1.Id = 1; node1.Latitude = 0; node1.Longitude = 0; Node node2 = new Node(); node2.Id = 2; node2.Latitude = 1; node2.Longitude = 0; Node node3 = new Node(); node3.Id = 3; node3.Latitude = 0; node3.Longitude = 1; Way way = new Way(); way.Id = 1; way.Nodes = new List<long>(); way.Nodes.Add(1); way.Nodes.Add(2); way.Nodes.Add(3); way.Nodes.Add(1); way.Tags = new TagsCollection(); way.Tags.Add("area", "yes"); var source = new List<OsmGeo>(); source.Add(node1); source.Add(node2); source.Add(node3); source.Add(way); // the use of natural=water implies an area-type. var interpreter = new SimpleFeatureInterpreter(); var completeStreamSource = new OsmSimpleCompleteStreamSource(source.ToOsmStreamSource()); // use the stream to interpret. var features = new List<Feature>(new FeatureInterpreterStreamSource(completeStreamSource, interpreter)); Assert.AreEqual(1, features.Count); }
public async Task<List<CompleteWay>> GetHighwaysAroundATrace(IEnumerable<Coordinate> coordinates) { var overpassQueryPostfix = @"way[highway](bn)-> .w; node(w.w)-> .n; (node._.n; way.w); out qt; "; var overpassQueryNodes = ""; foreach (var coordinate in coordinates) { // lat, lng overpassQueryNodes += $"(._; node(around: 300, {coordinate.Y}, {coordinate.X}););\n"; } using (var client = new HttpClient()) { var response = await client.PostAsync(OVERPASS_INTERPRETER_ADDRESS, new StringContent(overpassQueryNodes + overpassQueryPostfix)); Trace.WriteLine(await response.Content.ReadAsStringAsync()); var source = new XmlOsmStreamSource(await response.Content.ReadAsStreamAsync()); var cache = new OsmDataCacheMemory(); var completeSource = new OsmSimpleCompleteStreamSource(source, cache); var list = completeSource.OfType<CompleteWay>().ToList(); return list; } }