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