mirror of
https://onedev.fprog.nl/OsmToDatabase
synced 2025-12-20 16:48:38 +01:00
Asynchronously process OSM elements.
This commit is contained in:
parent
2b86cf595c
commit
ff72f11cc5
|
|
@ -7,11 +7,8 @@ long counter = 0;
|
|||
|
||||
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)
|
||||
{
|
||||
string? naturalValue = node.TagValueByKey("natural");
|
||||
|
|
@ -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
|
||||
|
|
@ -63,6 +60,14 @@ using (var fileStream = new FileInfo(args[0]).OpenRead())
|
|||
await db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (var fileStream = new FileInfo(args[0]).OpenRead())
|
||||
{
|
||||
var source = new PBFOsmStreamSource(fileStream);
|
||||
foreach (var element in source)
|
||||
{
|
||||
await ProcessOsmElement(element);
|
||||
}
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue