-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Labels
Description
using OsmSharp.Streams;
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace Sample.CompleteStream
{
class Program
{
/// <summary>
/// Downloads a file if it doesn't exist yet.
/// </summary>
public static async Task ToFile(string url, string filename)
{
if (!File.Exists(filename))
{
var client = new HttpClient();
using (var stream = await client.GetStreamAsync(url))
using (var outputStream = File.OpenWrite(filename))
{
stream.CopyTo(outputStream);
}
}
}
static void Main(string[] args)
{
ToFile("http://download.openstreetmap.fr/extracts/europe/ukraine//kiev.osm.pbf", "kiev.osm.pbf").Wait();
using (var fileStream = File.OpenRead("kiev.osm.pbf"))
{
// create source stream.
var source = new PBFOsmStreamSource(fileStream);
var complete = source.Where(_ => true).ToComplete();
var counted = complete.GroupBy(osmGeo => osmGeo.Type).Select(group => (group.Key, group.Count()));
foreach (var (k, v) in counted)
{
Console.WriteLine($"{k}={v}");
}
}
}
}
}
- Run the code above against either current
master
or withdotnet add package OsmSharp
for eithernetcoreapp2.1
ornetcoreapp3.1
. - See
Stack Overflow
printed on the console with no additional info.
P.S. Omitting .Where(_ => true)
will fail in the same way.