Asynchronously process OSM elements.

This commit is contained in:
Filip Strajnar 2024-06-24 13:17:23 +02:00
parent 2b86cf595c
commit ff72f11cc5

View file

@ -7,10 +7,7 @@ long counter = 0;
HashSet<string> naturalPeakFeatures = new HashSet<string> { "peak", "volcano" };
using (var fileStream = new FileInfo(args[0]).OpenRead())
{
var source = new PBFOsmStreamSource(fileStream);
foreach (var element in source)
async Task ProcessOsmElement(OsmGeo? element)
{
if (element is Node node)
{
@ -19,19 +16,19 @@ using (var fileStream = new FileInfo(args[0]).OpenRead())
// Skip if natural tag is missing.
if (naturalValue is null)
{
continue;
return;
}
// Skip if the node is not a desired feature.
if (!naturalPeakFeatures.Contains(naturalValue))
{
continue;
return;
}
// Skip if elevation is missing.
if (node.TagDoubleValueByKey("ele") is null)
{
continue;
return;
}
Peak peak = new Peak
@ -64,5 +61,13 @@ using (var fileStream = new FileInfo(args[0]).OpenRead())
}
}
}
using (var fileStream = new FileInfo(args[0]).OpenRead())
{
var source = new PBFOsmStreamSource(fileStream);
foreach (var element in source)
{
await ProcessOsmElement(element);
}
await db.SaveChangesAsync();
}