Renamed OsmWay -> OsmEdge again
Prevented duplicate writes of Tags for way
This commit is contained in:
@ -110,6 +110,7 @@ public class RegionConverter
|
||||
Dictionary<Tag.TagType, dynamic> currentTags = new();
|
||||
Dictionary<ulong, FileStream> regionWaysFileStreams = new();
|
||||
Dictionary<ulong, FileStream> regionTagsFileStreams = new();
|
||||
Dictionary<ulong, HashSet<ulong>> writtenWayTagsInRegion = new();
|
||||
while (xmlReader.ReadToFollowing("way"))
|
||||
{
|
||||
currentNodeIds.Clear();
|
||||
@ -141,26 +142,26 @@ public class RegionConverter
|
||||
{
|
||||
if (currentTags.ContainsKey(Tag.TagType.forward) && !(bool)currentTags[Tag.TagType.forward])
|
||||
{
|
||||
OsmWay n21e = new OsmWay(currentTags[Tag.TagType.id], node2Id, node1Id, nodeRegions[node2Id]);
|
||||
OsmEdge n21e = new OsmEdge(currentTags[Tag.TagType.id], node2Id, node1Id, nodeRegions[node2Id]);
|
||||
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
||||
WriteTag(ref regionTagsFileStreams, nodeRegions[node2Id], currentTags, outputPath);
|
||||
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node2Id], currentTags, outputPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
OsmWay n12e = new OsmWay(currentTags[Tag.TagType.id], node1Id, node2Id, nodeRegions[node2Id]);
|
||||
OsmEdge n12e = new OsmEdge(currentTags[Tag.TagType.id], node1Id, node2Id, nodeRegions[node2Id]);
|
||||
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
|
||||
WriteTag(ref regionTagsFileStreams, nodeRegions[node1Id], currentTags, outputPath);
|
||||
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node1Id], currentTags, outputPath);
|
||||
}
|
||||
}
|
||||
else if(nodeRegions.ContainsKey(node1Id) && nodeRegions.ContainsKey(node2Id))
|
||||
{
|
||||
OsmWay n12e = new OsmWay(currentTags[Tag.TagType.id], node1Id, node2Id, nodeRegions[node2Id]);
|
||||
OsmEdge n12e = new OsmEdge(currentTags[Tag.TagType.id], node1Id, node2Id, nodeRegions[node2Id]);
|
||||
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
|
||||
WriteTag(ref regionTagsFileStreams, nodeRegions[node1Id], currentTags, outputPath);
|
||||
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node1Id], currentTags, outputPath);
|
||||
|
||||
OsmWay n21e = new OsmWay(currentTags[Tag.TagType.id], node2Id, node1Id, nodeRegions[node2Id]);
|
||||
OsmEdge n21e = new OsmEdge(currentTags[Tag.TagType.id], node2Id, node1Id, nodeRegions[node2Id]);
|
||||
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
||||
WriteTag(ref regionTagsFileStreams, nodeRegions[node2Id], currentTags, outputPath);
|
||||
WriteTags(ref regionTagsFileStreams, ref writtenWayTagsInRegion, nodeRegions[node2Id], currentTags, outputPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -172,7 +173,7 @@ public class RegionConverter
|
||||
f.Dispose();
|
||||
}
|
||||
|
||||
private static void WriteWay(ref Dictionary<ulong, FileStream> regionWaysFileStreams, ulong regionHash, OsmWay way, string outputPath)
|
||||
private static void WriteWay(ref Dictionary<ulong, FileStream> regionWaysFileStreams, ulong regionHash, OsmEdge edge, string outputPath)
|
||||
{
|
||||
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||
if (!regionWaysFileStreams.ContainsKey(regionHash))
|
||||
@ -181,13 +182,19 @@ public class RegionConverter
|
||||
regionWaysFileStreams.Add(regionHash, new FileStream(waysRegionPath, FileMode.OpenOrCreate));
|
||||
}
|
||||
#pragma warning disable SYSLIB0011
|
||||
bFormatter.Serialize(regionWaysFileStreams[regionHash], way);
|
||||
bFormatter.Serialize(regionWaysFileStreams[regionHash], edge);
|
||||
#pragma warning restore SYSLIB0011
|
||||
|
||||
}
|
||||
|
||||
private static void WriteTag(ref Dictionary<ulong, FileStream> regionTagsFileStreams, ulong regionHash, Dictionary<Tag.TagType, dynamic> currentTags, string outputPath)
|
||||
private static void WriteTags(ref Dictionary<ulong, FileStream> regionTagsFileStreams, ref Dictionary<ulong, HashSet<ulong>> writtenWayTagsInRegion, ulong regionHash, Dictionary<Tag.TagType, dynamic> currentTags, string outputPath)
|
||||
{
|
||||
if (writtenWayTagsInRegion.ContainsKey(regionHash) &&
|
||||
writtenWayTagsInRegion[regionHash].Contains(currentTags[Tag.TagType.id]))
|
||||
return;
|
||||
else if(!writtenWayTagsInRegion.ContainsKey(regionHash))
|
||||
writtenWayTagsInRegion.Add(regionHash, new HashSet<ulong>());
|
||||
|
||||
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||
if (!regionTagsFileStreams.ContainsKey(regionHash))
|
||||
{
|
||||
@ -195,10 +202,11 @@ public class RegionConverter
|
||||
regionTagsFileStreams.Add(regionHash, new FileStream(tagsRegionPath, FileMode.OpenOrCreate));
|
||||
}
|
||||
|
||||
ulong id = currentTags[Tag.TagType.id];
|
||||
ulong wayId = currentTags[Tag.TagType.id];
|
||||
writtenWayTagsInRegion[regionHash].Add(wayId);
|
||||
TagManager tm = new TagManager();
|
||||
foreach(KeyValuePair<Tag.TagType, dynamic> kv in currentTags)
|
||||
tm.AddTag(id, kv);
|
||||
tm.AddTag(wayId, kv);
|
||||
#pragma warning disable SYSLIB0011
|
||||
bFormatter.Serialize(regionTagsFileStreams[regionHash], tm);
|
||||
#pragma warning restore SYSLIB0011
|
||||
|
@ -20,7 +20,7 @@ public class RegionLoader
|
||||
return r.nodes;
|
||||
}
|
||||
|
||||
public HashSet<OsmWay> GetWays(ulong regionHash)
|
||||
public HashSet<OsmEdge> GetWays(ulong regionHash)
|
||||
{
|
||||
Region r = GetRegion(regionHash);
|
||||
return r.ways;
|
||||
@ -59,8 +59,8 @@ public class RegionLoader
|
||||
{
|
||||
while (wayFileStream.Position < wayFileStream.Length)
|
||||
{
|
||||
OsmWay deserializedWay = (OsmWay)bFormatter.Deserialize(wayFileStream);
|
||||
newRegion.ways.Add(deserializedWay);
|
||||
OsmEdge deserializedEdge = (OsmEdge)bFormatter.Deserialize(wayFileStream);
|
||||
newRegion.ways.Add(deserializedEdge);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user