Readbility through Methods
This commit is contained in:
parent
b12f959f48
commit
9ef1d4a978
@ -19,7 +19,7 @@ public class RegionConverter
|
|||||||
|
|
||||||
public const string NodesFileName = "region.nodes";
|
public const string NodesFileName = "region.nodes";
|
||||||
public const string WaysFileName = "region.ways";
|
public const string WaysFileName = "region.ways";
|
||||||
public const string tagsFileName = "waytags";
|
public const string tagsFileName = "region.tags";
|
||||||
|
|
||||||
public static void ConvertXMLToRegions(string filePath, string outputPath)
|
public static void ConvertXMLToRegions(string filePath, string outputPath)
|
||||||
{
|
{
|
||||||
@ -108,7 +108,6 @@ public class RegionConverter
|
|||||||
return nodeRegions;
|
return nodeRegions;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO write all tags in region to single file instead of separate wayfiles
|
|
||||||
private static void ImportWays(XmlReader xmlReader, Dictionary<ulong, ulong> nodeRegions, string outputPath)
|
private static void ImportWays(XmlReader xmlReader, Dictionary<ulong, ulong> nodeRegions, string outputPath)
|
||||||
{
|
{
|
||||||
BinaryFormatter bFormatter = new BinaryFormatter();
|
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||||
@ -117,8 +116,7 @@ public class RegionConverter
|
|||||||
List<ulong> currentNodeIds = new();
|
List<ulong> currentNodeIds = new();
|
||||||
Dictionary<Tag.TagType, dynamic> currentTags = new();
|
Dictionary<Tag.TagType, dynamic> currentTags = new();
|
||||||
Dictionary<ulong, FileStream> regionWaysFileStreams = new();
|
Dictionary<ulong, FileStream> regionWaysFileStreams = new();
|
||||||
string wayFileStreamPath = "";
|
Dictionary<ulong, FileStream> regionTagsFileStreams = new();
|
||||||
FileStream wayFileStream = new FileStream(Path.GetTempFileName(), FileMode.Create);
|
|
||||||
while (xmlReader.ReadToFollowing("way"))
|
while (xmlReader.ReadToFollowing("way"))
|
||||||
{
|
{
|
||||||
ulong wayId = Convert.ToUInt64(xmlReader.GetAttribute("id")!);
|
ulong wayId = Convert.ToUInt64(xmlReader.GetAttribute("id")!);
|
||||||
@ -158,71 +156,60 @@ public class RegionConverter
|
|||||||
if (currentTags.ContainsKey(Tag.TagType.forward) && !(bool)currentTags[Tag.TagType.forward])
|
if (currentTags.ContainsKey(Tag.TagType.forward) && !(bool)currentTags[Tag.TagType.forward])
|
||||||
{
|
{
|
||||||
OsmWay n21e = new OsmWay(currentWayId, node2Id, node1Id, nodeRegions[node2Id]);
|
OsmWay n21e = new OsmWay(currentWayId, node2Id, node1Id, nodeRegions[node2Id]);
|
||||||
if (!regionWaysFileStreams.ContainsKey(nodeRegions[node2Id]))
|
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
||||||
{
|
WriteTag(ref regionTagsFileStreams, nodeRegions[node2Id], currentTags, outputPath);
|
||||||
string waysRegionPath = Path.Combine(outputPath, nodeRegions[node2Id].ToString(), WaysFileName);
|
|
||||||
regionWaysFileStreams.Add(nodeRegions[node2Id], new FileStream(waysRegionPath, FileMode.OpenOrCreate));
|
|
||||||
}
|
|
||||||
#pragma warning disable SYSLIB0011
|
|
||||||
bFormatter.Serialize(regionWaysFileStreams[nodeRegions[node2Id]], n21e);
|
|
||||||
|
|
||||||
wayFileStreamPath = Path.Combine(outputPath, nodeRegions[node2Id].ToString(), $"{wayId}.{tagsFileName}");
|
|
||||||
wayFileStream = new FileStream(wayFileStreamPath, FileMode.OpenOrCreate);
|
|
||||||
bFormatter.Serialize(wayFileStream, currentTags);
|
|
||||||
wayFileStream.Dispose();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OsmWay n12e = new OsmWay(currentWayId, node1Id, node2Id, nodeRegions[node2Id]);
|
OsmWay n12e = new OsmWay(currentWayId, node1Id, node2Id, nodeRegions[node2Id]);
|
||||||
if (!regionWaysFileStreams.ContainsKey(nodeRegions[node1Id]))
|
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
|
||||||
{
|
WriteTag(ref regionTagsFileStreams, nodeRegions[node1Id], currentTags, outputPath);
|
||||||
string waysRegionPath = Path.Combine(outputPath, nodeRegions[node1Id].ToString(), WaysFileName);
|
|
||||||
regionWaysFileStreams.Add(nodeRegions[node1Id], new FileStream(waysRegionPath, FileMode.OpenOrCreate));
|
|
||||||
}
|
|
||||||
bFormatter.Serialize(regionWaysFileStreams[nodeRegions[node1Id]], n12e);
|
|
||||||
|
|
||||||
wayFileStreamPath = Path.Combine(outputPath, nodeRegions[node1Id].ToString(), $"{wayId}.{tagsFileName}");
|
|
||||||
wayFileStream = new FileStream(wayFileStreamPath, FileMode.OpenOrCreate);
|
|
||||||
bFormatter.Serialize(wayFileStream, currentTags);
|
|
||||||
wayFileStream.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(nodeRegions.ContainsKey(node1Id) && nodeRegions.ContainsKey(node2Id))
|
else if(nodeRegions.ContainsKey(node1Id) && nodeRegions.ContainsKey(node2Id))
|
||||||
{
|
{
|
||||||
OsmWay n12e = new OsmWay(currentWayId, node1Id, node2Id, nodeRegions[node2Id]);
|
OsmWay n12e = new OsmWay(currentWayId, node1Id, node2Id, nodeRegions[node2Id]);
|
||||||
if (!regionWaysFileStreams.ContainsKey(nodeRegions[node1Id]))
|
WriteWay(ref regionWaysFileStreams, nodeRegions[node1Id], n12e, outputPath);
|
||||||
{
|
WriteTag(ref regionTagsFileStreams, nodeRegions[node1Id], currentTags, outputPath);
|
||||||
string waysRegionPath = Path.Combine(outputPath, nodeRegions[node1Id].ToString(), WaysFileName);
|
|
||||||
regionWaysFileStreams.Add(nodeRegions[node1Id], new FileStream(waysRegionPath, FileMode.OpenOrCreate));
|
|
||||||
}
|
|
||||||
bFormatter.Serialize(regionWaysFileStreams[nodeRegions[node1Id]], n12e);
|
|
||||||
|
|
||||||
wayFileStreamPath = Path.Combine(outputPath, nodeRegions[node1Id].ToString(), $"{wayId}.{tagsFileName}");
|
|
||||||
wayFileStream = new FileStream(wayFileStreamPath, FileMode.OpenOrCreate);
|
|
||||||
bFormatter.Serialize(wayFileStream, currentTags);
|
|
||||||
wayFileStream.Dispose();
|
|
||||||
|
|
||||||
OsmWay n21e = new OsmWay(currentWayId, node2Id, node1Id, nodeRegions[node2Id]);
|
OsmWay n21e = new OsmWay(currentWayId, node2Id, node1Id, nodeRegions[node2Id]);
|
||||||
if (!regionWaysFileStreams.ContainsKey(nodeRegions[node2Id]))
|
WriteWay(ref regionWaysFileStreams, nodeRegions[node2Id], n21e, outputPath);
|
||||||
{
|
WriteTag(ref regionTagsFileStreams, nodeRegions[node2Id], currentTags, outputPath);
|
||||||
string waysRegionPath = Path.Combine(outputPath, nodeRegions[node2Id].ToString(), WaysFileName);
|
|
||||||
regionWaysFileStreams.Add(nodeRegions[node2Id], new FileStream(waysRegionPath, FileMode.OpenOrCreate));
|
|
||||||
}
|
|
||||||
bFormatter.Serialize(regionWaysFileStreams[nodeRegions[node1Id]], n21e);
|
|
||||||
|
|
||||||
wayFileStreamPath = Path.Combine(outputPath, nodeRegions[node2Id].ToString(), $"{wayId}.{tagsFileName}");
|
|
||||||
wayFileStream = new FileStream(wayFileStreamPath, FileMode.OpenOrCreate);
|
|
||||||
bFormatter.Serialize(wayFileStream, currentTags);
|
|
||||||
wayFileStream.Dispose();
|
|
||||||
#pragma warning restore SYSLIB0011
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlReader.Close();
|
xmlReader.Close();
|
||||||
foreach (FileStream f in regionWaysFileStreams.Values)
|
foreach (FileStream f in regionWaysFileStreams.Values)
|
||||||
{
|
f.Dispose();
|
||||||
|
foreach(FileStream f in regionTagsFileStreams.Values)
|
||||||
f.Dispose();
|
f.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void WriteWay(ref Dictionary<ulong, FileStream> regionWaysFileStreams, ulong regionHash, OsmWay way, string outputPath)
|
||||||
|
{
|
||||||
|
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||||
|
if (!regionWaysFileStreams.ContainsKey(regionHash))
|
||||||
|
{
|
||||||
|
string waysRegionPath = Path.Combine(outputPath, regionHash.ToString(), WaysFileName);
|
||||||
|
regionWaysFileStreams.Add(regionHash, new FileStream(waysRegionPath, FileMode.OpenOrCreate));
|
||||||
|
}
|
||||||
|
#pragma warning disable SYSLIB0011
|
||||||
|
bFormatter.Serialize(regionWaysFileStreams[regionHash], way);
|
||||||
|
#pragma warning restore SYSLIB0011
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteTag(ref Dictionary<ulong, FileStream> regionTagsFileStreams, ulong regionHash, Dictionary<Tag.TagType, dynamic> currentTags, string outputPath)
|
||||||
|
{
|
||||||
|
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||||
|
if (!regionTagsFileStreams.ContainsKey(regionHash))
|
||||||
|
{
|
||||||
|
string tagsRegionPath = Path.Combine(outputPath, regionHash.ToString(), tagsFileName);
|
||||||
|
regionTagsFileStreams.Add(regionHash, new FileStream(tagsRegionPath, FileMode.OpenOrCreate));
|
||||||
|
}
|
||||||
|
#pragma warning disable SYSLIB0011
|
||||||
|
bFormatter.Serialize(regionTagsFileStreams[regionHash], currentTags);
|
||||||
|
#pragma warning restore SYSLIB0011
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user