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 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; } }